MySQLX 2.1.3__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mysqlx-2.1.3/README.rst → mysqlx-2.2.0/PKG-INFO +159 -167
- mysqlx-2.1.3/mysqlx.egg-info/PKG-INFO → mysqlx-2.2.0/README.rst +144 -182
- {mysqlx-2.1.3 → mysqlx-2.2.0}/mysqlx/__init__.py +12 -9
- mysqlx-2.2.0/mysqlx/constant.py +13 -0
- mysqlx-2.2.0/mysqlx/db.py +95 -0
- mysqlx-2.2.0/mysqlx/dbx.py +124 -0
- mysqlx-2.2.0/mysqlx/log_support.py +17 -0
- mysqlx-2.2.0/mysqlx/sql_holder.py +182 -0
- mysqlx-2.2.0/mysqlx/sql_id_exec.py +25 -0
- mysqlx-2.2.0/mysqlx/sql_mapper.py +111 -0
- mysqlx-2.2.0/mysqlx/sql_page_exec.py +12 -0
- mysqlx-2.2.0/mysqlx/sql_support.py +52 -0
- mysqlx-2.2.0/mysqlx/support.py +20 -0
- {mysqlx-2.1.3 → mysqlx-2.2.0/mysqlx.egg-info}/PKG-INFO +4 -27
- {mysqlx-2.1.3 → mysqlx-2.2.0}/mysqlx.egg-info/SOURCES.txt +7 -1
- mysqlx-2.2.0/mysqlx.egg-info/requires.txt +2 -0
- {mysqlx-2.1.3 → mysqlx-2.2.0}/setup.py +3 -4
- mysqlx-2.1.3/mysqlx/db.py +0 -8
- mysqlx-2.1.3/mysqlx/dbx.py +0 -2
- mysqlx-2.1.3/mysqlx/log_support.py +0 -14
- mysqlx-2.1.3/mysqlx/orm.py +0 -142
- mysqlx-2.1.3/mysqlx.egg-info/requires.txt +0 -1
- {mysqlx-2.1.3 → mysqlx-2.2.0}/mysqlx.egg-info/dependency_links.txt +0 -0
- {mysqlx-2.1.3 → mysqlx-2.2.0}/mysqlx.egg-info/not-zip-safe +0 -0
- {mysqlx-2.1.3 → mysqlx-2.2.0}/mysqlx.egg-info/top_level.txt +0 -0
- {mysqlx-2.1.3 → mysqlx-2.2.0}/setup.cfg +0 -0
|
@@ -1,167 +1,159 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
#
|
|
78
|
-
# (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
#
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
users =
|
|
90
|
-
# result:
|
|
91
|
-
# (3, 'zhangsan', 15)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
#
|
|
102
|
-
|
|
103
|
-
#
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
#
|
|
110
|
-
# (
|
|
111
|
-
|
|
112
|
-
users =
|
|
113
|
-
# result:
|
|
114
|
-
#
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
#
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
You can generate model class with mysqlx-generator: https://pypi.org/project/mysqlx-generator
|
|
162
|
-
|
|
163
|
-
If you want to operate PostgreSQL database, may be you need PgSqlx: https://pypi.org/project/pgsqlx
|
|
164
|
-
|
|
165
|
-
If you just wanted a simple sql executor, may be you need sqlx-exec: https://pypi.org/project/sqlx-exec
|
|
166
|
-
|
|
167
|
-
If you wanted simultaneously support MySQL and PostgreSQL, may be you need sqlx-batis: https://pypi.org/project/sqlx-batis
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: mysqlx
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: A thread safe sql executor for MySQL like MyBatis with connection pool. It helps you automatically manage database connections and transactions. It also provides ORM operations for single tables.
|
|
5
|
+
Home-page: https://gitee.com/summry/mysqlx
|
|
6
|
+
Author: summy
|
|
7
|
+
Author-email: xiazhongbiao@126.com
|
|
8
|
+
License: UNKNOWN
|
|
9
|
+
Keywords: sql,MySQL,MyBatis,python
|
|
10
|
+
Platform: UNKNOWN
|
|
11
|
+
Requires-Python: >=3.5
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
Mapper file
|
|
15
|
+
'''''''''''
|
|
16
|
+
|
|
17
|
+
Create a mapper file in 'mapper' folder, you can named
|
|
18
|
+
'user_mapper.xml', like follow:
|
|
19
|
+
|
|
20
|
+
.. code:: xml
|
|
21
|
+
|
|
22
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
23
|
+
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://gitee.com/summry/mysqlx/blob/master/dtd/mapper.dtd">
|
|
24
|
+
<mapper namespace="user">
|
|
25
|
+
<select id="select_all">
|
|
26
|
+
select id, name, age from user
|
|
27
|
+
</select>
|
|
28
|
+
|
|
29
|
+
<select id="select_by_name">
|
|
30
|
+
select id, name, age from user where name = ?
|
|
31
|
+
</select>
|
|
32
|
+
|
|
33
|
+
<select id="select_by_name2">
|
|
34
|
+
select id, name, age from user where name = :name
|
|
35
|
+
</select>
|
|
36
|
+
|
|
37
|
+
<select id="select_include" include="select_all">
|
|
38
|
+
{{ select_all }}
|
|
39
|
+
{% if name -%}
|
|
40
|
+
where name = :name
|
|
41
|
+
{%- endif -%}
|
|
42
|
+
</select>
|
|
43
|
+
</mapper>
|
|
44
|
+
|
|
45
|
+
Usage Sample
|
|
46
|
+
''''''''''''
|
|
47
|
+
|
|
48
|
+
.. code:: python
|
|
49
|
+
|
|
50
|
+
from mysqlx.orm import Model
|
|
51
|
+
from typing import List, Tuple, Mapping
|
|
52
|
+
from mysqlx import mapper, sql, db, dbx, init_db
|
|
53
|
+
|
|
54
|
+
@mapper(namespace='user')
|
|
55
|
+
def select_all(): List
|
|
56
|
+
|
|
57
|
+
@mapper(namespace='user')
|
|
58
|
+
def select_by_name(name: str): List
|
|
59
|
+
|
|
60
|
+
@mapper(namespace='user')
|
|
61
|
+
def select_by_name2(name: str): List
|
|
62
|
+
|
|
63
|
+
@mapper(namespace='user')
|
|
64
|
+
def select_include(name: str): List
|
|
65
|
+
|
|
66
|
+
@sql('select id, name, age from user where name = ?')
|
|
67
|
+
def query_by_name(name: str): List(Mapping)
|
|
68
|
+
|
|
69
|
+
@sql('select id, name, age from user where name = :name')
|
|
70
|
+
def query_by_name2(name: str): List(Mapping)
|
|
71
|
+
|
|
72
|
+
if __name__ == '__main__':
|
|
73
|
+
init_db(host='127.0.0.1', port='3306', user='xxx', password='xxx', database='test', pool_size=5, show_sql=True, mapper_path='./mapper')
|
|
74
|
+
|
|
75
|
+
users = select_all()
|
|
76
|
+
# result:
|
|
77
|
+
# (3, 'zhangsan', 15)
|
|
78
|
+
# (4, 'lisi', 26)
|
|
79
|
+
# (5, 'wangwu', 38)
|
|
80
|
+
|
|
81
|
+
users = select_by_name('zhangsan')
|
|
82
|
+
# result:
|
|
83
|
+
# (3, 'zhangsan', 15)
|
|
84
|
+
|
|
85
|
+
users = select_by_name2(name='zhangsan')
|
|
86
|
+
# result:
|
|
87
|
+
# (3, 'zhangsan', 15)
|
|
88
|
+
|
|
89
|
+
users = select_include(name='zhangsan')
|
|
90
|
+
# result:
|
|
91
|
+
# (3, 'zhangsan', 15)
|
|
92
|
+
|
|
93
|
+
users = query_by_name('zhangsan')
|
|
94
|
+
# result:
|
|
95
|
+
# {'id': 3, 'name': 'zhangsan', 'age': 15}
|
|
96
|
+
|
|
97
|
+
users = query_by_name2(name='zhangsan')
|
|
98
|
+
# result:
|
|
99
|
+
# {'id': 3, 'name': 'zhangsan', 'age': 15}
|
|
100
|
+
|
|
101
|
+
# you can use dbx execte mapper sql with full sql id: namespace join sql id
|
|
102
|
+
users = dbx.select('user.select_all') # 'user' is namespace, 'select_all' is sql id
|
|
103
|
+
# result:
|
|
104
|
+
# (3, 'zhangsan', 15)
|
|
105
|
+
# (4, 'lisi', 26)
|
|
106
|
+
# (5, 'wangwu', 38)
|
|
107
|
+
|
|
108
|
+
users = dbx.select('user.select_by_name', name='zhangsan')
|
|
109
|
+
# result:
|
|
110
|
+
# (3, 'zhangsan', 15)
|
|
111
|
+
|
|
112
|
+
users = dbx.sql('user.select_by_name').select(name='zhangsan')
|
|
113
|
+
# result:
|
|
114
|
+
# (3, 'zhangsan', 15)
|
|
115
|
+
|
|
116
|
+
# you can direct execute sql with db
|
|
117
|
+
effected_rowcount = db.insert(table='user', name='zhaoliu', age=66)
|
|
118
|
+
|
|
119
|
+
users = db.select('select id, name, age from user')
|
|
120
|
+
# result:
|
|
121
|
+
# (3, 'zhangsan', 15)
|
|
122
|
+
# (4, 'lisi', 26)
|
|
123
|
+
# (5, 'wangwu', 38)
|
|
124
|
+
|
|
125
|
+
users = db.query('select id, name, age from user name = :name', name='zhangsan')
|
|
126
|
+
# result:
|
|
127
|
+
# [{'id': 3, 'name': 'zhangsan', 'age': 15}]
|
|
128
|
+
|
|
129
|
+
users = db.sql('select id, name, age from user name = :name').query(name='zhangsan')
|
|
130
|
+
# result:
|
|
131
|
+
# [{'id': 3, 'name': 'zhangsan', 'age': 15}]
|
|
132
|
+
|
|
133
|
+
Transaction
|
|
134
|
+
'''''''''''
|
|
135
|
+
|
|
136
|
+
.. code:: python
|
|
137
|
+
|
|
138
|
+
from mysqlx import with_transaction, transaction
|
|
139
|
+
|
|
140
|
+
@with_transaction
|
|
141
|
+
def test_transaction():
|
|
142
|
+
insert_func(....)
|
|
143
|
+
update_func(....)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_transaction2():
|
|
147
|
+
with transaction():
|
|
148
|
+
insert_func(....)
|
|
149
|
+
update_func(....)
|
|
150
|
+
|
|
151
|
+
You can generate model class with mysqlx-generator: https://pypi.org/project/sqlormx
|
|
152
|
+
|
|
153
|
+
If you want to operate PostgreSQL database, may be you need PgSqlx: https://pypi.org/project/pgsqlx
|
|
154
|
+
|
|
155
|
+
If you just wanted a simple sql executor, may be you need sqlx-exec: https://pypi.org/project/sqlexecx
|
|
156
|
+
|
|
157
|
+
If you wanted simultaneously support MySQL and PostgreSQL, may be you need sqlx-batis: https://pypi.org/project/batisx
|
|
158
|
+
|
|
159
|
+
|