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.
@@ -1,167 +1,159 @@
1
- Mapper file
2
- '''''''''''
3
-
4
- Create a mapper file in 'mapper' folder, you can named
5
- 'user_mapper.xml', like follow:
6
-
7
- .. code:: xml
8
-
9
- <?xml version="1.0" encoding="UTF-8"?>
10
- <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "https://gitee.com/summry/mysqlx/blob/master/dtd/mapper.dtd">
11
- <mapper namespace="user">
12
- <select id="select_all">
13
- select id, name, age from user
14
- </select>
15
-
16
- <select id="select_by_name">
17
- select id, name, age from user where name = ?
18
- </select>
19
-
20
- <select id="select_by_name2">
21
- select id, name, age from user where name = :name
22
- </select>
23
-
24
- <select id="select_include" include="select_all">
25
- {{ select_all }}
26
- {% if name -%}
27
- where name = :name
28
- {%- endif -%}
29
- </select>
30
- </mapper>
31
-
32
- Usage Sample
33
- ''''''''''''
34
-
35
- .. code:: python
36
-
37
- from mysqlx.orm import Model
38
- from typing import List, Tuple, Mapping
39
- from mysqlx import mapper, sql, db, dbx, init_db
40
-
41
- @mapper(namespace='user')
42
- def select_all(): List
43
-
44
- @mapper(namespace='user')
45
- def select_by_name(name: str): List
46
-
47
- @mapper(namespace='user')
48
- def select_by_name2(name: str): List
49
-
50
- @mapper(namespace='user')
51
- def select_include(name: str): List
52
-
53
- @sql('select id, name, age from user where name = ?')
54
- def query_by_name(name: str): List(Mapping)
55
-
56
- @sql('select id, name, age from user where name = :name')
57
- def query_by_name2(name: str): List(Mapping)
58
-
59
- if __name__ == '__main__':
60
- init_db(host='127.0.0.1', port='3306', user='xxx', password='xxx', database='test', pool_size=5, show_sql=True, mapper_path='./mapper')
61
-
62
- users = select_all()
63
- # result:
64
- # (3, 'zhangsan', 15)
65
- # (4, 'lisi', 26)
66
- # (5, 'wangwu', 38)
67
-
68
- users = select_by_name('zhangsan')
69
- # result:
70
- # (3, 'zhangsan', 15)
71
-
72
- users = select_by_name2(name='zhangsan')
73
- # result:
74
- # (3, 'zhangsan', 15)
75
-
76
- users = select_include(name='zhangsan')
77
- # result:
78
- # (3, 'zhangsan', 15)
79
-
80
- users = query_by_name('zhangsan')
81
- # result:
82
- # {'id': 3, 'name': 'zhangsan', 'age': 15}
83
-
84
- users = query_by_name2(name='zhangsan')
85
- # result:
86
- # {'id': 3, 'name': 'zhangsan', 'age': 15}
87
-
88
- # you can use dbx execte mapper sql with full sql id: namespace join sql id
89
- users = dbx.select('user.select_all') # 'user' is namespace, 'select_all' is sql id
90
- # result:
91
- # (3, 'zhangsan', 15)
92
- # (4, 'lisi', 26)
93
- # (5, 'wangwu', 38)
94
-
95
- users = dbx.select('user.select_by_name', name='zhangsan')
96
- # result:
97
- # (3, 'zhangsan', 15)
98
-
99
- users = dbx.sql('user.select_by_name').select(name='zhangsan')
100
- # result:
101
- # (3, 'zhangsan', 15)
102
-
103
- # you can direct execute sql with db
104
- effected_rowcount = db.insert(table='user', name='zhaoliu', age=66)
105
-
106
- users = db.select('select id, name, age from user')
107
- # result:
108
- # (3, 'zhangsan', 15)
109
- # (4, 'lisi', 26)
110
- # (5, 'wangwu', 38)
111
-
112
- users = db.query('select id, name, age from user name = :name', name='zhangsan')
113
- # result:
114
- # [{'id': 3, 'name': 'zhangsan', 'age': 15}]
115
-
116
- users = db.sql('select id, name, age from user name = :name').query(name='zhangsan')
117
- # result:
118
- # [{'id': 3, 'name': 'zhangsan', 'age': 15}]
119
-
120
- # you can use orm to operate a single table
121
- class User(Model):
122
- __key__ = 'id'
123
- __table__ = 'user'
124
-
125
- def __init__(self, id: int = None, name: str = None, age: int = None):
126
- self.id = id
127
- self.name = name
128
- self.age = age
129
-
130
-
131
- effected_rowcount = User.insert(name='tianqi', age=77)
132
-
133
- users = User.query(name='tianqi')
134
- # select id, name, age from user where name = :name
135
- # result:
136
- # {'id': 7, 'name': 'tianqi', 'age': 77}
137
-
138
- users = User.query(name__eq='zhangsan')
139
- # select id, name, age from user where name = :name
140
- # result:
141
- # [{'id': 3, 'name': 'zhangsan', 'age': 15}]
142
-
143
- Transaction
144
- '''''''''''
145
-
146
- .. code:: python
147
-
148
- from mysqlx import with_transaction, transaction
149
-
150
- @with_transaction
151
- def test_transaction():
152
- insert_func(....)
153
- update_func(....)
154
-
155
-
156
- def test_transaction2():
157
- with transaction():
158
- insert_func(....)
159
- update_func(....)
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
+