reydb 1.1.58__py3-none-any.whl → 1.1.60__py3-none-any.whl
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.
- reydb/rbase.py +4 -5
- reydb/rbuild.py +677 -177
- reydb/rconfig.py +34 -90
- reydb/rconn.py +109 -105
- reydb/rdb.py +36 -15
- reydb/rerror.py +2 -2
- reydb/rexec.py +64 -45
- reydb/rfile.py +4 -4
- reydb/rorm.py +746 -170
- reydb/rparam.py +5 -2
- {reydb-1.1.58.dist-info → reydb-1.1.60.dist-info}/METADATA +1 -1
- reydb-1.1.60.dist-info/RECORD +17 -0
- reydb-1.1.58.dist-info/RECORD +0 -17
- {reydb-1.1.58.dist-info → reydb-1.1.60.dist-info}/WHEEL +0 -0
- {reydb-1.1.58.dist-info → reydb-1.1.60.dist-info}/licenses/LICENSE +0 -0
reydb/rdb.py
CHANGED
@@ -9,7 +9,7 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import Generic
|
12
|
+
from typing import TypeVar, Generic
|
13
13
|
from urllib.parse import quote as urllib_quote
|
14
14
|
from pymysql.constants.CLIENT import MULTI_STATEMENTS
|
15
15
|
from sqlalchemy import Engine, create_engine as sqlalchemy_create_engine
|
@@ -26,13 +26,22 @@ __all__ = (
|
|
26
26
|
)
|
27
27
|
|
28
28
|
|
29
|
+
DatabaseConnectionT = TypeVar('DatabaseConnectionT', 'rconn.DatabaseConnection', 'rconn.DatabaseConnectionAsync')
|
30
|
+
DatabaseExecuteT = TypeVar('DatabaseExecuteT', 'rexec.DatabaseExecute', 'rexec.DatabaseExecuteAsync')
|
31
|
+
DatabaseSchemaT = TypeVar('DatabaseSchemaT', 'rparam.DatabaseSchema', 'rparam.DatabaseSchemaAsync')
|
32
|
+
DatabaseORMT = TypeVar('DatabaseORMT', 'rorm.DatabaseORM', 'rorm.DatabaseORMAsync')
|
33
|
+
DatabaseBuildT = TypeVar('DatabaseBuildT')
|
34
|
+
|
35
|
+
|
29
36
|
class DatabaseSuper(
|
30
37
|
rbase.DatabaseBase,
|
31
38
|
Generic[
|
32
39
|
rbase.EngineT,
|
33
|
-
|
34
|
-
|
35
|
-
|
40
|
+
DatabaseConnectionT,
|
41
|
+
DatabaseExecuteT,
|
42
|
+
DatabaseSchemaT,
|
43
|
+
DatabaseORMT,
|
44
|
+
DatabaseBuildT
|
36
45
|
]
|
37
46
|
):
|
38
47
|
"""
|
@@ -70,7 +79,7 @@ class DatabaseSuper(
|
|
70
79
|
pool_recycle : Number of seconds `recycle` connection.
|
71
80
|
- `None | Literal[-1]`: No recycle.
|
72
81
|
- `int`: Use this value.
|
73
|
-
report : Whether report SQL execute information.
|
82
|
+
report : Whether report SQL execute information, not include ORM execute.
|
74
83
|
query : Remote server database parameters.
|
75
84
|
"""
|
76
85
|
|
@@ -237,7 +246,7 @@ class DatabaseSuper(
|
|
237
246
|
return keep_n, overflow_n
|
238
247
|
|
239
248
|
|
240
|
-
def connect(self, autocommit: bool = False) ->
|
249
|
+
def connect(self, autocommit: bool = False) -> DatabaseConnectionT:
|
241
250
|
"""
|
242
251
|
Build database connection instance.
|
243
252
|
|
@@ -261,7 +270,7 @@ class DatabaseSuper(
|
|
261
270
|
|
262
271
|
|
263
272
|
@property
|
264
|
-
def execute(self) ->
|
273
|
+
def execute(self) -> DatabaseExecuteT:
|
265
274
|
"""
|
266
275
|
Build database execute instance.
|
267
276
|
|
@@ -278,7 +287,7 @@ class DatabaseSuper(
|
|
278
287
|
|
279
288
|
|
280
289
|
@property
|
281
|
-
def orm(self):
|
290
|
+
def orm(self) -> DatabaseORMT:
|
282
291
|
"""
|
283
292
|
Build database ORM instance.
|
284
293
|
|
@@ -288,13 +297,17 @@ class DatabaseSuper(
|
|
288
297
|
"""
|
289
298
|
|
290
299
|
# Build.
|
291
|
-
|
300
|
+
match self:
|
301
|
+
case Database():
|
302
|
+
orm = rorm.DatabaseORM(self)
|
303
|
+
case DatabaseAsync():
|
304
|
+
orm = rorm.DatabaseORMAsync(self)
|
292
305
|
|
293
306
|
return orm
|
294
307
|
|
295
308
|
|
296
309
|
@property
|
297
|
-
def build(self):
|
310
|
+
def build(self) -> DatabaseBuildT:
|
298
311
|
"""
|
299
312
|
Build database build instance.
|
300
313
|
|
@@ -304,9 +317,13 @@ class DatabaseSuper(
|
|
304
317
|
"""
|
305
318
|
|
306
319
|
# Build.
|
307
|
-
|
320
|
+
match self:
|
321
|
+
case Database():
|
322
|
+
build = rbuild.DatabaseBuild(self)
|
323
|
+
case DatabaseAsync():
|
324
|
+
build = rbuild.DatabaseBuildAsync(self)
|
308
325
|
|
309
|
-
return
|
326
|
+
return build
|
310
327
|
|
311
328
|
|
312
329
|
@property
|
@@ -394,7 +411,7 @@ class DatabaseSuper(
|
|
394
411
|
|
395
412
|
|
396
413
|
@property
|
397
|
-
def schema(self) ->
|
414
|
+
def schema(self) -> DatabaseSchemaT:
|
398
415
|
"""
|
399
416
|
Build database schema instance.
|
400
417
|
|
@@ -484,7 +501,9 @@ class Database(
|
|
484
501
|
Engine,
|
485
502
|
'rconn.DatabaseConnection',
|
486
503
|
'rexec.DatabaseExecute',
|
487
|
-
'rparam.DatabaseSchema'
|
504
|
+
'rparam.DatabaseSchema',
|
505
|
+
'rorm.DatabaseORM',
|
506
|
+
'rbuild.DatabaseBuild'
|
488
507
|
]
|
489
508
|
):
|
490
509
|
"""
|
@@ -497,7 +516,9 @@ class DatabaseAsync(
|
|
497
516
|
AsyncEngine,
|
498
517
|
'rconn.DatabaseConnectionAsync',
|
499
518
|
'rexec.DatabaseExecuteAsync',
|
500
|
-
'rparam.DatabaseSchemaAsync'
|
519
|
+
'rparam.DatabaseSchemaAsync',
|
520
|
+
'rorm.DatabaseORMAsync',
|
521
|
+
'rbuild.DatabaseBuildAsync'
|
501
522
|
]
|
502
523
|
):
|
503
524
|
"""
|
reydb/rerror.py
CHANGED
@@ -53,7 +53,7 @@ class DatabaseError(DatabaseBase):
|
|
53
53
|
|
54
54
|
def build_db(self) -> None:
|
55
55
|
"""
|
56
|
-
Check and build
|
56
|
+
Check and build database tables, by `self.db_names`.
|
57
57
|
"""
|
58
58
|
|
59
59
|
# Set parameter.
|
@@ -223,7 +223,7 @@ class DatabaseError(DatabaseBase):
|
|
223
223
|
|
224
224
|
# Insert.
|
225
225
|
self.db.execute.insert(
|
226
|
-
|
226
|
+
self.db_names['base.error'],
|
227
227
|
data=data
|
228
228
|
)
|
229
229
|
|
reydb/rexec.py
CHANGED
@@ -24,7 +24,7 @@ from reykit.rtime import TimeMark, time_to
|
|
24
24
|
from reykit.rwrap import wrap_runtime
|
25
25
|
|
26
26
|
from . import rconn
|
27
|
-
from .rbase import DatabaseBase, handle_sql, handle_data
|
27
|
+
from .rbase import DatabaseBase, handle_sql, handle_data, extract_path
|
28
28
|
|
29
29
|
|
30
30
|
__all__ = (
|
@@ -40,7 +40,7 @@ Result = Result_
|
|
40
40
|
monkey_sqlalchemy_row_index_field()
|
41
41
|
|
42
42
|
|
43
|
-
DatabaseConnectionT = TypeVar('DatabaseConnectionT')
|
43
|
+
DatabaseConnectionT = TypeVar('DatabaseConnectionT', 'rconn.DatabaseConnection', 'rconn.DatabaseConnectionAsync')
|
44
44
|
|
45
45
|
|
46
46
|
class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
@@ -59,7 +59,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
59
59
|
"""
|
60
60
|
|
61
61
|
# Build.
|
62
|
-
self.
|
62
|
+
self.conn = dbconn
|
63
63
|
|
64
64
|
|
65
65
|
def handle_execute(
|
@@ -87,7 +87,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
87
87
|
"""
|
88
88
|
|
89
89
|
# Handle parameter.
|
90
|
-
report = get_first_notnone(report, self.
|
90
|
+
report = get_first_notnone(report, self.conn.db.report)
|
91
91
|
sql = handle_sql(sql)
|
92
92
|
if data is None:
|
93
93
|
if kwdata == {}:
|
@@ -119,7 +119,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
119
119
|
|
120
120
|
Parameters
|
121
121
|
----------
|
122
|
-
table : Table name.
|
122
|
+
table : Table name, can include database name.
|
123
123
|
fields : Select clause content.
|
124
124
|
- `None`: Is `SELECT *`.
|
125
125
|
- `str`: Join as `SELECT str`.
|
@@ -139,6 +139,11 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
139
139
|
Parameter `sql`.
|
140
140
|
"""
|
141
141
|
|
142
|
+
# Handle parameter.
|
143
|
+
database = self.conn.db.database
|
144
|
+
if '.' in table:
|
145
|
+
database, table, _ = extract_path(table)
|
146
|
+
|
142
147
|
# Generate SQL.
|
143
148
|
sql_list = []
|
144
149
|
|
@@ -161,7 +166,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
161
166
|
sql_list.append(sql_select)
|
162
167
|
|
163
168
|
## Part 'FROM' syntax.
|
164
|
-
sql_from = f'FROM `{
|
169
|
+
sql_from = f'FROM `{database}`.`{table}`'
|
165
170
|
sql_list.append(sql_from)
|
166
171
|
|
167
172
|
## Part 'WHERE' syntax.
|
@@ -213,7 +218,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
213
218
|
|
214
219
|
Parameters
|
215
220
|
----------
|
216
|
-
table : Table name.
|
221
|
+
table : Table name, can include database name.
|
217
222
|
data : Insert data.
|
218
223
|
duplicate : Handle method when constraint error.
|
219
224
|
- `None`: Not handled.
|
@@ -230,6 +235,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
230
235
|
"""
|
231
236
|
|
232
237
|
# Handle parameter.
|
238
|
+
database = self.conn.db.database
|
239
|
+
if '.' in table:
|
240
|
+
database, table, _ = extract_path(table)
|
233
241
|
|
234
242
|
## Data.
|
235
243
|
data_table = Table(data)
|
@@ -296,14 +304,14 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
296
304
|
### Not handle.
|
297
305
|
case None:
|
298
306
|
sql = (
|
299
|
-
f'INSERT INTO `{
|
307
|
+
f'INSERT INTO `{database}`.`{table}`({sql_fields})\n'
|
300
308
|
f'VALUES({sql_values})'
|
301
309
|
)
|
302
310
|
|
303
311
|
### Ignore.
|
304
312
|
case 'ignore':
|
305
313
|
sql = (
|
306
|
-
f'INSERT IGNORE INTO `{
|
314
|
+
f'INSERT IGNORE INTO `{database}`.`{table}`({sql_fields})\n'
|
307
315
|
f'VALUES({sql_values})'
|
308
316
|
)
|
309
317
|
|
@@ -323,7 +331,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
323
331
|
]
|
324
332
|
)
|
325
333
|
sql = (
|
326
|
-
f'INSERT INTO `{
|
334
|
+
f'INSERT INTO `{database}`.`{table}`({sql_fields})\n'
|
327
335
|
f'VALUES({sql_values})\n'
|
328
336
|
'ON DUPLICATE KEY UPDATE\n'
|
329
337
|
f' {update_content}'
|
@@ -344,7 +352,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
344
352
|
|
345
353
|
Parameters
|
346
354
|
----------
|
347
|
-
table : Table name.
|
355
|
+
table : Table name, can include database name.
|
348
356
|
data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
|
349
357
|
- `Key`: Table field.
|
350
358
|
`literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
|
@@ -367,6 +375,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
367
375
|
"""
|
368
376
|
|
369
377
|
# Handle parameter.
|
378
|
+
database = self.conn.db.database
|
379
|
+
if '.' in table:
|
380
|
+
database, table, _ = extract_path(table)
|
370
381
|
|
371
382
|
## Data.
|
372
383
|
data_table = Table(data)
|
@@ -408,7 +419,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
408
419
|
if type(where_fields) == str:
|
409
420
|
where_fields = [where_fields]
|
410
421
|
sqls_list = []
|
411
|
-
sql_update = f'UPDATE `{
|
422
|
+
sql_update = f'UPDATE `{database}`.`{table}`'
|
412
423
|
for index, row in enumerate(data):
|
413
424
|
sql_parts = [sql_update]
|
414
425
|
for key, value in row.items():
|
@@ -484,7 +495,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
484
495
|
|
485
496
|
Parameters
|
486
497
|
----------
|
487
|
-
table : Table name.
|
498
|
+
table : Table name, can include database name.
|
488
499
|
where : Clause `WHERE` content, join as `WHERE str`.
|
489
500
|
order : Clause `ORDER BY` content, join as `ORDER BY str`.
|
490
501
|
limit : Clause `LIMIT` content, join as `LIMIT int/str`.
|
@@ -494,11 +505,16 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
494
505
|
Parameter `sql`.
|
495
506
|
"""
|
496
507
|
|
508
|
+
# Handle parameter.
|
509
|
+
database = self.conn.db.database
|
510
|
+
if '.' in table:
|
511
|
+
database, table, _ = extract_path(table)
|
512
|
+
|
497
513
|
# Generate SQL.
|
498
514
|
sqls = []
|
499
515
|
|
500
516
|
## Part 'DELETE' syntax.
|
501
|
-
sql_delete = f'DELETE FROM `{
|
517
|
+
sql_delete = f'DELETE FROM `{database}`.`{table}`'
|
502
518
|
sqls.append(sql_delete)
|
503
519
|
|
504
520
|
## Part 'WHERE' syntax.
|
@@ -534,7 +550,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
534
550
|
|
535
551
|
Parameters
|
536
552
|
----------
|
537
|
-
table : Table name.
|
553
|
+
table : Table name, can include database name.
|
538
554
|
where : Clause `WHERE` content, join as `WHERE str`.
|
539
555
|
limit : Clause `LIMIT` content.
|
540
556
|
- `int | str`: Join as `LIMIT int/str`.
|
@@ -551,7 +567,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
551
567
|
"""
|
552
568
|
|
553
569
|
# Handle parameter.
|
554
|
-
|
570
|
+
database = self.conn.db.database
|
571
|
+
if '.' in table:
|
572
|
+
database, table, _ = extract_path(table)
|
573
|
+
table_info: list[dict] = self.conn.db.info(database)(table)()
|
555
574
|
field_key = 'COLUMN_NAME'
|
556
575
|
fields = [
|
557
576
|
row[field_key]
|
@@ -586,7 +605,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
586
605
|
)
|
587
606
|
)
|
588
607
|
sql_fields = ', '.join(sql_fields_filter)
|
589
|
-
sql_insert = f'INSERT INTO `{
|
608
|
+
sql_insert = f'INSERT INTO `{database}`.`{table}`({sql_fields})'
|
590
609
|
sqls.append(sql_insert)
|
591
610
|
|
592
611
|
## Part 'SELECT' syntax.
|
@@ -617,7 +636,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
617
636
|
sql_values = ', '.join(sql_values_filter)
|
618
637
|
sql_select = (
|
619
638
|
f'SELECT {sql_values}\n'
|
620
|
-
f'FROM `{
|
639
|
+
f'FROM `{database}`.`{table}`'
|
621
640
|
)
|
622
641
|
sqls.append(sql_select)
|
623
642
|
|
@@ -677,13 +696,13 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
677
696
|
sql, data, report = self.handle_execute(sql, data, report, **kwdata)
|
678
697
|
|
679
698
|
# Transaction.
|
680
|
-
self.
|
699
|
+
self.conn.get_begin()
|
681
700
|
|
682
701
|
# Execute.
|
683
702
|
|
684
703
|
## Report.
|
685
704
|
if report:
|
686
|
-
execute = wrap_runtime(self.
|
705
|
+
execute = wrap_runtime(self.conn.connection.execute, to_return=True, to_print=False)
|
687
706
|
result, report_runtime, *_ = execute(sql, data)
|
688
707
|
report_info = (
|
689
708
|
f'{report_runtime}\n'
|
@@ -701,12 +720,12 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
701
720
|
|
702
721
|
## Not report.
|
703
722
|
else:
|
704
|
-
result = self.
|
723
|
+
result = self.conn.connection.execute(sql, data)
|
705
724
|
|
706
725
|
# Automatic commit.
|
707
|
-
if self.
|
708
|
-
self.
|
709
|
-
self.
|
726
|
+
if self.conn.autocommit:
|
727
|
+
self.conn.commit()
|
728
|
+
self.conn.close()
|
710
729
|
|
711
730
|
return result
|
712
731
|
|
@@ -731,7 +750,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
731
750
|
|
732
751
|
Parameters
|
733
752
|
----------
|
734
|
-
table : Table name.
|
753
|
+
table : Table name, can include database name.
|
735
754
|
fields : Select clause content.
|
736
755
|
- `None`: Is `SELECT *`.
|
737
756
|
- `str`: Join as `SELECT str`.
|
@@ -790,7 +809,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
790
809
|
|
791
810
|
Parameters
|
792
811
|
----------
|
793
|
-
table : Table name.
|
812
|
+
table : Table name, can include database name.
|
794
813
|
data : Insert data.
|
795
814
|
duplicate : Handle method when constraint error.
|
796
815
|
- `None`: Not handled.
|
@@ -842,7 +861,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
842
861
|
|
843
862
|
Parameters
|
844
863
|
----------
|
845
|
-
table : Table name.
|
864
|
+
table : Table name, can include database name.
|
846
865
|
data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
|
847
866
|
- `Key`: Table field.
|
848
867
|
`literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
|
@@ -901,7 +920,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
901
920
|
|
902
921
|
Parameters
|
903
922
|
----------
|
904
|
-
table : Table name.
|
923
|
+
table : Table name, can include database name.
|
905
924
|
where : Clause `WHERE` content, join as `WHERE str`.
|
906
925
|
order : Clause `ORDER BY` content, join as `ORDER BY str`.
|
907
926
|
limit : Clause `LIMIT` content, join as `LIMIT int/str`.
|
@@ -945,7 +964,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
945
964
|
|
946
965
|
Parameters
|
947
966
|
----------
|
948
|
-
table : Table name.
|
967
|
+
table : Table name, can include database name.
|
949
968
|
where : Clause `WHERE` content, join as `WHERE str`.
|
950
969
|
limit : Clause `LIMIT` content.
|
951
970
|
- `int | str`: Join as `LIMIT int/str`.
|
@@ -993,7 +1012,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
993
1012
|
|
994
1013
|
Parameters
|
995
1014
|
----------
|
996
|
-
table : Table name.
|
1015
|
+
table : Table name, can include database name.
|
997
1016
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
998
1017
|
- `None`: Match all.
|
999
1018
|
- `str`: Match condition.
|
@@ -1034,7 +1053,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1034
1053
|
|
1035
1054
|
Parameters
|
1036
1055
|
----------
|
1037
|
-
table : Table name.
|
1056
|
+
table : Table name, can include database name.
|
1038
1057
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
1039
1058
|
- `None`: Match all.
|
1040
1059
|
- `str`: Match condition.
|
@@ -1198,7 +1217,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1198
1217
|
sql, data, report = self.handle_execute(sql, data, report, **kwdata)
|
1199
1218
|
|
1200
1219
|
# Transaction.
|
1201
|
-
await self.
|
1220
|
+
await self.conn.get_begin()
|
1202
1221
|
|
1203
1222
|
# Execute.
|
1204
1223
|
|
@@ -1206,7 +1225,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1206
1225
|
if report:
|
1207
1226
|
tm = TimeMark()
|
1208
1227
|
tm()
|
1209
|
-
result = await self.
|
1228
|
+
result = await self.conn.connection.execute(sql, data)
|
1210
1229
|
tm()
|
1211
1230
|
|
1212
1231
|
### Generate report.
|
@@ -1238,13 +1257,13 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1238
1257
|
|
1239
1258
|
## Not report.
|
1240
1259
|
else:
|
1241
|
-
result = await self.
|
1260
|
+
result = await self.conn.connection.execute(sql, data)
|
1242
1261
|
|
1243
1262
|
# Automatic commit.
|
1244
|
-
if self.
|
1245
|
-
await self.
|
1246
|
-
await self.
|
1247
|
-
await self.
|
1263
|
+
if self.conn.autocommit:
|
1264
|
+
await self.conn.commit()
|
1265
|
+
await self.conn.close()
|
1266
|
+
await self.conn.db.dispose()
|
1248
1267
|
|
1249
1268
|
return result
|
1250
1269
|
|
@@ -1269,7 +1288,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1269
1288
|
|
1270
1289
|
Parameters
|
1271
1290
|
----------
|
1272
|
-
table : Table name.
|
1291
|
+
table : Table name, can include database name.
|
1273
1292
|
fields : Select clause content.
|
1274
1293
|
- `None`: Is `SELECT *`.
|
1275
1294
|
- `str`: Join as `SELECT str`.
|
@@ -1328,7 +1347,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1328
1347
|
|
1329
1348
|
Parameters
|
1330
1349
|
----------
|
1331
|
-
table : Table name.
|
1350
|
+
table : Table name, can include database name.
|
1332
1351
|
data : Insert data.
|
1333
1352
|
duplicate : Handle method when constraint error.
|
1334
1353
|
- `None`: Not handled.
|
@@ -1380,7 +1399,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1380
1399
|
|
1381
1400
|
Parameters
|
1382
1401
|
----------
|
1383
|
-
table : Table name.
|
1402
|
+
table : Table name, can include database name.
|
1384
1403
|
data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
|
1385
1404
|
- `Key`: Table field.
|
1386
1405
|
`literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
|
@@ -1439,7 +1458,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1439
1458
|
|
1440
1459
|
Parameters
|
1441
1460
|
----------
|
1442
|
-
table : Table name.
|
1461
|
+
table : Table name, can include database name.
|
1443
1462
|
where : Clause `WHERE` content, join as `WHERE str`.
|
1444
1463
|
order : Clause `ORDER BY` content, join as `ORDER BY str`.
|
1445
1464
|
limit : Clause `LIMIT` content, join as `LIMIT int/str`.
|
@@ -1483,7 +1502,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1483
1502
|
|
1484
1503
|
Parameters
|
1485
1504
|
----------
|
1486
|
-
table : Table name.
|
1505
|
+
table : Table name, can include database name.
|
1487
1506
|
where : Clause `WHERE` content, join as `WHERE str`.
|
1488
1507
|
limit : Clause `LIMIT` content.
|
1489
1508
|
- `int | str`: Join as `LIMIT int/str`.
|
@@ -1531,7 +1550,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1531
1550
|
|
1532
1551
|
Parameters
|
1533
1552
|
----------
|
1534
|
-
table : Table name.
|
1553
|
+
table : Table name, can include database name.
|
1535
1554
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
1536
1555
|
- `None`: Match all.
|
1537
1556
|
- `str`: Match condition.
|
@@ -1572,7 +1591,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1572
1591
|
|
1573
1592
|
Parameters
|
1574
1593
|
----------
|
1575
|
-
table : Table name.
|
1594
|
+
table : Table name, can include database name.
|
1576
1595
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
1577
1596
|
- `None`: Match all.
|
1578
1597
|
- `str`: Match condition.
|
reydb/rfile.py
CHANGED
@@ -56,7 +56,7 @@ class DatabaseFile(DatabaseBase):
|
|
56
56
|
|
57
57
|
def build_db(self) -> None:
|
58
58
|
"""
|
59
|
-
Check and build
|
59
|
+
Check and build database tables, by `self.db_names`.
|
60
60
|
"""
|
61
61
|
|
62
62
|
# Set parameter.
|
@@ -327,7 +327,7 @@ class DatabaseFile(DatabaseBase):
|
|
327
327
|
|
328
328
|
# Exist.
|
329
329
|
exist = conn.execute.exist(
|
330
|
-
|
330
|
+
self.db_names['file.data'],
|
331
331
|
'`md5` = :file_md5',
|
332
332
|
file_md5=file_md5
|
333
333
|
)
|
@@ -342,7 +342,7 @@ class DatabaseFile(DatabaseBase):
|
|
342
342
|
'bytes': file_bytes
|
343
343
|
}
|
344
344
|
conn.execute.insert(
|
345
|
-
|
345
|
+
self.db_names['file.data'],
|
346
346
|
data,
|
347
347
|
'ignore'
|
348
348
|
)
|
@@ -354,7 +354,7 @@ class DatabaseFile(DatabaseBase):
|
|
354
354
|
'note': note
|
355
355
|
}
|
356
356
|
conn.execute.insert(
|
357
|
-
|
357
|
+
self.db_names['file.information'],
|
358
358
|
data
|
359
359
|
)
|
360
360
|
|