MySQLX 2.2.4__tar.gz → 2.2.5__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,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mysqlx
3
- Version: 2.2.4
3
+ Version: 2.2.5
4
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
5
  Home-page: https://gitee.com/summry/mysqlx
6
6
  Author: summy
@@ -136,16 +136,16 @@ Transaction
136
136
 
137
137
  .. code:: python
138
138
 
139
- from mysqlx import with_transaction, transaction
139
+ from mysqlx import trans
140
140
 
141
- @with_transaction
141
+ @trans
142
142
  def test_transaction():
143
143
  insert_func(....)
144
144
  update_func(....)
145
145
 
146
146
 
147
147
  def test_transaction2():
148
- with transaction():
148
+ with trans():
149
149
  insert_func(....)
150
150
  update_func(....)
151
151
 
@@ -122,16 +122,16 @@ Transaction
122
122
 
123
123
  .. code:: python
124
124
 
125
- from mysqlx import with_transaction, transaction
125
+ from mysqlx import trans
126
126
 
127
- @with_transaction
127
+ @trans
128
128
  def test_transaction():
129
129
  insert_func(....)
130
130
  update_func(....)
131
131
 
132
132
 
133
133
  def test_transaction2():
134
- with transaction():
134
+ with trans():
135
135
  insert_func(....)
136
136
  update_func(....)
137
137
 
@@ -1,8 +1,6 @@
1
1
  from sqlexecx import (
2
- connection,
3
- transaction,
4
- with_connection,
5
- with_transaction,
2
+ conn,
3
+ trans,
6
4
  get_connection,
7
5
  close,
8
6
  Driver,
@@ -46,13 +46,13 @@ def do_get_sql(sql_model, batch, param_names, *args, **kwargs):
46
46
  :return:
47
47
  """
48
48
  if sql_model.dynamic:
49
- if not kwargs:
50
- raise MapperError("Parameter 'kwargs' must not be empty when named mapping sql.")
51
49
  sql = sql_model.sql.render(**kwargs)
52
- logger.debug("Original sql: {}".format(sql))
50
+ # 去掉空行
51
+ sql = '\n\t'.join([line for line in sql.rstrip().split('\n\t') if line.strip()])
52
+ logger.debug(f"Original sql: {sql}")
53
53
  return get_named_sql_args(sql, **kwargs)
54
54
  else:
55
- logger.debug("Original sql: {}".format(sql_model.sql))
55
+ logger.debug(f"Original sql: {sql_model.sql}")
56
56
  if sql_model.mapping and kwargs:
57
57
  return get_named_sql_args(sql_model.sql, **kwargs)
58
58
  elif sql_model.placeholder and kwargs:
@@ -65,7 +65,7 @@ def do_get_sql(sql_model, batch, param_names, *args, **kwargs):
65
65
 
66
66
 
67
67
  def build_sql_id(namespace, _id):
68
- return namespace + "." + _id
68
+ return f'{namespace}.{_id}'
69
69
 
70
70
 
71
71
  def get_sql_model(sql_id: str):
@@ -179,4 +179,6 @@ def _load_sql(namespace, child, file):
179
179
 
180
180
 
181
181
  def _valid_sql(sql_id, sql, tag):
182
+ if tag in (SqlAction.SQL.value, SqlAction.CALL.value):
183
+ return
182
184
  assert tag in _valid_sql_actions and tag in sql.lower(), "Sql id: '{}' has not '{}' key word in {} sql.".format(sql_id, tag, tag)
@@ -87,16 +87,20 @@ def get_exec_func(func, action, batch):
87
87
  def get_select_func(func):
88
88
  names = func.__code__.co_names
89
89
  is_list = 'list' in names or 'List' in names
90
- if 'Mapping' in names and is_list:
90
+ is_dict = 'dict' in names or 'Mapping' in names
91
+ is_tuple = 'tuple' in names or 'Tuple' in names
92
+ if is_dict and is_list:
91
93
  return sqlexecx.do_query
92
- elif 'Mapping' in names:
94
+ elif is_tuple and is_list:
95
+ return sqlexecx.do_select
96
+ elif is_dict in names:
93
97
  return sqlexecx.do_query_one
94
98
  elif len(names) == 1 and names[0] in ('int', 'float', 'Decimal', 'str', 'AnyStr', 'date', 'time', 'datetime'):
95
99
  return sqlexecx.do_get
96
100
  elif len(names) == 1 and names[0] in ('tuple', 'Tuple'):
97
101
  return sqlexecx.do_select_one
98
- elif is_list:
99
- return sqlexecx.do_select
102
+ elif is_list and len(names) == 2:
103
+ return sqlexecx.do_ravel_list
100
104
  else:
101
105
  return sqlexecx.do_query
102
106
 
@@ -11,6 +11,7 @@ class NotFoundError(DBError):
11
11
 
12
12
 
13
13
  class SqlAction(Enum):
14
+ SQL = 'sql'
14
15
  CALL = 'call'
15
16
  INSERT = 'insert'
16
17
  UPDATE = 'update'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mysqlx
3
- Version: 2.2.4
3
+ Version: 2.2.5
4
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
5
  Home-page: https://gitee.com/summry/mysqlx
6
6
  Author: summy
@@ -136,16 +136,16 @@ Transaction
136
136
 
137
137
  .. code:: python
138
138
 
139
- from mysqlx import with_transaction, transaction
139
+ from mysqlx import trans
140
140
 
141
- @with_transaction
141
+ @trans
142
142
  def test_transaction():
143
143
  insert_func(....)
144
144
  update_func(....)
145
145
 
146
146
 
147
147
  def test_transaction2():
148
- with transaction():
148
+ with trans():
149
149
  insert_func(....)
150
150
  update_func(....)
151
151
 
@@ -0,0 +1,2 @@
1
+ Jinja2>=2.7.0
2
+ sqlexecx>=2.1.4
@@ -19,9 +19,9 @@ setup(
19
19
  long_description_content_type='text/markdown',
20
20
  install_requires=[
21
21
  'Jinja2>=2.7.0',
22
- 'sqlexecx>=2.1.3',
22
+ 'sqlexecx>=2.1.4',
23
23
  ],
24
- version='2.2.4',
24
+ version='2.2.5',
25
25
  url='https://gitee.com/summry/mysqlx',
26
26
  author='summy',
27
27
  author_email='xiazhongbiao@126.com',
@@ -1,2 +0,0 @@
1
- Jinja2>=2.7.0
2
- sqlexecx>=2.1.3
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes