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