reydb 1.2.2__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/rconfig.py CHANGED
@@ -9,7 +9,7 @@
9
9
  """
10
10
 
11
11
 
12
- from typing import TypedDict, TypeVar, Generic
12
+ from typing import Any, TypedDict, TypeVar, Generic
13
13
  from datetime import (
14
14
  datetime as Datetime,
15
15
  date as Date,
@@ -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.
@@ -66,24 +81,20 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
66
81
  self.db = db
67
82
 
68
83
 
69
- def handle_build_db(self) -> None:
84
+ def handle_build_db(self) -> tuple[list[type[TableConfig]], list[dict[str, Any]]] :
70
85
  """
71
86
  Handle method of check and build database tables, by `self.db_names`.
87
+
88
+ Returns
89
+ -------
90
+ Build database parameter.
72
91
  """
73
92
 
74
93
  # Set parameter.
94
+ TableConfig._set_name(self.db_names['config'])
75
95
 
76
96
  ## Table.
77
- class Config(rorm.Model, table=True):
78
- __name__ = self.db_names['config']
79
- __comment__ = 'Config data table.'
80
- create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Config create time.')
81
- update_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', index_n=True, comment='Config update time.')
82
- key: str = rorm.Field(field_type=rorm.types.VARCHAR(50), key=True, comment='Config key.')
83
- value: str = rorm.Field(field_type=rorm.types.TEXT, not_null=True, comment='Config value.')
84
- type: str = rorm.Field(field_type=rorm.types.VARCHAR(50), not_null=True, comment='Config value type.')
85
- note: str = rorm.Field(field_type=rorm.types.VARCHAR(500), comment='Config note.')
86
- tables = [Config]
97
+ tables = [TableConfig]
87
98
 
88
99
  ## View stats.
89
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.
@@ -60,24 +75,20 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
60
75
  self.db = db
61
76
 
62
77
 
63
- def handle_build_db(self) -> None:
78
+ def handle_build_db(self) -> tuple[list[type[TableError]], list[dict[str, Any]]]:
64
79
  """
65
80
  Handle method of check and build database tables, by `self.db_names`.
81
+
82
+ Returns
83
+ -------
84
+ Build database parameter.
66
85
  """
67
86
 
68
87
  # Set parameter.
88
+ TableError._set_name(self.db_names['error'])
69
89
 
70
90
  ## Table.
71
- class error(rorm.Model, table=True):
72
- __name__ = self.db_names['error']
73
- __comment__ = 'Error log table.'
74
- create_time: rorm.Datetime = rorm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Record create time.')
75
- id: int = rorm.Field(field_type=rorm.types_mysql.INTEGER(unsigned=True), key_auto=True, comment='ID.')
76
- type: str = rorm.Field(field_type=rorm.types.VARCHAR(50), not_null=True, index_n=True, comment='Error type.')
77
- data: str = rorm.Field(field_type=rorm.types.JSON, comment='Error data.')
78
- stack: str = rorm.Field(field_type=rorm.types.JSON, comment='Error code traceback stack.')
79
- note: str = rorm.Field(field_type=rorm.types.VARCHAR(500), comment='Error note.')
80
- tables = [error]
91
+ tables = [TableError]
81
92
 
82
93
  ## View stats.
83
94
  views_stats = [
reydb/rinfo.py CHANGED
@@ -255,7 +255,7 @@ class DatabaseInformationSchema(DatabaseInformationSchemaSuper['rdb.Database']):
255
255
  self,
256
256
  database: str,
257
257
  *,
258
- refresh: bool = True
258
+ cache: bool = True
259
259
  ) -> bool: ...
260
260
 
261
261
  @overload
@@ -264,7 +264,7 @@ class DatabaseInformationSchema(DatabaseInformationSchemaSuper['rdb.Database']):
264
264
  database: str,
265
265
  *,
266
266
  table: str,
267
- refresh: bool = True
267
+ cache: bool = True
268
268
  ) -> bool: ...
269
269
 
270
270
  @overload
@@ -273,7 +273,7 @@ class DatabaseInformationSchema(DatabaseInformationSchemaSuper['rdb.Database']):
273
273
  database: str,
274
274
  table: str,
275
275
  column: str,
276
- refresh: bool = True
276
+ cache: bool = True
277
277
  ) -> bool: ...
278
278
 
279
279
  def exist(
@@ -281,7 +281,7 @@ class DatabaseInformationSchema(DatabaseInformationSchemaSuper['rdb.Database']):
281
281
  database: str,
282
282
  table: str | None = None,
283
283
  column: str | None = None,
284
- refresh: bool = True
284
+ cache: bool = True
285
285
  ) -> bool:
286
286
  """
287
287
  Judge database or table or column whether it exists.
@@ -291,7 +291,7 @@ class DatabaseInformationSchema(DatabaseInformationSchemaSuper['rdb.Database']):
291
291
  database : Database name.
292
292
  table : Table name.
293
293
  column : Column name.
294
- refresh : Whether refresh cache data. Cache can improve efficiency.
294
+ cache : Whether use cache data, can improve efficiency.
295
295
 
296
296
  Returns
297
297
  -------
@@ -300,12 +300,12 @@ class DatabaseInformationSchema(DatabaseInformationSchemaSuper['rdb.Database']):
300
300
 
301
301
  # Set parameter.
302
302
  if (
303
- refresh
304
- or self.db._schema is None
303
+ cache
304
+ and self.db._schema is not None
305
305
  ):
306
- schema = self.schema()
307
- else:
308
306
  schema = self.db._schema
307
+ else:
308
+ schema = self.schema()
309
309
 
310
310
  # Judge.
311
311
  result = self.handle_exist(schema, database, table, column)
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
 
@@ -327,6 +327,28 @@ class DatabaseORMModel(DatabaseORMBase, SQLModel, metaclass=model_metaclass):
327
327
  return table
328
328
 
329
329
 
330
+ @classmethod
331
+ def _set_name(cls_or_self, name: str) -> None:
332
+ """
333
+ Set database table name.
334
+ """
335
+
336
+ # Get.
337
+ table = cls_or_self._get_table()
338
+ table.name = name
339
+
340
+
341
+ @classmethod
342
+ def _set_comment(cls_or_self, comment: str) -> None:
343
+ """
344
+ Set database table comment.
345
+ """
346
+
347
+ # Get.
348
+ table = cls_or_self._get_table()
349
+ table.comment = comment
350
+
351
+
330
352
  @property
331
353
  def _m(self):
332
354
  """
@@ -826,7 +848,7 @@ class DatabaseORMSession(
826
848
 
827
849
  # Handle parameter.
828
850
  tables = [
829
- model._table()
851
+ model._get_table()
830
852
  for model in models
831
853
  ]
832
854
 
@@ -855,7 +877,7 @@ class DatabaseORMSession(
855
877
 
856
878
  # Handle parameter.
857
879
  tables = [
858
- model._table()
880
+ model._get_table()
859
881
  for model in models
860
882
  ]
861
883
 
@@ -1192,7 +1214,7 @@ class DatabaseORMSessionAsync(
1192
1214
 
1193
1215
  # Handle parameter.
1194
1216
  tables = [
1195
- model._table()
1217
+ model._get_table()
1196
1218
  for model in models
1197
1219
  ]
1198
1220
 
@@ -1222,7 +1244,7 @@ class DatabaseORMSessionAsync(
1222
1244
 
1223
1245
  # Handle parameter.
1224
1246
  tables = [
1225
- model._table()
1247
+ model._get_table()
1226
1248
  for model in models
1227
1249
  ]
1228
1250
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reydb
3
- Version: 1.2.2
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>
@@ -0,0 +1,15 @@
1
+ reydb/__init__.py,sha256=4mnlkfJfkBfxBpCotVUJ86f4AnT8plqlFbGiH3vZ4PM,550
2
+ reydb/rall.py,sha256=IxSPGh77xz7ndDC7J8kZ_66Gq_xTAztGtnELUku1Ouw,364
3
+ reydb/rbase.py,sha256=vx37yV6LlWP89nWAfYyOf0Xm3N_e9eB8z5Mxe-aTEo4,8248
4
+ reydb/rbuild.py,sha256=imakdlqQXzQlbAukti3_REVU_h7IRRE3fwUk91LaIIM,80430
5
+ reydb/rconfig.py,sha256=Z8h23-w_FTiDMu9-1Bdu6xpRqJt1j8EESNq0MsJRies,19157
6
+ reydb/rconn.py,sha256=guRaR8N6RuzZzujwaeq7HhKWTizF9SrUBqEAFjfjpoo,6909
7
+ reydb/rdb.py,sha256=syyqZbEu92NbCj9O6_T6iAv7E46CyfQOC4T8qtPfHNs,14364
8
+ reydb/rerror.py,sha256=cB3xAq1Zy97Mvq43ql9o-WtoSvgluXKqaQwHrHETrY8,14884
9
+ reydb/rexec.py,sha256=djHx311c6mr1IjzNLqnGe-4yr3qNmYGUy4pHQA3WElQ,53042
10
+ reydb/rinfo.py,sha256=LjrqTA7JJbWJsjXwV-zKpbE1htv-whg6239hoQj4yIU,18151
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,,
@@ -1,15 +0,0 @@
1
- reydb/__init__.py,sha256=4mnlkfJfkBfxBpCotVUJ86f4AnT8plqlFbGiH3vZ4PM,550
2
- reydb/rall.py,sha256=IxSPGh77xz7ndDC7J8kZ_66Gq_xTAztGtnELUku1Ouw,364
3
- reydb/rbase.py,sha256=vx37yV6LlWP89nWAfYyOf0Xm3N_e9eB8z5Mxe-aTEo4,8248
4
- reydb/rbuild.py,sha256=rmwfkjxjhavcbyn-V0ZTqwKNq3wKmgvHng8p5I0dghQ,40281
5
- reydb/rconfig.py,sha256=5ZfFQwgt6JI5k1luv7PIj3H9Izuc6KNMOCFCJGBb1rQ,18998
6
- reydb/rconn.py,sha256=guRaR8N6RuzZzujwaeq7HhKWTizF9SrUBqEAFjfjpoo,6909
7
- reydb/rdb.py,sha256=syyqZbEu92NbCj9O6_T6iAv7E46CyfQOC4T8qtPfHNs,14364
8
- reydb/rerror.py,sha256=renVDvi5e6-AC-y2KPksARPRX978WFh0Hqa9yfl9j1A,14735
9
- reydb/rexec.py,sha256=djHx311c6mr1IjzNLqnGe-4yr3qNmYGUy4pHQA3WElQ,53042
10
- reydb/rinfo.py,sha256=9qpVFqFwMol5_n9gE3zYLv9Fn5r2EuVD5ibgQkSXYyw,18168
11
- reydb/rorm.py,sha256=X99AKlpMQk3et9_3x1ddpKn1BxZRULLG8x_opYbWVX8,40934
12
- reydb-1.2.2.dist-info/METADATA,sha256=J_Jq9TRbL2LRW154knFoOtwv8wWVQQqhfup0YTfEwRM,1621
13
- reydb-1.2.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- reydb-1.2.2.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
15
- reydb-1.2.2.dist-info/RECORD,,
File without changes