reydb 1.2.3__py3-none-any.whl → 1.2.4__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
@@ -983,7 +983,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
983
983
  """
984
984
 
985
985
  # Get.
986
- table = model._table()
986
+ table = model._get_table()
987
987
  text = f'TABLE `{self.db.database}`.`{table}`'
988
988
  if 'mysql_charset' in table.kwargs:
989
989
  text += f" | CHARSET '{table.kwargs['mysql_charset']}'"
@@ -1146,7 +1146,7 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
1146
1146
  or issubclass(params, DatabaseORMModel)
1147
1147
  ):
1148
1148
  database = self.db.database
1149
- table = params._table().name
1149
+ table = params._get_table().name
1150
1150
 
1151
1151
  ## Exist.
1152
1152
  if (
@@ -1367,7 +1367,7 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
1367
1367
  or issubclass(params, DatabaseORMModel)
1368
1368
  ):
1369
1369
  database = self.db.database
1370
- table = params._table().name
1370
+ table = params._get_table().name
1371
1371
 
1372
1372
  ## Exist.
1373
1373
  if (
@@ -2463,7 +2463,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
2463
2463
  """
2464
2464
 
2465
2465
  # Get.
2466
- table = model._table()
2466
+ table = model._get_table()
2467
2467
  text = f'TABLE `{self.db.database}`.`{table}`'
2468
2468
  if 'mysql_charset' in table.kwargs:
2469
2469
  text += f" | CHARSET '{table.kwargs['mysql_charset']}'"
@@ -2619,32 +2619,8 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
2619
2619
  # Table.
2620
2620
  for params in tables:
2621
2621
 
2622
- ## ORM.
2623
- if (
2624
- is_instance(params)
2625
- and isinstance(params, DatabaseORMModel)
2626
- or issubclass(params, DatabaseORMModel)
2627
- ):
2628
- database = self.db.database
2629
- table = params._table().name
2630
-
2631
- ## Exist.
2632
- if (
2633
- skip
2634
- and self.db.schema.exist(self.db.database, table)
2635
- ):
2636
- continue
2637
-
2638
- ## Confirm.
2639
- if ask:
2640
- text = self.get_orm_table_text(params)
2641
- self.input_confirm_build(text)
2642
-
2643
- ## Execute.
2644
- self.create_orm_table(params)
2645
-
2646
2622
  ## Parameter.
2647
- else:
2623
+ if type(params) == dict:
2648
2624
  path: str | tuple[str, str] = params['path']
2649
2625
  if type(path) == str:
2650
2626
  database, table = self.db.database, path
@@ -2668,6 +2644,26 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
2668
2644
  ### Execute.
2669
2645
  self.db.execute(sql)
2670
2646
 
2647
+ ## ORM.
2648
+ else:
2649
+ database = self.db.database
2650
+ table = params._get_table().name
2651
+
2652
+ ## Exist.
2653
+ if (
2654
+ skip
2655
+ and self.db.schema.exist(self.db.database, table)
2656
+ ):
2657
+ continue
2658
+
2659
+ ## Confirm.
2660
+ if ask:
2661
+ text = self.get_orm_table_text(params)
2662
+ self.input_confirm_build(text)
2663
+
2664
+ ## Execute.
2665
+ self.create_orm_table(params)
2666
+
2671
2667
  ## Report.
2672
2668
  text = f"Table '{table}' of database '{database}' build completed."
2673
2669
  print(text)
@@ -2847,7 +2843,7 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
2847
2843
  or issubclass(params, DatabaseORMModel)
2848
2844
  ):
2849
2845
  database = self.db.database
2850
- table = params._table().name
2846
+ table = params._get_table().name
2851
2847
 
2852
2848
  ## Exist.
2853
2849
  if (
reydb/rconfig.py CHANGED
@@ -24,6 +24,7 @@ from .rbase import DatabaseBase
24
24
 
25
25
 
26
26
  __all__ = (
27
+ 'TableConfig',
27
28
  'DatabaseConfigSuper',
28
29
  'DatabaseConfig',
29
30
  'DatabaseConfigAsync'
@@ -37,6 +38,20 @@ ConfigValueT = TypeVar('T', bound=ConfigValue) # Any.
37
38
  DatabaseT = TypeVar('DatabaseT', 'rdb.Database', 'rdb.DatabaseAsync')
38
39
 
39
40
 
41
+ class TableConfig(rorm.Model, table=True):
42
+ """
43
+ Database `config` table model.
44
+ """
45
+
46
+ __comment__ = 'Config data table.'
47
+ create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Config create time.')
48
+ update_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', index_n=True, comment='Config update time.')
49
+ key: str = rorm.Field(field_type=rorm.types.VARCHAR(50), key=True, comment='Config key.')
50
+ value: str = rorm.Field(field_type=rorm.types.TEXT, not_null=True, comment='Config value.')
51
+ type: str = rorm.Field(field_type=rorm.types.VARCHAR(50), not_null=True, comment='Config value type.')
52
+ note: str = rorm.Field(field_type=rorm.types.VARCHAR(500), comment='Config note.')
53
+
54
+
40
55
  class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
41
56
  """
42
57
  Database config super type.
@@ -45,7 +60,6 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
45
60
  Attributes
46
61
  ----------
47
62
  db_names : Database table name mapping dictionary.
48
- Config : Database `config` table model.
49
63
  """
50
64
 
51
65
  db_names = {
@@ -54,16 +68,6 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
54
68
  }
55
69
 
56
70
 
57
- class Config(rorm.Model, table=True):
58
- __comment__ = 'Config data table.'
59
- create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Config create time.')
60
- update_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', index_n=True, comment='Config update time.')
61
- key: str = rorm.Field(field_type=rorm.types.VARCHAR(50), key=True, comment='Config key.')
62
- value: str = rorm.Field(field_type=rorm.types.TEXT, not_null=True, comment='Config value.')
63
- type: str = rorm.Field(field_type=rorm.types.VARCHAR(50), not_null=True, comment='Config value type.')
64
- note: str = rorm.Field(field_type=rorm.types.VARCHAR(500), comment='Config note.')
65
-
66
-
67
71
  def __init__(self, db: DatabaseT) -> None:
68
72
  """
69
73
  Build instance attributes.
@@ -77,7 +81,7 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
77
81
  self.db = db
78
82
 
79
83
 
80
- def handle_build_db(self) -> tuple[list[type[Config]], list[dict[str, Any]]] :
84
+ def handle_build_db(self) -> tuple[list[type[TableConfig]], list[dict[str, Any]]] :
81
85
  """
82
86
  Handle method of check and build database tables, by `self.db_names`.
83
87
 
@@ -87,10 +91,10 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
87
91
  """
88
92
 
89
93
  # Set parameter.
90
- self.Config._name(self.db_names['config'])
94
+ TableConfig._set_name(self.db_names['config'])
91
95
 
92
96
  ## Table.
93
- tables = [self.Config]
97
+ tables = [TableConfig]
94
98
 
95
99
  ## View stats.
96
100
  views_stats = [
reydb/rerror.py CHANGED
@@ -22,6 +22,7 @@ from .rbase import DatabaseBase
22
22
 
23
23
 
24
24
  __all__ = (
25
+ 'TableError',
25
26
  'DatabaseErrorSuper',
26
27
  'DatabaseError',
27
28
  'DatabaseErrorAsync'
@@ -31,6 +32,20 @@ __all__ = (
31
32
  DatabaseT = TypeVar('DatabaseT', 'rdb.Database', 'rdb.DatabaseAsync')
32
33
 
33
34
 
35
+ class TableError(rorm.Model, table=True):
36
+ """
37
+ Database `error` table model.
38
+ """
39
+
40
+ __comment__ = 'Error log table.'
41
+ create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
42
+ id: int = rorm.Field(field_type=rorm.types_mysql.INTEGER(unsigned=True), key_auto=True, comment='ID.')
43
+ type: str = rorm.Field(field_type=rorm.types.VARCHAR(50), not_null=True, index_n=True, comment='Error type.')
44
+ data: str = rorm.Field(field_type=rorm.types.JSON, comment='Error data.')
45
+ stack: str = rorm.Field(field_type=rorm.types.JSON, comment='Error code traceback stack.')
46
+ note: str = rorm.Field(field_type=rorm.types.VARCHAR(500), comment='Error note.')
47
+
48
+
34
49
  class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
35
50
  """
36
51
  Database error super type.
@@ -39,7 +54,6 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
39
54
  Attributes
40
55
  ----------
41
56
  db_names : Database table name mapping dictionary.
42
- Error : Database `error` table model.
43
57
  """
44
58
 
45
59
  db_names = {
@@ -48,16 +62,6 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
48
62
  }
49
63
 
50
64
 
51
- class Error(rorm.Model, table=True):
52
- __comment__ = 'Error log table.'
53
- create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
54
- id: int = rorm.Field(field_type=rorm.types_mysql.INTEGER(unsigned=True), key_auto=True, comment='ID.')
55
- type: str = rorm.Field(field_type=rorm.types.VARCHAR(50), not_null=True, index_n=True, comment='Error type.')
56
- data: str = rorm.Field(field_type=rorm.types.JSON, comment='Error data.')
57
- stack: str = rorm.Field(field_type=rorm.types.JSON, comment='Error code traceback stack.')
58
- note: str = rorm.Field(field_type=rorm.types.VARCHAR(500), comment='Error note.')
59
-
60
-
61
65
  def __init__(self, db: DatabaseT) -> None:
62
66
  """
63
67
  Build instance attributes.
@@ -71,7 +75,7 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
71
75
  self.db = db
72
76
 
73
77
 
74
- def handle_build_db(self) -> tuple[list[type[Error]], list[dict[str, Any]]]:
78
+ def handle_build_db(self) -> tuple[list[type[TableError]], list[dict[str, Any]]]:
75
79
  """
76
80
  Handle method of check and build database tables, by `self.db_names`.
77
81
 
@@ -81,10 +85,10 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
81
85
  """
82
86
 
83
87
  # Set parameter.
84
- self.Error._name(self.db_names['error'])
88
+ TableError._set_name(self.db_names['error'])
85
89
 
86
90
  ## Table.
87
- tables = [self.Error]
91
+ tables = [TableError]
88
92
 
89
93
  ## View stats.
90
94
  views_stats = [
reydb/rorm.py CHANGED
@@ -312,7 +312,7 @@ class DatabaseORMModel(DatabaseORMBase, SQLModel, metaclass=model_metaclass):
312
312
 
313
313
 
314
314
  @classmethod
315
- def _table(cls_or_self) -> Table:
315
+ def _get_table(cls_or_self) -> Table:
316
316
  """
317
317
  Return mapping database table instance.
318
318
 
@@ -328,24 +328,24 @@ class DatabaseORMModel(DatabaseORMBase, SQLModel, metaclass=model_metaclass):
328
328
 
329
329
 
330
330
  @classmethod
331
- def _name(cls_or_self, name: str) -> None:
331
+ def _set_name(cls_or_self, name: str) -> None:
332
332
  """
333
333
  Set database table name.
334
334
  """
335
335
 
336
336
  # Get.
337
- table = cls_or_self._table()
337
+ table = cls_or_self._get_table()
338
338
  table.name = name
339
339
 
340
340
 
341
341
  @classmethod
342
- def _comment(cls_or_self, comment: str) -> None:
342
+ def _set_comment(cls_or_self, comment: str) -> None:
343
343
  """
344
344
  Set database table comment.
345
345
  """
346
346
 
347
347
  # Get.
348
- table = cls_or_self._table()
348
+ table = cls_or_self._get_table()
349
349
  table.comment = comment
350
350
 
351
351
 
@@ -848,7 +848,7 @@ class DatabaseORMSession(
848
848
 
849
849
  # Handle parameter.
850
850
  tables = [
851
- model._table()
851
+ model._get_table()
852
852
  for model in models
853
853
  ]
854
854
 
@@ -877,7 +877,7 @@ class DatabaseORMSession(
877
877
 
878
878
  # Handle parameter.
879
879
  tables = [
880
- model._table()
880
+ model._get_table()
881
881
  for model in models
882
882
  ]
883
883
 
@@ -1214,7 +1214,7 @@ class DatabaseORMSessionAsync(
1214
1214
 
1215
1215
  # Handle parameter.
1216
1216
  tables = [
1217
- model._table()
1217
+ model._get_table()
1218
1218
  for model in models
1219
1219
  ]
1220
1220
 
@@ -1244,7 +1244,7 @@ class DatabaseORMSessionAsync(
1244
1244
 
1245
1245
  # Handle parameter.
1246
1246
  tables = [
1247
- model._table()
1247
+ model._get_table()
1248
1248
  for model in models
1249
1249
  ]
1250
1250
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reydb
3
- Version: 1.2.3
3
+ Version: 1.2.4
4
4
  Summary: Database method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reydb/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -1,15 +1,15 @@
1
1
  reydb/__init__.py,sha256=4mnlkfJfkBfxBpCotVUJ86f4AnT8plqlFbGiH3vZ4PM,550
2
2
  reydb/rall.py,sha256=IxSPGh77xz7ndDC7J8kZ_66Gq_xTAztGtnELUku1Ouw,364
3
3
  reydb/rbase.py,sha256=vx37yV6LlWP89nWAfYyOf0Xm3N_e9eB8z5Mxe-aTEo4,8248
4
- reydb/rbuild.py,sha256=8frMtmY8gKc-uYYaJPso9sm8IS3_CyTHrL_F0Wv5RI0,80554
5
- reydb/rconfig.py,sha256=g428a0npVNgB3PMJiEpVRPwyvWm63G9KLcEru4-vPTU,19144
4
+ reydb/rbuild.py,sha256=imakdlqQXzQlbAukti3_REVU_h7IRRE3fwUk91LaIIM,80430
5
+ reydb/rconfig.py,sha256=Z8h23-w_FTiDMu9-1Bdu6xpRqJt1j8EESNq0MsJRies,19157
6
6
  reydb/rconn.py,sha256=guRaR8N6RuzZzujwaeq7HhKWTizF9SrUBqEAFjfjpoo,6909
7
7
  reydb/rdb.py,sha256=syyqZbEu92NbCj9O6_T6iAv7E46CyfQOC4T8qtPfHNs,14364
8
- reydb/rerror.py,sha256=LcXyinipQw-saQxGwbkXU4BTOjb29RMX9hnAFidJN3Q,14871
8
+ reydb/rerror.py,sha256=cB3xAq1Zy97Mvq43ql9o-WtoSvgluXKqaQwHrHETrY8,14884
9
9
  reydb/rexec.py,sha256=djHx311c6mr1IjzNLqnGe-4yr3qNmYGUy4pHQA3WElQ,53042
10
10
  reydb/rinfo.py,sha256=LjrqTA7JJbWJsjXwV-zKpbE1htv-whg6239hoQj4yIU,18151
11
- reydb/rorm.py,sha256=AVV50cC5Vm8pT6gIeBUAelXd3OpdQSldPsZltL8ceOg,41375
12
- reydb-1.2.3.dist-info/METADATA,sha256=IULuCfrYhhcnoLjLulnsgEy4R_Dzc9s5P9IrhRCVsAM,1621
13
- reydb-1.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- reydb-1.2.3.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
15
- reydb-1.2.3.dist-info/RECORD,,
11
+ reydb/rorm.py,sha256=2C2g0zd188pf9VoGH52TiVZkjd9y9YAZTqU4XJUSlhA,41411
12
+ reydb-1.2.4.dist-info/METADATA,sha256=9f-mOq7OwHoRXtkOLKzkNskD7dt1s59Dv5foLX6N_Nw,1621
13
+ reydb-1.2.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ reydb-1.2.4.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
15
+ reydb-1.2.4.dist-info/RECORD,,
File without changes