reydb 1.1.60__py3-none-any.whl → 1.2.0__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 -2
- reydb/rall.py +0 -2
- reydb/rbase.py +0 -48
- reydb/rbuild.py +129 -315
- reydb/rconfig.py +379 -42
- reydb/rdb.py +77 -84
- reydb/rerror.py +298 -109
- reydb/rexec.py +148 -168
- reydb/rorm.py +151 -120
- reydb/rparam.py +408 -68
- {reydb-1.1.60.dist-info → reydb-1.2.0.dist-info}/METADATA +1 -1
- reydb-1.2.0.dist-info/RECORD +15 -0
- reydb/rfile.py +0 -482
- reydb/rinfo.py +0 -499
- reydb-1.1.60.dist-info/RECORD +0 -17
- {reydb-1.1.60.dist-info → reydb-1.2.0.dist-info}/WHEEL +0 -0
- {reydb-1.1.60.dist-info → reydb-1.2.0.dist-info}/licenses/LICENSE +0 -0
reydb/rbuild.py
CHANGED
@@ -15,12 +15,14 @@ from reykit.rbase import throw, is_instance
|
|
15
15
|
from reykit.rstdout import ask
|
16
16
|
|
17
17
|
from . import rdb
|
18
|
-
from .rbase import DatabaseBase
|
18
|
+
from .rbase import DatabaseBase
|
19
19
|
from .rorm import DatabaseORMModel
|
20
20
|
|
21
21
|
|
22
22
|
__all__ = (
|
23
|
+
'DatabaseBuildSuper',
|
23
24
|
'DatabaseBuild',
|
25
|
+
'DatabaseBuildAsync'
|
24
26
|
)
|
25
27
|
|
26
28
|
|
@@ -64,7 +66,6 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
64
66
|
|
65
67
|
# Set attribute.
|
66
68
|
self.db = db
|
67
|
-
self._schema: dict[str, dict[str, list[str]]] | None = None
|
68
69
|
|
69
70
|
|
70
71
|
def get_sql_create_database(
|
@@ -230,8 +231,8 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
230
231
|
|
231
232
|
Parameters
|
232
233
|
----------
|
233
|
-
path :
|
234
|
-
- `str`:
|
234
|
+
path : Path.
|
235
|
+
- `str`: Table name.
|
235
236
|
- `tuple[str, str]`: Database name and table name.
|
236
237
|
fields : Fields set table.
|
237
238
|
- `Key 'name'`: Field name, required.
|
@@ -276,7 +277,9 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
276
277
|
|
277
278
|
# Handle parameter.
|
278
279
|
if type(path) == str:
|
279
|
-
database, table
|
280
|
+
database, table = self.db.database, path
|
281
|
+
else:
|
282
|
+
database, table = path
|
280
283
|
if fields.__class__ == dict:
|
281
284
|
fields = [fields]
|
282
285
|
if primary.__class__ == str:
|
@@ -349,9 +352,9 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
349
352
|
|
350
353
|
Parameters
|
351
354
|
----------
|
352
|
-
path :
|
353
|
-
- `str`:
|
354
|
-
- `tuple[str, str]`: Database name and
|
355
|
+
path : Path.
|
356
|
+
- `str`: Table name.
|
357
|
+
- `tuple[str, str]`: Database name and table name.
|
355
358
|
select : View select SQL.
|
356
359
|
execute : Whether directly execute.
|
357
360
|
|
@@ -361,11 +364,14 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
361
364
|
"""
|
362
365
|
|
363
366
|
# Handle parameter.
|
364
|
-
|
367
|
+
if type(path) == str:
|
368
|
+
database, table = self.db.database, path
|
369
|
+
else:
|
370
|
+
database, table = path
|
365
371
|
|
366
372
|
# Generate SQL.
|
367
373
|
select = select.replace('\n', '\n ')
|
368
|
-
sql = 'CREATE VIEW
|
374
|
+
sql = f'CREATE VIEW `{database}`.`{table}` AS (\n {select}\n)'
|
369
375
|
|
370
376
|
return sql
|
371
377
|
|
@@ -380,9 +386,9 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
380
386
|
|
381
387
|
Parameters
|
382
388
|
----------
|
383
|
-
path :
|
384
|
-
- `str`:
|
385
|
-
- `tuple[str, str]`: Database name and
|
389
|
+
path : Path.
|
390
|
+
- `str`: Table name.
|
391
|
+
- `tuple[str, str]`: Database name and table name.
|
386
392
|
items : Items set table.
|
387
393
|
- `Key 'name'`: Item name, required.
|
388
394
|
- `Key 'select'`: Item select SQL, must only return one value, required.
|
@@ -462,8 +468,8 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
462
468
|
|
463
469
|
Parameters
|
464
470
|
----------
|
465
|
-
path :
|
466
|
-
- `str`:
|
471
|
+
path : Path.
|
472
|
+
- `str`: Table name.
|
467
473
|
- `tuple[str, str]`: Database name and table name.
|
468
474
|
execute : Whether directly execute.
|
469
475
|
|
@@ -473,7 +479,10 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
473
479
|
"""
|
474
480
|
|
475
481
|
# Handle parameter.
|
476
|
-
|
482
|
+
if type(path) == str:
|
483
|
+
database, table = self.db.database, path
|
484
|
+
else:
|
485
|
+
database, table = path
|
477
486
|
|
478
487
|
# Generate.
|
479
488
|
sql = f'DROP TABLE `{database}`.`{table}`'
|
@@ -490,9 +499,9 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
490
499
|
|
491
500
|
Parameters
|
492
501
|
----------
|
493
|
-
path :
|
494
|
-
- `str`:
|
495
|
-
- `tuple[str, str]`: Database name and
|
502
|
+
path : Path.
|
503
|
+
- `str`: Table name.
|
504
|
+
- `tuple[str, str]`: Database name and table name.
|
496
505
|
execute : Whether directly execute.
|
497
506
|
|
498
507
|
Returns
|
@@ -501,10 +510,13 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
501
510
|
"""
|
502
511
|
|
503
512
|
# Handle parameter.
|
504
|
-
|
513
|
+
if type(path) == str:
|
514
|
+
database, table = self.db.database, path
|
515
|
+
else:
|
516
|
+
database, table = path
|
505
517
|
|
506
518
|
# Generate SQL.
|
507
|
-
sql = 'DROP VIEW `%s`.`%s`' % (database,
|
519
|
+
sql = 'DROP VIEW `%s`.`%s`' % (database, table)
|
508
520
|
|
509
521
|
return sql
|
510
522
|
|
@@ -566,8 +578,8 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
566
578
|
|
567
579
|
Parameters
|
568
580
|
----------
|
569
|
-
path :
|
570
|
-
- `str`:
|
581
|
+
path : Path.
|
582
|
+
- `str`: Table name.
|
571
583
|
- `tuple[str, str]`: Database name and table name.
|
572
584
|
fields : Fields set table.
|
573
585
|
- `Key 'name'`: Field name, required.
|
@@ -605,7 +617,10 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
605
617
|
"""
|
606
618
|
|
607
619
|
# Handle parameter.
|
608
|
-
|
620
|
+
if type(path) == str:
|
621
|
+
database, table = self.db.database, path
|
622
|
+
else:
|
623
|
+
database, table = path
|
609
624
|
if fields.__class__ == dict:
|
610
625
|
fields = [fields]
|
611
626
|
if primary.__class__ == str:
|
@@ -676,8 +691,8 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
676
691
|
|
677
692
|
Parameters
|
678
693
|
----------
|
679
|
-
path :
|
680
|
-
- `str`:
|
694
|
+
path : Path.
|
695
|
+
- `str`: Table name.
|
681
696
|
- `tuple[str, str]`: Database name and table name.
|
682
697
|
fields : Delete fields name.
|
683
698
|
primary : Whether delete primary key.
|
@@ -690,7 +705,10 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
690
705
|
"""
|
691
706
|
|
692
707
|
# Handle parameter.
|
693
|
-
|
708
|
+
if type(path) == str:
|
709
|
+
database, table = self.db.database, path
|
710
|
+
else:
|
711
|
+
database, table = path
|
694
712
|
if fields.__class__ == str:
|
695
713
|
fields = [fields]
|
696
714
|
if indexes.__class__ == str:
|
@@ -745,8 +763,8 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
745
763
|
|
746
764
|
Parameters
|
747
765
|
----------
|
748
|
-
path :
|
749
|
-
- `str`:
|
766
|
+
path : Path.
|
767
|
+
- `str`: Table name.
|
750
768
|
- `tuple[str, str]`: Database name and table name.
|
751
769
|
fields : Fields set table.
|
752
770
|
- `Key 'name'`: Field name, required.
|
@@ -775,7 +793,10 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
775
793
|
"""
|
776
794
|
|
777
795
|
# Handle parameter.
|
778
|
-
|
796
|
+
if type(path) == str:
|
797
|
+
database, table = self.db.database, path
|
798
|
+
else:
|
799
|
+
database, table = path
|
779
800
|
if fields.__class__ == dict:
|
780
801
|
fields = [fields]
|
781
802
|
|
@@ -854,9 +875,9 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
854
875
|
|
855
876
|
Parameters
|
856
877
|
----------
|
857
|
-
path :
|
858
|
-
- `str`:
|
859
|
-
- `tuple[str, str]`: Database name and
|
878
|
+
path : Path.
|
879
|
+
- `str`: Table name.
|
880
|
+
- `tuple[str, str]`: Database name and table name.
|
860
881
|
select : View select SQL.
|
861
882
|
execute : Whether directly execute.
|
862
883
|
|
@@ -866,10 +887,13 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
866
887
|
"""
|
867
888
|
|
868
889
|
# Handle parameter.
|
869
|
-
|
890
|
+
if type(path) == str:
|
891
|
+
database, table = self.db.database, path
|
892
|
+
else:
|
893
|
+
database, table = path
|
870
894
|
|
871
895
|
# Generate SQL.
|
872
|
-
sql = 'ALTER VIEW `%s`.`%s` AS\n%s' % (database,
|
896
|
+
sql = 'ALTER VIEW `%s`.`%s` AS\n%s' % (database, table, select)
|
873
897
|
|
874
898
|
return sql
|
875
899
|
|
@@ -883,8 +907,8 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
883
907
|
|
884
908
|
Parameters
|
885
909
|
----------
|
886
|
-
path :
|
887
|
-
- `str`:
|
910
|
+
path : Path.
|
911
|
+
- `str`: Table name.
|
888
912
|
- `tuple[str, str]`: Database name and table name.
|
889
913
|
execute : Whether directly execute.
|
890
914
|
|
@@ -894,7 +918,10 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
894
918
|
"""
|
895
919
|
|
896
920
|
# Handle parameter.
|
897
|
-
|
921
|
+
if type(path) == str:
|
922
|
+
database, table = self.db.database, path
|
923
|
+
else:
|
924
|
+
database, table = path
|
898
925
|
|
899
926
|
# Generate.
|
900
927
|
sql = f'TRUNCATE TABLE `{database}`.`{table}`'
|
@@ -956,7 +983,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
956
983
|
"""
|
957
984
|
|
958
985
|
# Get.
|
959
|
-
table = model.
|
986
|
+
table = model._table()
|
960
987
|
text = f'TABLE `{self.db.database}`.`{table}`'
|
961
988
|
if 'mysql_charset' in table.kwargs:
|
962
989
|
text += f" | CHARSET '{table.kwargs['mysql_charset']}'"
|
@@ -1013,215 +1040,12 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
1013
1040
|
return text
|
1014
1041
|
|
1015
1042
|
|
1016
|
-
def build(
|
1017
|
-
self,
|
1018
|
-
databases: list[dict] | None = None,
|
1019
|
-
tables: list[dict] | None = None,
|
1020
|
-
tables_orm: list[Type[DatabaseORMModel]] | None = None,
|
1021
|
-
views: list[dict] | None = None,
|
1022
|
-
views_stats: list[dict] | None = None,
|
1023
|
-
ask: bool = True,
|
1024
|
-
skip: bool = False
|
1025
|
-
) -> None:
|
1026
|
-
"""
|
1027
|
-
Build databases or tables.
|
1028
|
-
|
1029
|
-
Parameters
|
1030
|
-
----------
|
1031
|
-
databases : Database build parameters, equivalent to the parameters of method `self.create_database`.
|
1032
|
-
tables : Tables build parameters, equivalent to the parameters of method `self.create_table`.
|
1033
|
-
tables_orm : Tables buile model, equivalent to the parameters of method `self.create_table_orm`.
|
1034
|
-
views : Views build parameters, equivalent to the parameters of method `self.create_view`.
|
1035
|
-
views_stats : Views stats build parameters, equivalent to the parameters of method `self.create_view_stats`.
|
1036
|
-
ask : Whether ask confirm execute.
|
1037
|
-
skip : Whether skip existing table.
|
1038
|
-
"""
|
1039
|
-
|
1040
|
-
# Handle parameter.
|
1041
|
-
databases = databases or []
|
1042
|
-
tables = tables or []
|
1043
|
-
tables_orm = tables_orm or []
|
1044
|
-
views = views or []
|
1045
|
-
views_stats = views_stats or []
|
1046
|
-
|
1047
|
-
# Database.
|
1048
|
-
for params in databases:
|
1049
|
-
database = params['name']
|
1050
|
-
|
1051
|
-
## Exist.
|
1052
|
-
if (
|
1053
|
-
skip
|
1054
|
-
and self.exist(database)
|
1055
|
-
):
|
1056
|
-
continue
|
1057
|
-
|
1058
|
-
## Create.
|
1059
|
-
sql = self.get_sql_create_database(**params)
|
1060
|
-
|
1061
|
-
## Confirm.
|
1062
|
-
if ask:
|
1063
|
-
self.input_confirm_build(sql)
|
1064
|
-
|
1065
|
-
## Execute.
|
1066
|
-
self.db.execute(sql)
|
1067
|
-
|
1068
|
-
## Report.
|
1069
|
-
text = f"Database '{database}' build completed."
|
1070
|
-
print(text)
|
1071
|
-
|
1072
|
-
# Table.
|
1073
|
-
for params in tables:
|
1074
|
-
path = params['path']
|
1075
|
-
database, table, _ = extract_path(path)
|
1076
|
-
|
1077
|
-
## Exist.
|
1078
|
-
if (
|
1079
|
-
skip
|
1080
|
-
and self.exist((database, table))
|
1081
|
-
):
|
1082
|
-
continue
|
1083
|
-
|
1084
|
-
## Create.
|
1085
|
-
sql = self.create_table(**params)
|
1086
|
-
|
1087
|
-
## Confirm.
|
1088
|
-
if ask:
|
1089
|
-
self.input_confirm_build(sql)
|
1090
|
-
|
1091
|
-
## Execute.
|
1092
|
-
self.db.execute(sql)
|
1093
|
-
|
1094
|
-
## Report.
|
1095
|
-
text = f"Table '{table}' of database '{database}' build completed."
|
1096
|
-
print(text)
|
1097
|
-
|
1098
|
-
# Table ORM.
|
1099
|
-
for model in tables_orm:
|
1100
|
-
table = model.table()
|
1101
|
-
|
1102
|
-
## Exist.
|
1103
|
-
if (
|
1104
|
-
skip
|
1105
|
-
and self.exist((self.db.database, table.name))
|
1106
|
-
):
|
1107
|
-
continue
|
1108
|
-
|
1109
|
-
## Confirm.
|
1110
|
-
if ask:
|
1111
|
-
text = self.get_orm_table_text(model)
|
1112
|
-
self.input_confirm_build(text)
|
1113
|
-
|
1114
|
-
## Execute.
|
1115
|
-
self.create_orm_table(model)
|
1116
|
-
|
1117
|
-
## Report.
|
1118
|
-
text = f"Table '{table.name}' of database '{self.db.database}' build completed."
|
1119
|
-
print(text)
|
1120
|
-
|
1121
|
-
# View.
|
1122
|
-
for params in views:
|
1123
|
-
path = params['path']
|
1124
|
-
database, view, _ = extract_path(path)
|
1125
|
-
|
1126
|
-
## Exist.
|
1127
|
-
if (
|
1128
|
-
skip
|
1129
|
-
and self.exist((database, view))
|
1130
|
-
):
|
1131
|
-
continue
|
1132
|
-
|
1133
|
-
## Create.
|
1134
|
-
sql = self.create_view(**params)
|
1135
|
-
|
1136
|
-
## Confirm.
|
1137
|
-
if ask:
|
1138
|
-
self.input_confirm_build(sql)
|
1139
|
-
|
1140
|
-
## Execute.
|
1141
|
-
self.db.execute(sql)
|
1142
|
-
|
1143
|
-
## Report.
|
1144
|
-
text = f"View '{view}' of database '{database}' build completed."
|
1145
|
-
print(text)
|
1146
|
-
|
1147
|
-
# View stats.
|
1148
|
-
for params in views_stats:
|
1149
|
-
path = params['path']
|
1150
|
-
database, view, _ = extract_path(path)
|
1151
|
-
|
1152
|
-
## Exist.
|
1153
|
-
if (
|
1154
|
-
skip
|
1155
|
-
and self.exist((database, view))
|
1156
|
-
):
|
1157
|
-
continue
|
1158
|
-
|
1159
|
-
## Create.
|
1160
|
-
sql = self.create_view_stats(**params)
|
1161
|
-
|
1162
|
-
## Confirm.
|
1163
|
-
if ask:
|
1164
|
-
self.input_confirm_build(sql)
|
1165
|
-
|
1166
|
-
## Execute.
|
1167
|
-
self.db.execute(sql)
|
1168
|
-
|
1169
|
-
## Report.
|
1170
|
-
text = f"View '{view}' of database '{database}' build completed."
|
1171
|
-
print(text)
|
1172
|
-
|
1173
|
-
|
1174
|
-
__call__ = build
|
1175
|
-
|
1176
|
-
|
1177
1043
|
class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
|
1178
1044
|
"""
|
1179
1045
|
Database build type.
|
1180
1046
|
"""
|
1181
1047
|
|
1182
1048
|
|
1183
|
-
def exist(
|
1184
|
-
self,
|
1185
|
-
path: str | tuple[str] | tuple[str, str] | tuple[str, str, str]
|
1186
|
-
) -> bool:
|
1187
|
-
"""
|
1188
|
-
Judge database or table or column exists.
|
1189
|
-
|
1190
|
-
Parameters
|
1191
|
-
----------
|
1192
|
-
path : Database name and table name and column name.
|
1193
|
-
- `str`: Automatic extract.
|
1194
|
-
- `tuple`: Format is `(database[, table, column]).`
|
1195
|
-
|
1196
|
-
Returns
|
1197
|
-
-------
|
1198
|
-
Judge result.
|
1199
|
-
"""
|
1200
|
-
|
1201
|
-
# Handle parameter.
|
1202
|
-
database, table, column = extract_path(path)
|
1203
|
-
if self._schema is None:
|
1204
|
-
self._schema = self.db.schema(False)
|
1205
|
-
|
1206
|
-
# Judge.
|
1207
|
-
judge = (
|
1208
|
-
database in self._schema
|
1209
|
-
and (
|
1210
|
-
table is None
|
1211
|
-
or (
|
1212
|
-
(database_info := self._schema.get(database)) is not None
|
1213
|
-
and (table_info := database_info.get(table)) is not None
|
1214
|
-
)
|
1215
|
-
)
|
1216
|
-
and (
|
1217
|
-
column is None
|
1218
|
-
or column in table_info
|
1219
|
-
)
|
1220
|
-
)
|
1221
|
-
|
1222
|
-
return judge
|
1223
|
-
|
1224
|
-
|
1225
1049
|
def create_orm_table(
|
1226
1050
|
self,
|
1227
1051
|
*models: Type[DatabaseORMModel] | DatabaseORMModel,
|
@@ -1283,9 +1107,9 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
|
|
1283
1107
|
# Handle parameter.
|
1284
1108
|
databases = databases or []
|
1285
1109
|
tables = tables or []
|
1286
|
-
tables_orm = tables_orm or []
|
1287
1110
|
views = views or []
|
1288
1111
|
views_stats = views_stats or []
|
1112
|
+
refresh_schema = False
|
1289
1113
|
|
1290
1114
|
# Database.
|
1291
1115
|
for params in databases:
|
@@ -1294,7 +1118,7 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
|
|
1294
1118
|
## Exist.
|
1295
1119
|
if (
|
1296
1120
|
skip
|
1297
|
-
and self.exist(database)
|
1121
|
+
and self.db.schema.exist(database)
|
1298
1122
|
):
|
1299
1123
|
continue
|
1300
1124
|
|
@@ -1317,15 +1141,17 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
|
|
1317
1141
|
|
1318
1142
|
## ORM.
|
1319
1143
|
if (
|
1320
|
-
|
1321
|
-
|
1144
|
+
is_instance(params)
|
1145
|
+
and isinstance(params, DatabaseORMModel)
|
1146
|
+
or issubclass(params, DatabaseORMModel)
|
1322
1147
|
):
|
1323
|
-
|
1148
|
+
database = self.db.database
|
1149
|
+
table = params._table().name
|
1324
1150
|
|
1325
1151
|
## Exist.
|
1326
1152
|
if (
|
1327
1153
|
skip
|
1328
|
-
and self.exist(
|
1154
|
+
and self.db.schema.exist(self.db.database, table)
|
1329
1155
|
):
|
1330
1156
|
continue
|
1331
1157
|
|
@@ -1339,13 +1165,16 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
|
|
1339
1165
|
|
1340
1166
|
## Parameter.
|
1341
1167
|
else:
|
1342
|
-
path = params['path']
|
1343
|
-
|
1168
|
+
path: str | tuple[str, str] = params['path']
|
1169
|
+
if type(path) == str:
|
1170
|
+
database, table = self.db.database, path
|
1171
|
+
else:
|
1172
|
+
database, table = path
|
1344
1173
|
|
1345
1174
|
### Exist.
|
1346
1175
|
if (
|
1347
1176
|
skip
|
1348
|
-
and self.exist(
|
1177
|
+
and self.db.schema.exist(database, table)
|
1349
1178
|
):
|
1350
1179
|
continue
|
1351
1180
|
|
@@ -1358,20 +1187,28 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
|
|
1358
1187
|
|
1359
1188
|
### Execute.
|
1360
1189
|
self.db.execute(sql)
|
1190
|
+
refresh_schema = True
|
1361
1191
|
|
1362
1192
|
## Report.
|
1363
1193
|
text = f"Table '{table}' of database '{database}' build completed."
|
1364
1194
|
print(text)
|
1365
1195
|
|
1196
|
+
# Refresh schema.
|
1197
|
+
if refresh_schema:
|
1198
|
+
self.db.schema()
|
1199
|
+
|
1366
1200
|
# View.
|
1367
1201
|
for params in views:
|
1368
1202
|
path = params['path']
|
1369
|
-
|
1203
|
+
if type(path) == str:
|
1204
|
+
database, table = self.db.database, path
|
1205
|
+
else:
|
1206
|
+
database, table = path
|
1370
1207
|
|
1371
1208
|
## Exist.
|
1372
1209
|
if (
|
1373
1210
|
skip
|
1374
|
-
and self.exist(
|
1211
|
+
and self.db.schema.exist(database, table)
|
1375
1212
|
):
|
1376
1213
|
continue
|
1377
1214
|
|
@@ -1386,18 +1223,21 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
|
|
1386
1223
|
self.db.execute(sql)
|
1387
1224
|
|
1388
1225
|
## Report.
|
1389
|
-
text = f"View '{
|
1226
|
+
text = f"View '{table}' of database '{database}' build completed."
|
1390
1227
|
print(text)
|
1391
1228
|
|
1392
1229
|
# View stats.
|
1393
1230
|
for params in views_stats:
|
1394
1231
|
path = params['path']
|
1395
|
-
|
1232
|
+
if type(path) == str:
|
1233
|
+
database, table = self.db.database, path
|
1234
|
+
else:
|
1235
|
+
database, table = path
|
1396
1236
|
|
1397
1237
|
## Exist.
|
1398
1238
|
if (
|
1399
1239
|
skip
|
1400
|
-
and self.exist(
|
1240
|
+
and self.db.schema.exist(database, table)
|
1401
1241
|
):
|
1402
1242
|
continue
|
1403
1243
|
|
@@ -1412,7 +1252,7 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
|
|
1412
1252
|
self.db.execute(sql)
|
1413
1253
|
|
1414
1254
|
## Report.
|
1415
|
-
text = f"View '{
|
1255
|
+
text = f"View '{table}' of database '{database}' build completed."
|
1416
1256
|
print(text)
|
1417
1257
|
|
1418
1258
|
|
@@ -1425,48 +1265,6 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1425
1265
|
"""
|
1426
1266
|
|
1427
1267
|
|
1428
|
-
async def exist(
|
1429
|
-
self,
|
1430
|
-
path: str | tuple[str] | tuple[str, str] | tuple[str, str, str]
|
1431
|
-
) -> bool:
|
1432
|
-
"""
|
1433
|
-
Asynchronous judge database or table or column exists.
|
1434
|
-
|
1435
|
-
Parameters
|
1436
|
-
----------
|
1437
|
-
path : Database name and table name and column name.
|
1438
|
-
- `str`: Automatic extract.
|
1439
|
-
- `tuple`: Format is `(database[, table, column]).`
|
1440
|
-
|
1441
|
-
Returns
|
1442
|
-
-------
|
1443
|
-
Judge result.
|
1444
|
-
"""
|
1445
|
-
|
1446
|
-
# Handle parameter.
|
1447
|
-
database, table, column = extract_path(path)
|
1448
|
-
if self._schema is None:
|
1449
|
-
self._schema = await self.db.schema(False)
|
1450
|
-
|
1451
|
-
# Judge.
|
1452
|
-
judge = (
|
1453
|
-
database in self._schema
|
1454
|
-
and (
|
1455
|
-
table is None
|
1456
|
-
or (
|
1457
|
-
(database_info := self._schema.get(database)) is not None
|
1458
|
-
and (table_info := database_info.get(table)) is not None
|
1459
|
-
)
|
1460
|
-
)
|
1461
|
-
and (
|
1462
|
-
column is None
|
1463
|
-
or column in table_info
|
1464
|
-
)
|
1465
|
-
)
|
1466
|
-
|
1467
|
-
return judge
|
1468
|
-
|
1469
|
-
|
1470
1268
|
async def create_orm_table(
|
1471
1269
|
self,
|
1472
1270
|
*models: Type[DatabaseORMModel] | DatabaseORMModel,
|
@@ -1520,7 +1318,6 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1520
1318
|
----------
|
1521
1319
|
databases : Database build parameters, equivalent to the parameters of method `self.create_database`.
|
1522
1320
|
tables : Tables build parameters, equivalent to the parameters of method `self.create_table`.
|
1523
|
-
tables_orm : Tables buile model, equivalent to the parameters of method `self.create_table_orm`.
|
1524
1321
|
views : Views build parameters, equivalent to the parameters of method `self.create_view`.
|
1525
1322
|
views_stats : Views stats build parameters, equivalent to the parameters of method `self.create_view_stats`.
|
1526
1323
|
ask : Whether ask confirm execute.
|
@@ -1533,6 +1330,7 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1533
1330
|
tables_orm = tables_orm or []
|
1534
1331
|
views = views or []
|
1535
1332
|
views_stats = views_stats or []
|
1333
|
+
refresh_schema = False
|
1536
1334
|
|
1537
1335
|
# Database.
|
1538
1336
|
for params in databases:
|
@@ -1541,7 +1339,7 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1541
1339
|
## Exist.
|
1542
1340
|
if (
|
1543
1341
|
skip
|
1544
|
-
and await self.exist(database)
|
1342
|
+
and await self.db.schema.exist(database)
|
1545
1343
|
):
|
1546
1344
|
continue
|
1547
1345
|
|
@@ -1561,18 +1359,20 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1561
1359
|
|
1562
1360
|
# Table.
|
1563
1361
|
for params in tables:
|
1564
|
-
if is_instance(params):
|
1565
|
-
params_type = type(params)
|
1566
1362
|
|
1567
1363
|
## ORM.
|
1568
|
-
if
|
1364
|
+
if (
|
1365
|
+
is_instance(params)
|
1366
|
+
and isinstance(params, DatabaseORMModel)
|
1367
|
+
or issubclass(params, DatabaseORMModel)
|
1368
|
+
):
|
1569
1369
|
database = self.db.database
|
1570
|
-
table = params.
|
1370
|
+
table = params._table().name
|
1571
1371
|
|
1572
1372
|
## Exist.
|
1573
1373
|
if (
|
1574
1374
|
skip
|
1575
|
-
and await self.exist(
|
1375
|
+
and await self.db.schema.exist(self.db.database, table)
|
1576
1376
|
):
|
1577
1377
|
continue
|
1578
1378
|
|
@@ -1586,13 +1386,16 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1586
1386
|
|
1587
1387
|
## Parameter.
|
1588
1388
|
else:
|
1589
|
-
path = params['path']
|
1590
|
-
|
1389
|
+
path: str | tuple[str, str] = params['path']
|
1390
|
+
if type(path) == str:
|
1391
|
+
database, table = self.db.database, path
|
1392
|
+
else:
|
1393
|
+
database, table = path
|
1591
1394
|
|
1592
1395
|
### Exist.
|
1593
1396
|
if (
|
1594
1397
|
skip
|
1595
|
-
and await self.exist(
|
1398
|
+
and await self.db.schema.exist(database, table)
|
1596
1399
|
):
|
1597
1400
|
continue
|
1598
1401
|
|
@@ -1605,20 +1408,28 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1605
1408
|
|
1606
1409
|
### Execute.
|
1607
1410
|
await self.db.execute(sql)
|
1411
|
+
refresh_schema = True
|
1608
1412
|
|
1609
1413
|
## Report.
|
1610
1414
|
text = f"Table '{table}' of database '{database}' build completed."
|
1611
1415
|
print(text)
|
1612
1416
|
|
1417
|
+
# Refresh schema.
|
1418
|
+
if refresh_schema:
|
1419
|
+
self.db.schema()
|
1420
|
+
|
1613
1421
|
# View.
|
1614
1422
|
for params in views:
|
1615
1423
|
path = params['path']
|
1616
|
-
|
1424
|
+
if type(path) == str:
|
1425
|
+
database, table = self.db.database, path
|
1426
|
+
else:
|
1427
|
+
database, table = path
|
1617
1428
|
|
1618
1429
|
## Exist.
|
1619
1430
|
if (
|
1620
1431
|
skip
|
1621
|
-
and await self.exist(
|
1432
|
+
and await self.db.schema.exist(database, table)
|
1622
1433
|
):
|
1623
1434
|
continue
|
1624
1435
|
|
@@ -1633,18 +1444,21 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1633
1444
|
await self.db.execute(sql)
|
1634
1445
|
|
1635
1446
|
## Report.
|
1636
|
-
text = f"View '{
|
1447
|
+
text = f"View '{table}' of database '{database}' build completed."
|
1637
1448
|
print(text)
|
1638
1449
|
|
1639
1450
|
# View stats.
|
1640
1451
|
for params in views_stats:
|
1641
1452
|
path = params['path']
|
1642
|
-
|
1453
|
+
if type(path) == str:
|
1454
|
+
database, table = self.db.database, path
|
1455
|
+
else:
|
1456
|
+
database, table = path
|
1643
1457
|
|
1644
1458
|
## Exist.
|
1645
1459
|
if (
|
1646
1460
|
skip
|
1647
|
-
and await self.exist(
|
1461
|
+
and await self.db.schema.exist(database, table)
|
1648
1462
|
):
|
1649
1463
|
continue
|
1650
1464
|
|
@@ -1659,7 +1473,7 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1659
1473
|
await self.db.execute(sql)
|
1660
1474
|
|
1661
1475
|
## Report.
|
1662
|
-
text = f"View '{
|
1476
|
+
text = f"View '{table}' of database '{database}' build completed."
|
1663
1477
|
print(text)
|
1664
1478
|
|
1665
1479
|
|