reydb 1.1.59__py3-none-any.whl → 1.1.61__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/__init__.py +0 -1
- reydb/rall.py +0 -1
- reydb/rbase.py +0 -10
- reydb/rbuild.py +683 -177
- reydb/rconfig.py +435 -104
- reydb/rconn.py +44 -40
- reydb/rdb.py +88 -72
- reydb/rerror.py +2 -2
- reydb/rexec.py +89 -121
- reydb/rfile.py +4 -4
- reydb/rorm.py +41 -24
- reydb/rparam.py +191 -56
- {reydb-1.1.59.dist-info → reydb-1.1.61.dist-info}/METADATA +1 -1
- reydb-1.1.61.dist-info/RECORD +16 -0
- reydb/rinfo.py +0 -499
- reydb-1.1.59.dist-info/RECORD +0 -17
- {reydb-1.1.59.dist-info → reydb-1.1.61.dist-info}/WHEEL +0 -0
- {reydb-1.1.59.dist-info → reydb-1.1.61.dist-info}/licenses/LICENSE +0 -0
reydb/rexec.py
CHANGED
@@ -24,11 +24,12 @@ 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__ = (
|
31
31
|
'Result',
|
32
|
+
'DatabaseExecuteSuper',
|
32
33
|
'DatabaseExecute',
|
33
34
|
'DatabaseExecuteAsync'
|
34
35
|
)
|
@@ -40,7 +41,7 @@ Result = Result_
|
|
40
41
|
monkey_sqlalchemy_row_index_field()
|
41
42
|
|
42
43
|
|
43
|
-
DatabaseConnectionT = TypeVar('DatabaseConnectionT')
|
44
|
+
DatabaseConnectionT = TypeVar('DatabaseConnectionT', 'rconn.DatabaseConnection', 'rconn.DatabaseConnectionAsync')
|
44
45
|
|
45
46
|
|
46
47
|
class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
@@ -59,7 +60,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
59
60
|
"""
|
60
61
|
|
61
62
|
# Build.
|
62
|
-
self.
|
63
|
+
self.conn = dbconn
|
63
64
|
|
64
65
|
|
65
66
|
def handle_execute(
|
@@ -87,7 +88,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
87
88
|
"""
|
88
89
|
|
89
90
|
# Handle parameter.
|
90
|
-
report = get_first_notnone(report, self.
|
91
|
+
report = get_first_notnone(report, self.conn.db.report)
|
91
92
|
sql = handle_sql(sql)
|
92
93
|
if data is None:
|
93
94
|
if kwdata == {}:
|
@@ -119,7 +120,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
119
120
|
|
120
121
|
Parameters
|
121
122
|
----------
|
122
|
-
table : Table name.
|
123
|
+
table : Table name, can include database name.
|
123
124
|
fields : Select clause content.
|
124
125
|
- `None`: Is `SELECT *`.
|
125
126
|
- `str`: Join as `SELECT str`.
|
@@ -139,6 +140,11 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
139
140
|
Parameter `sql`.
|
140
141
|
"""
|
141
142
|
|
143
|
+
# Handle parameter.
|
144
|
+
database = self.conn.db.database
|
145
|
+
if '.' in table:
|
146
|
+
database, table, _ = extract_path(table)
|
147
|
+
|
142
148
|
# Generate SQL.
|
143
149
|
sql_list = []
|
144
150
|
|
@@ -161,7 +167,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
161
167
|
sql_list.append(sql_select)
|
162
168
|
|
163
169
|
## Part 'FROM' syntax.
|
164
|
-
sql_from = f'FROM `{
|
170
|
+
sql_from = f'FROM `{database}`.`{table}`'
|
165
171
|
sql_list.append(sql_from)
|
166
172
|
|
167
173
|
## Part 'WHERE' syntax.
|
@@ -213,7 +219,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
213
219
|
|
214
220
|
Parameters
|
215
221
|
----------
|
216
|
-
table : Table name.
|
222
|
+
table : Table name, can include database name.
|
217
223
|
data : Insert data.
|
218
224
|
duplicate : Handle method when constraint error.
|
219
225
|
- `None`: Not handled.
|
@@ -230,6 +236,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
230
236
|
"""
|
231
237
|
|
232
238
|
# Handle parameter.
|
239
|
+
database = self.conn.db.database
|
240
|
+
if '.' in table:
|
241
|
+
database, table, _ = extract_path(table)
|
233
242
|
|
234
243
|
## Data.
|
235
244
|
data_table = Table(data)
|
@@ -296,14 +305,14 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
296
305
|
### Not handle.
|
297
306
|
case None:
|
298
307
|
sql = (
|
299
|
-
f'INSERT INTO `{
|
308
|
+
f'INSERT INTO `{database}`.`{table}`({sql_fields})\n'
|
300
309
|
f'VALUES({sql_values})'
|
301
310
|
)
|
302
311
|
|
303
312
|
### Ignore.
|
304
313
|
case 'ignore':
|
305
314
|
sql = (
|
306
|
-
f'INSERT IGNORE INTO `{
|
315
|
+
f'INSERT IGNORE INTO `{database}`.`{table}`({sql_fields})\n'
|
307
316
|
f'VALUES({sql_values})'
|
308
317
|
)
|
309
318
|
|
@@ -323,7 +332,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
323
332
|
]
|
324
333
|
)
|
325
334
|
sql = (
|
326
|
-
f'INSERT INTO `{
|
335
|
+
f'INSERT INTO `{database}`.`{table}`({sql_fields})\n'
|
327
336
|
f'VALUES({sql_values})\n'
|
328
337
|
'ON DUPLICATE KEY UPDATE\n'
|
329
338
|
f' {update_content}'
|
@@ -344,7 +353,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
344
353
|
|
345
354
|
Parameters
|
346
355
|
----------
|
347
|
-
table : Table name.
|
356
|
+
table : Table name, can include database name.
|
348
357
|
data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
|
349
358
|
- `Key`: Table field.
|
350
359
|
`literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
|
@@ -367,6 +376,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
367
376
|
"""
|
368
377
|
|
369
378
|
# Handle parameter.
|
379
|
+
database = self.conn.db.database
|
380
|
+
if '.' in table:
|
381
|
+
database, table, _ = extract_path(table)
|
370
382
|
|
371
383
|
## Data.
|
372
384
|
data_table = Table(data)
|
@@ -408,7 +420,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
408
420
|
if type(where_fields) == str:
|
409
421
|
where_fields = [where_fields]
|
410
422
|
sqls_list = []
|
411
|
-
sql_update = f'UPDATE `{
|
423
|
+
sql_update = f'UPDATE `{database}`.`{table}`'
|
412
424
|
for index, row in enumerate(data):
|
413
425
|
sql_parts = [sql_update]
|
414
426
|
for key, value in row.items():
|
@@ -484,7 +496,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
484
496
|
|
485
497
|
Parameters
|
486
498
|
----------
|
487
|
-
table : Table name.
|
499
|
+
table : Table name, can include database name.
|
488
500
|
where : Clause `WHERE` content, join as `WHERE str`.
|
489
501
|
order : Clause `ORDER BY` content, join as `ORDER BY str`.
|
490
502
|
limit : Clause `LIMIT` content, join as `LIMIT int/str`.
|
@@ -494,11 +506,16 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
494
506
|
Parameter `sql`.
|
495
507
|
"""
|
496
508
|
|
509
|
+
# Handle parameter.
|
510
|
+
database = self.conn.db.database
|
511
|
+
if '.' in table:
|
512
|
+
database, table, _ = extract_path(table)
|
513
|
+
|
497
514
|
# Generate SQL.
|
498
515
|
sqls = []
|
499
516
|
|
500
517
|
## Part 'DELETE' syntax.
|
501
|
-
sql_delete = f'DELETE FROM `{
|
518
|
+
sql_delete = f'DELETE FROM `{database}`.`{table}`'
|
502
519
|
sqls.append(sql_delete)
|
503
520
|
|
504
521
|
## Part 'WHERE' syntax.
|
@@ -525,25 +542,24 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
525
542
|
def handle_copy(
|
526
543
|
self,
|
527
544
|
table: str,
|
545
|
+
fields: str | Iterable[str] | None = None,
|
528
546
|
where: str | None = None,
|
529
|
-
limit: int | str | tuple[int, int] | None = None
|
530
|
-
**kwdata: Any
|
547
|
+
limit: int | str | tuple[int, int] | None = None
|
531
548
|
) -> Result:
|
532
549
|
"""
|
533
550
|
Execute inesrt SQL of copy records.
|
534
551
|
|
535
552
|
Parameters
|
536
553
|
----------
|
537
|
-
table : Table name.
|
554
|
+
table : Table name, can include database name.
|
555
|
+
fields : Select clause content.
|
556
|
+
- `None`: Is `SELECT *`.
|
557
|
+
- `str`: Join as `SELECT str`.
|
558
|
+
- `Iterable[str]`: Join as `SELECT str`.
|
538
559
|
where : Clause `WHERE` content, join as `WHERE str`.
|
539
560
|
limit : Clause `LIMIT` content.
|
540
561
|
- `int | str`: Join as `LIMIT int/str`.
|
541
562
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
542
|
-
kwdata : Keyword parameters for filling.
|
543
|
-
- `In 'WHERE' syntax`: Fill 'WHERE' syntax.
|
544
|
-
- `Not in 'WHERE' syntax`: Fill 'INSERT' and 'SELECT' syntax.
|
545
|
-
`str and first character is ':'`: Use this syntax.
|
546
|
-
`Any`: Use this value.
|
547
563
|
|
548
564
|
Returns
|
549
565
|
-------
|
@@ -551,73 +567,27 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
551
567
|
"""
|
552
568
|
|
553
569
|
# Handle parameter.
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
if type(where) == str:
|
562
|
-
where_keys = findall(pattern, where)
|
563
|
-
else:
|
564
|
-
where_keys = ()
|
570
|
+
database = self.conn.db.database
|
571
|
+
if '.' in table:
|
572
|
+
database, table, _ = extract_path(table)
|
573
|
+
if fields is None:
|
574
|
+
fields = '*'
|
575
|
+
elif type(fields) != str:
|
576
|
+
fields = ', '.join(fields)
|
565
577
|
|
566
578
|
# Generate SQL.
|
567
579
|
sqls = []
|
568
580
|
|
569
581
|
## Part 'INSERT' syntax.
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
if field not in kwdata
|
574
|
-
)
|
575
|
-
if kwdata != {}:
|
576
|
-
sql_fields_kwdata = ', '.join(
|
577
|
-
f'`{field}`'
|
578
|
-
for field in kwdata
|
579
|
-
if field not in where_keys
|
580
|
-
)
|
581
|
-
sql_fields_filter = filter(
|
582
|
-
lambda sql: sql != '',
|
583
|
-
(
|
584
|
-
sql_fields,
|
585
|
-
sql_fields_kwdata
|
586
|
-
)
|
587
|
-
)
|
588
|
-
sql_fields = ', '.join(sql_fields_filter)
|
589
|
-
sql_insert = f'INSERT INTO `{self.dbconn.db.database}`.`{table}`({sql_fields})'
|
582
|
+
sql_insert = f'INSERT INTO `{database}`.`{table}`'
|
583
|
+
if fields != '*':
|
584
|
+
sql_insert += f'({fields})'
|
590
585
|
sqls.append(sql_insert)
|
591
586
|
|
592
587
|
## Part 'SELECT' syntax.
|
593
|
-
sql_values = ', '.join(
|
594
|
-
f'`{field}`'
|
595
|
-
for field in fields
|
596
|
-
if field not in kwdata
|
597
|
-
)
|
598
|
-
if kwdata != {}:
|
599
|
-
sql_values_kwdata = ', '.join(
|
600
|
-
value[1:]
|
601
|
-
if (
|
602
|
-
type(value) == str
|
603
|
-
and value.startswith(':')
|
604
|
-
and value != ':'
|
605
|
-
)
|
606
|
-
else f':{field}'
|
607
|
-
for field, value in kwdata.items()
|
608
|
-
if field not in where_keys
|
609
|
-
)
|
610
|
-
sql_values_filter = filter(
|
611
|
-
lambda sql: sql != '',
|
612
|
-
(
|
613
|
-
sql_values,
|
614
|
-
sql_values_kwdata
|
615
|
-
)
|
616
|
-
)
|
617
|
-
sql_values = ', '.join(sql_values_filter)
|
618
588
|
sql_select = (
|
619
|
-
f'SELECT {
|
620
|
-
f'FROM `{
|
589
|
+
f'SELECT {fields}\n'
|
590
|
+
f'FROM `{database}`.`{table}`'
|
621
591
|
)
|
622
592
|
sqls.append(sql_select)
|
623
593
|
|
@@ -677,13 +647,13 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
677
647
|
sql, data, report = self.handle_execute(sql, data, report, **kwdata)
|
678
648
|
|
679
649
|
# Transaction.
|
680
|
-
self.
|
650
|
+
self.conn.get_begin()
|
681
651
|
|
682
652
|
# Execute.
|
683
653
|
|
684
654
|
## Report.
|
685
655
|
if report:
|
686
|
-
execute = wrap_runtime(self.
|
656
|
+
execute = wrap_runtime(self.conn.connection.execute, to_return=True, to_print=False)
|
687
657
|
result, report_runtime, *_ = execute(sql, data)
|
688
658
|
report_info = (
|
689
659
|
f'{report_runtime}\n'
|
@@ -701,12 +671,12 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
701
671
|
|
702
672
|
## Not report.
|
703
673
|
else:
|
704
|
-
result = self.
|
674
|
+
result = self.conn.connection.execute(sql, data)
|
705
675
|
|
706
676
|
# Automatic commit.
|
707
|
-
if self.
|
708
|
-
self.
|
709
|
-
self.
|
677
|
+
if self.conn.autocommit:
|
678
|
+
self.conn.commit()
|
679
|
+
self.conn.close()
|
710
680
|
|
711
681
|
return result
|
712
682
|
|
@@ -731,7 +701,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
731
701
|
|
732
702
|
Parameters
|
733
703
|
----------
|
734
|
-
table : Table name.
|
704
|
+
table : Table name, can include database name.
|
735
705
|
fields : Select clause content.
|
736
706
|
- `None`: Is `SELECT *`.
|
737
707
|
- `str`: Join as `SELECT str`.
|
@@ -790,7 +760,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
790
760
|
|
791
761
|
Parameters
|
792
762
|
----------
|
793
|
-
table : Table name.
|
763
|
+
table : Table name, can include database name.
|
794
764
|
data : Insert data.
|
795
765
|
duplicate : Handle method when constraint error.
|
796
766
|
- `None`: Not handled.
|
@@ -842,7 +812,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
842
812
|
|
843
813
|
Parameters
|
844
814
|
----------
|
845
|
-
table : Table name.
|
815
|
+
table : Table name, can include database name.
|
846
816
|
data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
|
847
817
|
- `Key`: Table field.
|
848
818
|
`literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
|
@@ -901,7 +871,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
901
871
|
|
902
872
|
Parameters
|
903
873
|
----------
|
904
|
-
table : Table name.
|
874
|
+
table : Table name, can include database name.
|
905
875
|
where : Clause `WHERE` content, join as `WHERE str`.
|
906
876
|
order : Clause `ORDER BY` content, join as `ORDER BY str`.
|
907
877
|
limit : Clause `LIMIT` content, join as `LIMIT int/str`.
|
@@ -935,6 +905,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
935
905
|
def copy(
|
936
906
|
self,
|
937
907
|
table: str,
|
908
|
+
fields: str | Iterable[str] | None = None,
|
938
909
|
where: str | None = None,
|
939
910
|
limit: int | str | tuple[int, int] | None = None,
|
940
911
|
report: bool | None = None,
|
@@ -945,18 +916,16 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
945
916
|
|
946
917
|
Parameters
|
947
918
|
----------
|
948
|
-
table : Table name.
|
919
|
+
table : Table name, can include database name.
|
920
|
+
fields : Select clause content.
|
921
|
+
- `None`: Is `SELECT *`.
|
922
|
+
- `str`: Join as `SELECT str`.
|
923
|
+
- `Iterable[str]`: Join as `SELECT str`.
|
949
924
|
where : Clause `WHERE` content, join as `WHERE str`.
|
950
925
|
limit : Clause `LIMIT` content.
|
951
926
|
- `int | str`: Join as `LIMIT int/str`.
|
952
927
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
953
|
-
report : Whether report SQL execute information.
|
954
|
-
- `None`: Use attribute `Database.report`.
|
955
928
|
kwdata : Keyword parameters for filling.
|
956
|
-
- `In 'WHERE' syntax`: Fill 'WHERE' syntax.
|
957
|
-
- `Not in 'WHERE' syntax`: Fill 'INSERT' and 'SELECT' syntax.
|
958
|
-
`str and first character is ':'`: Use this syntax.
|
959
|
-
`Any`: Use this value.
|
960
929
|
|
961
930
|
Returns
|
962
931
|
-------
|
@@ -973,7 +942,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
973
942
|
"""
|
974
943
|
|
975
944
|
# Handle parameter.
|
976
|
-
sql = self.handle_copy(table, where, limit
|
945
|
+
sql = self.handle_copy(table, fields, where, limit)
|
977
946
|
|
978
947
|
# Execute SQL.
|
979
948
|
result = self.execute(sql, report=report, **kwdata)
|
@@ -993,7 +962,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
993
962
|
|
994
963
|
Parameters
|
995
964
|
----------
|
996
|
-
table : Table name.
|
965
|
+
table : Table name, can include database name.
|
997
966
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
998
967
|
- `None`: Match all.
|
999
968
|
- `str`: Match condition.
|
@@ -1034,7 +1003,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1034
1003
|
|
1035
1004
|
Parameters
|
1036
1005
|
----------
|
1037
|
-
table : Table name.
|
1006
|
+
table : Table name, can include database name.
|
1038
1007
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
1039
1008
|
- `None`: Match all.
|
1040
1009
|
- `str`: Match condition.
|
@@ -1198,7 +1167,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1198
1167
|
sql, data, report = self.handle_execute(sql, data, report, **kwdata)
|
1199
1168
|
|
1200
1169
|
# Transaction.
|
1201
|
-
await self.
|
1170
|
+
await self.conn.get_begin()
|
1202
1171
|
|
1203
1172
|
# Execute.
|
1204
1173
|
|
@@ -1206,7 +1175,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1206
1175
|
if report:
|
1207
1176
|
tm = TimeMark()
|
1208
1177
|
tm()
|
1209
|
-
result = await self.
|
1178
|
+
result = await self.conn.connection.execute(sql, data)
|
1210
1179
|
tm()
|
1211
1180
|
|
1212
1181
|
### Generate report.
|
@@ -1238,13 +1207,13 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1238
1207
|
|
1239
1208
|
## Not report.
|
1240
1209
|
else:
|
1241
|
-
result = await self.
|
1210
|
+
result = await self.conn.connection.execute(sql, data)
|
1242
1211
|
|
1243
1212
|
# Automatic commit.
|
1244
|
-
if self.
|
1245
|
-
await self.
|
1246
|
-
await self.
|
1247
|
-
await self.
|
1213
|
+
if self.conn.autocommit:
|
1214
|
+
await self.conn.commit()
|
1215
|
+
await self.conn.close()
|
1216
|
+
await self.conn.db.dispose()
|
1248
1217
|
|
1249
1218
|
return result
|
1250
1219
|
|
@@ -1269,7 +1238,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1269
1238
|
|
1270
1239
|
Parameters
|
1271
1240
|
----------
|
1272
|
-
table : Table name.
|
1241
|
+
table : Table name, can include database name.
|
1273
1242
|
fields : Select clause content.
|
1274
1243
|
- `None`: Is `SELECT *`.
|
1275
1244
|
- `str`: Join as `SELECT str`.
|
@@ -1328,7 +1297,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1328
1297
|
|
1329
1298
|
Parameters
|
1330
1299
|
----------
|
1331
|
-
table : Table name.
|
1300
|
+
table : Table name, can include database name.
|
1332
1301
|
data : Insert data.
|
1333
1302
|
duplicate : Handle method when constraint error.
|
1334
1303
|
- `None`: Not handled.
|
@@ -1380,7 +1349,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1380
1349
|
|
1381
1350
|
Parameters
|
1382
1351
|
----------
|
1383
|
-
table : Table name.
|
1352
|
+
table : Table name, can include database name.
|
1384
1353
|
data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
|
1385
1354
|
- `Key`: Table field.
|
1386
1355
|
`literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
|
@@ -1439,7 +1408,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1439
1408
|
|
1440
1409
|
Parameters
|
1441
1410
|
----------
|
1442
|
-
table : Table name.
|
1411
|
+
table : Table name, can include database name.
|
1443
1412
|
where : Clause `WHERE` content, join as `WHERE str`.
|
1444
1413
|
order : Clause `ORDER BY` content, join as `ORDER BY str`.
|
1445
1414
|
limit : Clause `LIMIT` content, join as `LIMIT int/str`.
|
@@ -1473,6 +1442,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1473
1442
|
async def copy(
|
1474
1443
|
self,
|
1475
1444
|
table: str,
|
1445
|
+
fields: str | Iterable[str] | None = None,
|
1476
1446
|
where: str | None = None,
|
1477
1447
|
limit: int | str | tuple[int, int] | None = None,
|
1478
1448
|
report: bool | None = None,
|
@@ -1483,18 +1453,16 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1483
1453
|
|
1484
1454
|
Parameters
|
1485
1455
|
----------
|
1486
|
-
table : Table name.
|
1456
|
+
table : Table name, can include database name.
|
1457
|
+
fields : Select clause content.
|
1458
|
+
- `None`: Is `SELECT *`.
|
1459
|
+
- `str`: Join as `SELECT str`.
|
1460
|
+
- `Iterable[str]`: Join as `SELECT str`.
|
1487
1461
|
where : Clause `WHERE` content, join as `WHERE str`.
|
1488
1462
|
limit : Clause `LIMIT` content.
|
1489
1463
|
- `int | str`: Join as `LIMIT int/str`.
|
1490
1464
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
1491
|
-
report : Whether report SQL execute information.
|
1492
|
-
- `None`: Use attribute `Database.report`.
|
1493
1465
|
kwdata : Keyword parameters for filling.
|
1494
|
-
- `In 'WHERE' syntax`: Fill 'WHERE' syntax.
|
1495
|
-
- `Not in 'WHERE' syntax`: Fill 'INSERT' and 'SELECT' syntax.
|
1496
|
-
`str and first character is ':'`: Use this syntax.
|
1497
|
-
`Any`: Use this value.
|
1498
1466
|
|
1499
1467
|
Returns
|
1500
1468
|
-------
|
@@ -1511,7 +1479,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1511
1479
|
"""
|
1512
1480
|
|
1513
1481
|
# Handle parameter.
|
1514
|
-
sql = self.handle_copy(table, where, limit
|
1482
|
+
sql = self.handle_copy(table, fields, where, limit)
|
1515
1483
|
|
1516
1484
|
# Execute SQL.
|
1517
1485
|
result = await self.execute(sql, report=report, **kwdata)
|
@@ -1531,7 +1499,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1531
1499
|
|
1532
1500
|
Parameters
|
1533
1501
|
----------
|
1534
|
-
table : Table name.
|
1502
|
+
table : Table name, can include database name.
|
1535
1503
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
1536
1504
|
- `None`: Match all.
|
1537
1505
|
- `str`: Match condition.
|
@@ -1572,7 +1540,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1572
1540
|
|
1573
1541
|
Parameters
|
1574
1542
|
----------
|
1575
|
-
table : Table name.
|
1543
|
+
table : Table name, can include database name.
|
1576
1544
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
1577
1545
|
- `None`: Match all.
|
1578
1546
|
- `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
|
|