reydb 1.2.0__py3-none-any.whl → 1.2.2__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 +1 -1
- reydb/rall.py +1 -1
- reydb/rbase.py +4 -4
- reydb/rbuild.py +13 -13
- reydb/rconfig.py +24 -20
- reydb/rdb.py +61 -41
- reydb/rerror.py +27 -23
- reydb/rexec.py +124 -123
- reydb/{rparam.py → rinfo.py} +54 -47
- reydb/rorm.py +40 -24
- {reydb-1.2.0.dist-info → reydb-1.2.2.dist-info}/METADATA +1 -1
- reydb-1.2.2.dist-info/RECORD +15 -0
- reydb-1.2.0.dist-info/RECORD +0 -15
- {reydb-1.2.0.dist-info → reydb-1.2.2.dist-info}/WHEEL +0 -0
- {reydb-1.2.0.dist-info → reydb-1.2.2.dist-info}/licenses/LICENSE +0 -0
reydb/__init__.py
CHANGED
reydb/rall.py
CHANGED
reydb/rbase.py
CHANGED
@@ -75,7 +75,7 @@ def handle_sql(sql: str | TextClause) -> TextClause:
|
|
75
75
|
TextClause instance.
|
76
76
|
"""
|
77
77
|
|
78
|
-
#
|
78
|
+
# Set parameter.
|
79
79
|
if type(sql) == TextClause:
|
80
80
|
sql = sql.text
|
81
81
|
|
@@ -102,7 +102,7 @@ def handle_data(data: list[dict], sql: str | TextClause) -> list[dict]:
|
|
102
102
|
Filled data.
|
103
103
|
"""
|
104
104
|
|
105
|
-
#
|
105
|
+
# Set parameter.
|
106
106
|
if type(sql) == TextClause:
|
107
107
|
sql = sql.text
|
108
108
|
|
@@ -298,7 +298,7 @@ def get_syntax(self, sql: str | TextClause) -> list[str]:
|
|
298
298
|
SQL syntax type for each segment.
|
299
299
|
"""
|
300
300
|
|
301
|
-
#
|
301
|
+
# Set parameter.
|
302
302
|
if type(sql) == TextClause:
|
303
303
|
sql = sql.text
|
304
304
|
|
@@ -325,7 +325,7 @@ def is_multi_sql(self, sql: str | TextClause) -> bool:
|
|
325
325
|
Judgment result.
|
326
326
|
"""
|
327
327
|
|
328
|
-
#
|
328
|
+
# Set parameter.
|
329
329
|
if type(sql) == TextClause:
|
330
330
|
sql = sql.text
|
331
331
|
|
reydb/rbuild.py
CHANGED
@@ -121,7 +121,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
121
121
|
Field set SQL.
|
122
122
|
"""
|
123
123
|
|
124
|
-
#
|
124
|
+
# Set parameter.
|
125
125
|
|
126
126
|
## Constraint.
|
127
127
|
constraint = ' ' + constraint
|
@@ -175,7 +175,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
175
175
|
Index set SQL.
|
176
176
|
"""
|
177
177
|
|
178
|
-
#
|
178
|
+
# Set parameter.
|
179
179
|
if fields.__class__ == str:
|
180
180
|
fields = [fields]
|
181
181
|
match type_:
|
@@ -275,7 +275,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
275
275
|
SQL.
|
276
276
|
"""
|
277
277
|
|
278
|
-
#
|
278
|
+
# Set parameter.
|
279
279
|
if type(path) == str:
|
280
280
|
database, table = self.db.database, path
|
281
281
|
else:
|
@@ -363,7 +363,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
363
363
|
SQL.
|
364
364
|
"""
|
365
365
|
|
366
|
-
#
|
366
|
+
# Set parameter.
|
367
367
|
if type(path) == str:
|
368
368
|
database, table = self.db.database, path
|
369
369
|
else:
|
@@ -478,7 +478,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
478
478
|
SQL.
|
479
479
|
"""
|
480
480
|
|
481
|
-
#
|
481
|
+
# Set parameter.
|
482
482
|
if type(path) == str:
|
483
483
|
database, table = self.db.database, path
|
484
484
|
else:
|
@@ -509,7 +509,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
509
509
|
SQL.
|
510
510
|
"""
|
511
511
|
|
512
|
-
#
|
512
|
+
# Set parameter.
|
513
513
|
if type(path) == str:
|
514
514
|
database, table = self.db.database, path
|
515
515
|
else:
|
@@ -616,7 +616,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
616
616
|
SQL.
|
617
617
|
"""
|
618
618
|
|
619
|
-
#
|
619
|
+
# Set parameter.
|
620
620
|
if type(path) == str:
|
621
621
|
database, table = self.db.database, path
|
622
622
|
else:
|
@@ -704,7 +704,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
704
704
|
SQL.
|
705
705
|
"""
|
706
706
|
|
707
|
-
#
|
707
|
+
# Set parameter.
|
708
708
|
if type(path) == str:
|
709
709
|
database, table = self.db.database, path
|
710
710
|
else:
|
@@ -792,7 +792,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
792
792
|
SQL.
|
793
793
|
"""
|
794
794
|
|
795
|
-
#
|
795
|
+
# Set parameter.
|
796
796
|
if type(path) == str:
|
797
797
|
database, table = self.db.database, path
|
798
798
|
else:
|
@@ -886,7 +886,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
886
886
|
SQL.
|
887
887
|
"""
|
888
888
|
|
889
|
-
#
|
889
|
+
# Set parameter.
|
890
890
|
if type(path) == str:
|
891
891
|
database, table = self.db.database, path
|
892
892
|
else:
|
@@ -917,7 +917,7 @@ class DatabaseBuildSuper(DatabaseBase, Generic[DatabaseT]):
|
|
917
917
|
SQL.
|
918
918
|
"""
|
919
919
|
|
920
|
-
#
|
920
|
+
# Set parameter.
|
921
921
|
if type(path) == str:
|
922
922
|
database, table = self.db.database, path
|
923
923
|
else:
|
@@ -1104,7 +1104,7 @@ class DatabaseBuild(DatabaseBuildSuper['rdb.Database']):
|
|
1104
1104
|
skip : Whether skip existing table.
|
1105
1105
|
"""
|
1106
1106
|
|
1107
|
-
#
|
1107
|
+
# Set parameter.
|
1108
1108
|
databases = databases or []
|
1109
1109
|
tables = tables or []
|
1110
1110
|
views = views or []
|
@@ -1324,7 +1324,7 @@ class DatabaseBuildAsync(DatabaseBuildSuper['rdb.DatabaseAsync']):
|
|
1324
1324
|
skip : Whether skip existing table.
|
1325
1325
|
"""
|
1326
1326
|
|
1327
|
-
#
|
1327
|
+
# Set parameter.
|
1328
1328
|
databases = databases or []
|
1329
1329
|
tables = tables or []
|
1330
1330
|
tables_orm = tables_orm or []
|
reydb/rconfig.py
CHANGED
@@ -19,8 +19,8 @@ from datetime import (
|
|
19
19
|
from reykit.rbase import Null, throw
|
20
20
|
|
21
21
|
from . import rdb
|
22
|
+
from . import rorm
|
22
23
|
from .rbase import DatabaseBase
|
23
|
-
from .rorm import DatabaseORM as orm
|
24
24
|
|
25
25
|
|
26
26
|
__all__ = (
|
@@ -41,8 +41,17 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
|
|
41
41
|
"""
|
42
42
|
Database config super type.
|
43
43
|
Can create database used `self.build_db` method.
|
44
|
+
|
45
|
+
Attributes
|
46
|
+
----------
|
47
|
+
db_names : Database table name mapping dictionary.
|
44
48
|
"""
|
45
49
|
|
50
|
+
db_names = {
|
51
|
+
'config': 'config',
|
52
|
+
'stats_config': 'stats_config'
|
53
|
+
}
|
54
|
+
|
46
55
|
|
47
56
|
def __init__(self, db: DatabaseT) -> None:
|
48
57
|
"""
|
@@ -55,10 +64,6 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
|
|
55
64
|
|
56
65
|
# Build.
|
57
66
|
self.db = db
|
58
|
-
self.db_names = {
|
59
|
-
'config': 'config',
|
60
|
-
'stats_config': 'stats_config'
|
61
|
-
}
|
62
67
|
|
63
68
|
|
64
69
|
def handle_build_db(self) -> None:
|
@@ -66,19 +71,18 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
|
|
66
71
|
Handle method of check and build database tables, by `self.db_names`.
|
67
72
|
"""
|
68
73
|
|
69
|
-
#
|
74
|
+
# Set parameter.
|
70
75
|
|
71
76
|
## Table.
|
72
|
-
class Config(
|
77
|
+
class Config(rorm.Model, table=True):
|
73
78
|
__name__ = self.db_names['config']
|
74
79
|
__comment__ = 'Config data table.'
|
75
|
-
create_time: Datetime =
|
76
|
-
update_time: Datetime =
|
77
|
-
key: str =
|
78
|
-
value: str =
|
79
|
-
type: str =
|
80
|
-
note: str =
|
81
|
-
|
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.')
|
82
86
|
tables = [Config]
|
83
87
|
|
84
88
|
## View stats.
|
@@ -137,7 +141,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
137
141
|
Check and build database tables, by `self.db_names`.
|
138
142
|
"""
|
139
143
|
|
140
|
-
#
|
144
|
+
# Set parameter.
|
141
145
|
tables, views_stats = self.handle_build_db()
|
142
146
|
|
143
147
|
# Build.
|
@@ -260,7 +264,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
260
264
|
- `ConfigTable`: Config key and value and note.
|
261
265
|
"""
|
262
266
|
|
263
|
-
#
|
267
|
+
# Set parameter.
|
264
268
|
if type(data) == dict:
|
265
269
|
data = [
|
266
270
|
{
|
@@ -421,7 +425,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
421
425
|
value : Config value.
|
422
426
|
"""
|
423
427
|
|
424
|
-
#
|
428
|
+
# Set parameter.
|
425
429
|
if type(key_note) != str:
|
426
430
|
key, note = key_note
|
427
431
|
else:
|
@@ -462,7 +466,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
462
466
|
Asynchronous check and build database tables, by `self.db_names`.
|
463
467
|
"""
|
464
468
|
|
465
|
-
#
|
469
|
+
# Set parameter.
|
466
470
|
tables, views_stats = self.handle_build_db()
|
467
471
|
|
468
472
|
# Build.
|
@@ -585,7 +589,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
585
589
|
- `ConfigTable`: Config key and value and note.
|
586
590
|
"""
|
587
591
|
|
588
|
-
#
|
592
|
+
# Set parameter.
|
589
593
|
if type(data) == dict:
|
590
594
|
data = [
|
591
595
|
{
|
@@ -746,7 +750,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
746
750
|
value : Config value.
|
747
751
|
"""
|
748
752
|
|
749
|
-
#
|
753
|
+
# Set parameter.
|
750
754
|
if type(key_note) != str:
|
751
755
|
key, note = key_note
|
752
756
|
else:
|
reydb/rdb.py
CHANGED
@@ -16,7 +16,7 @@ from sqlalchemy import Engine, create_engine as sqlalchemy_create_engine
|
|
16
16
|
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine as sqlalchemy_create_async_engine
|
17
17
|
from reykit.rtext import join_data_text
|
18
18
|
|
19
|
-
from . import rbase, rbuild, rconfig, rconn, rerror, rexec,
|
19
|
+
from . import rbase, rbuild, rconfig, rconn, rerror, rexec, rinfo, rorm
|
20
20
|
|
21
21
|
|
22
22
|
__all__ = (
|
@@ -31,11 +31,31 @@ DatabaseExecuteT = TypeVar('DatabaseExecuteT', 'rexec.DatabaseExecute', 'rexec.D
|
|
31
31
|
DatabaseORMT = TypeVar('DatabaseORMT', 'rorm.DatabaseORM', 'rorm.DatabaseORMAsync')
|
32
32
|
DatabaseBuildT = TypeVar('DatabaseBuildT', 'rbuild.DatabaseBuild', 'rbuild.DatabaseBuildAsync')
|
33
33
|
DatabaseConfigT = TypeVar('DatabaseConfigT', 'rconfig.DatabaseConfig', 'rconfig.DatabaseConfigAsync')
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
DatabaseInformationSchemaT = TypeVar(
|
35
|
+
'DatabaseInformationSchemaT',
|
36
|
+
'rinfo.DatabaseInformationSchema',
|
37
|
+
'rinfo.DatabaseInformationSchemaAsync'
|
38
|
+
)
|
39
|
+
DatabaseInformationParameterVariablesT = TypeVar(
|
40
|
+
'DatabaseInformationParameterVariablesT',
|
41
|
+
'rinfo.DatabaseInformationParameterVariables',
|
42
|
+
'rinfo.DatabaseInformationParameterVariablesAsync'
|
43
|
+
)
|
44
|
+
DatabaseInformationParameterStatusT = TypeVar(
|
45
|
+
'DatabaseInformationParameterStatusT',
|
46
|
+
'rinfo.DatabaseInformationParameterStatus',
|
47
|
+
'rinfo.DatabaseInformationParameterStatusAsync'
|
48
|
+
)
|
49
|
+
DatabaseInformationParameterVariablesGlobalT = TypeVar(
|
50
|
+
'DatabaseInformationParameterVariablesGlobalT',
|
51
|
+
'rinfo.DatabaseInformationParameterVariablesGlobal',
|
52
|
+
'rinfo.DatabaseInformationParameterVariablesGlobalAsync'
|
53
|
+
)
|
54
|
+
DatabaseInformationParameterStatusGlobalT = TypeVar(
|
55
|
+
'DatabaseInformationParameterStatusGlobalT',
|
56
|
+
'rinfo.DatabaseInformationParameterStatusGlobal',
|
57
|
+
'rinfo.DatabaseInformationParameterStatusGlobalAsync'
|
58
|
+
)
|
39
59
|
|
40
60
|
|
41
61
|
class DatabaseSuper(
|
@@ -47,11 +67,11 @@ class DatabaseSuper(
|
|
47
67
|
DatabaseORMT,
|
48
68
|
DatabaseBuildT,
|
49
69
|
DatabaseConfigT,
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
70
|
+
DatabaseInformationSchemaT,
|
71
|
+
DatabaseInformationParameterVariablesT,
|
72
|
+
DatabaseInformationParameterStatusT,
|
73
|
+
DatabaseInformationParameterVariablesGlobalT,
|
74
|
+
DatabaseInformationParameterStatusGlobalT
|
55
75
|
]
|
56
76
|
):
|
57
77
|
"""
|
@@ -70,7 +90,7 @@ class DatabaseSuper(
|
|
70
90
|
max_overflow: int = 10,
|
71
91
|
pool_timeout: float = 30.0,
|
72
92
|
pool_recycle: int | None = 3600,
|
73
|
-
|
93
|
+
echo: bool = False,
|
74
94
|
**query: str
|
75
95
|
) -> None:
|
76
96
|
"""
|
@@ -89,11 +109,11 @@ class DatabaseSuper(
|
|
89
109
|
pool_recycle : Number of seconds `recycle` connection.
|
90
110
|
- `None | Literal[-1]`: No recycle.
|
91
111
|
- `int`: Use this value.
|
92
|
-
|
112
|
+
echo : Whether report SQL execute information, not include ORM execute.
|
93
113
|
query : Remote server database parameters.
|
94
114
|
"""
|
95
115
|
|
96
|
-
#
|
116
|
+
# Set parameter.
|
97
117
|
if type(port) == str:
|
98
118
|
port = int(port)
|
99
119
|
|
@@ -110,7 +130,7 @@ class DatabaseSuper(
|
|
110
130
|
self.pool_recycle = -1
|
111
131
|
else:
|
112
132
|
self.pool_recycle = pool_recycle
|
113
|
-
self.
|
133
|
+
self.echo = echo
|
114
134
|
self.query = query
|
115
135
|
|
116
136
|
## Schema.
|
@@ -217,7 +237,7 @@ class DatabaseSuper(
|
|
217
237
|
Engine object.
|
218
238
|
"""
|
219
239
|
|
220
|
-
#
|
240
|
+
# Set parameter.
|
221
241
|
engine_params = {
|
222
242
|
'url': self.url,
|
223
243
|
'pool_size': self.pool_size,
|
@@ -380,7 +400,7 @@ class DatabaseSuper(
|
|
380
400
|
|
381
401
|
|
382
402
|
@property
|
383
|
-
def schema(self) ->
|
403
|
+
def schema(self) -> DatabaseInformationSchemaT:
|
384
404
|
"""
|
385
405
|
Build database schema instance.
|
386
406
|
|
@@ -392,15 +412,15 @@ class DatabaseSuper(
|
|
392
412
|
# Build.
|
393
413
|
match self:
|
394
414
|
case Database():
|
395
|
-
schema =
|
415
|
+
schema = rinfo.DatabaseInformationSchema(self)
|
396
416
|
case DatabaseAsync():
|
397
|
-
schema =
|
417
|
+
schema = rinfo.DatabaseInformationSchemaAsync(self)
|
398
418
|
|
399
419
|
return schema
|
400
420
|
|
401
421
|
|
402
422
|
@property
|
403
|
-
def var(self) ->
|
423
|
+
def var(self) -> DatabaseInformationParameterVariablesT:
|
404
424
|
"""
|
405
425
|
Build database parameters variable instance.
|
406
426
|
|
@@ -412,15 +432,15 @@ class DatabaseSuper(
|
|
412
432
|
# Build.
|
413
433
|
match self:
|
414
434
|
case Database():
|
415
|
-
var =
|
435
|
+
var = rinfo.DatabaseInformationParameterVariables(self)
|
416
436
|
case DatabaseAsync():
|
417
|
-
var =
|
437
|
+
var = rinfo.DatabaseInformationParameterVariablesAsync(self)
|
418
438
|
|
419
439
|
return var
|
420
440
|
|
421
441
|
|
422
442
|
@property
|
423
|
-
def stat(self) ->
|
443
|
+
def stat(self) -> DatabaseInformationParameterVariablesT:
|
424
444
|
"""
|
425
445
|
Build database parameters status instance.
|
426
446
|
|
@@ -432,15 +452,15 @@ class DatabaseSuper(
|
|
432
452
|
# Build.
|
433
453
|
match self:
|
434
454
|
case Database():
|
435
|
-
stat =
|
455
|
+
stat = rinfo.DatabaseInformationParameterStatus(self)
|
436
456
|
case DatabaseAsync():
|
437
|
-
stat =
|
457
|
+
stat = rinfo.DatabaseInformationParameterStatusAsync(self)
|
438
458
|
|
439
459
|
return stat
|
440
460
|
|
441
461
|
|
442
462
|
@property
|
443
|
-
def glob_var(self) ->
|
463
|
+
def glob_var(self) -> DatabaseInformationParameterVariablesGlobalT:
|
444
464
|
"""
|
445
465
|
Build global database parameters variable instance.
|
446
466
|
|
@@ -452,15 +472,15 @@ class DatabaseSuper(
|
|
452
472
|
# Build.
|
453
473
|
match self:
|
454
474
|
case Database():
|
455
|
-
var =
|
475
|
+
var = rinfo.DatabaseInformationParameterVariablesGlobal(self)
|
456
476
|
case DatabaseAsync():
|
457
|
-
var =
|
477
|
+
var = rinfo.DatabaseInformationParameterVariablesGlobalAsync(self)
|
458
478
|
|
459
479
|
return var
|
460
480
|
|
461
481
|
|
462
482
|
@property
|
463
|
-
def glob_stat(self) ->
|
483
|
+
def glob_stat(self) -> DatabaseInformationParameterStatusGlobalT:
|
464
484
|
"""
|
465
485
|
Build global database parameters status instance.
|
466
486
|
|
@@ -472,9 +492,9 @@ class DatabaseSuper(
|
|
472
492
|
# Build.
|
473
493
|
match self:
|
474
494
|
case Database():
|
475
|
-
stat =
|
495
|
+
stat = rinfo.DatabaseInformationParameterStatusGlobal(self)
|
476
496
|
case DatabaseAsync():
|
477
|
-
stat =
|
497
|
+
stat = rinfo.DatabaseInformationParameterStatusGlobalAsync(self)
|
478
498
|
|
479
499
|
return stat
|
480
500
|
|
@@ -487,11 +507,11 @@ class Database(
|
|
487
507
|
'rorm.DatabaseORM',
|
488
508
|
'rbuild.DatabaseBuild',
|
489
509
|
'rconfig.DatabaseConfig',
|
490
|
-
'
|
491
|
-
'
|
492
|
-
'
|
493
|
-
'
|
494
|
-
'
|
510
|
+
'rinfo.DatabaseInformationSchema',
|
511
|
+
'rinfo.DatabaseInformationParameterVariables',
|
512
|
+
'rinfo.DatabaseInformationParameterStatus',
|
513
|
+
'rinfo.DatabaseInformationParameterVariablesGlobal',
|
514
|
+
'rinfo.DatabaseInformationParameterStatusGlobal'
|
495
515
|
]
|
496
516
|
):
|
497
517
|
"""
|
@@ -507,11 +527,11 @@ class DatabaseAsync(
|
|
507
527
|
'rorm.DatabaseORMAsync',
|
508
528
|
'rbuild.DatabaseBuildAsync',
|
509
529
|
'rconfig.DatabaseConfigAsync',
|
510
|
-
'
|
511
|
-
'
|
512
|
-
'
|
513
|
-
'
|
514
|
-
'
|
530
|
+
'rinfo.DatabaseInformationSchemaAsync',
|
531
|
+
'rinfo.DatabaseInformationParameterVariablesAsync',
|
532
|
+
'rinfo.DatabaseInformationParameterStatusAsync',
|
533
|
+
'rinfo.DatabaseInformationParameterVariablesGlobalAsync',
|
534
|
+
'rinfo.DatabaseInformationParameterStatusGlobalAsync'
|
515
535
|
]
|
516
536
|
):
|
517
537
|
"""
|
reydb/rerror.py
CHANGED
@@ -14,12 +14,11 @@ from collections.abc import Callable
|
|
14
14
|
from inspect import iscoroutinefunction
|
15
15
|
from traceback import StackSummary
|
16
16
|
from functools import wraps as functools_wraps
|
17
|
-
from datetime import datetime as Datetime
|
18
17
|
from reykit.rbase import T, Exit, catch_exc
|
19
18
|
|
20
19
|
from . import rdb
|
20
|
+
from . import rorm
|
21
21
|
from .rbase import DatabaseBase
|
22
|
-
from .rorm import DatabaseORM as orm
|
23
22
|
|
24
23
|
|
25
24
|
__all__ = (
|
@@ -36,8 +35,17 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
|
|
36
35
|
"""
|
37
36
|
Database error super type.
|
38
37
|
Can create database used `self.build_db` method.
|
38
|
+
|
39
|
+
Attributes
|
40
|
+
----------
|
41
|
+
db_names : Database table name mapping dictionary.
|
39
42
|
"""
|
40
43
|
|
44
|
+
db_names = {
|
45
|
+
'error': 'error',
|
46
|
+
'stats_error': 'stats_error'
|
47
|
+
}
|
48
|
+
|
41
49
|
|
42
50
|
def __init__(self, db: DatabaseT) -> None:
|
43
51
|
"""
|
@@ -50,10 +58,6 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
|
|
50
58
|
|
51
59
|
# Build.
|
52
60
|
self.db = db
|
53
|
-
self.db_names = {
|
54
|
-
'error': 'error',
|
55
|
-
'stats_error': 'stats_error'
|
56
|
-
}
|
57
61
|
|
58
62
|
|
59
63
|
def handle_build_db(self) -> None:
|
@@ -61,18 +65,18 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
|
|
61
65
|
Handle method of check and build database tables, by `self.db_names`.
|
62
66
|
"""
|
63
67
|
|
64
|
-
#
|
68
|
+
# Set parameter.
|
65
69
|
|
66
70
|
## Table.
|
67
|
-
class error(
|
71
|
+
class error(rorm.Model, table=True):
|
68
72
|
__name__ = self.db_names['error']
|
69
73
|
__comment__ = 'Error log table.'
|
70
|
-
create_time: Datetime =
|
71
|
-
id: int =
|
72
|
-
type: str =
|
73
|
-
data: str =
|
74
|
-
stack: str =
|
75
|
-
note: str =
|
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.')
|
76
80
|
tables = [error]
|
77
81
|
|
78
82
|
## View stats.
|
@@ -146,7 +150,7 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
|
|
146
150
|
note : Exception note.
|
147
151
|
"""
|
148
152
|
|
149
|
-
#
|
153
|
+
# Set parameter.
|
150
154
|
exc_type = type(exc).__name__
|
151
155
|
exc_data = list(exc.args) or None
|
152
156
|
exc_stack = [
|
@@ -180,7 +184,7 @@ class DatabaseError(DatabaseErrorSuper['rdb.Database']):
|
|
180
184
|
Check and build database tables, by `self.db_names`.
|
181
185
|
"""
|
182
186
|
|
183
|
-
#
|
187
|
+
# Set parameter.
|
184
188
|
tables, views_stats = self.handle_build_db()
|
185
189
|
|
186
190
|
# Build.
|
@@ -203,7 +207,7 @@ class DatabaseError(DatabaseErrorSuper['rdb.Database']):
|
|
203
207
|
note : Exception note.
|
204
208
|
"""
|
205
209
|
|
206
|
-
#
|
210
|
+
# Set parameter.
|
207
211
|
data = self.handle_record(exc, stack, note)
|
208
212
|
|
209
213
|
# Insert.
|
@@ -230,7 +234,7 @@ class DatabaseError(DatabaseErrorSuper['rdb.Database']):
|
|
230
234
|
filter_type : Exception types of not insert, but still throw exception.
|
231
235
|
"""
|
232
236
|
|
233
|
-
#
|
237
|
+
# Set parameter.
|
234
238
|
_, exc, stack = catch_exc()
|
235
239
|
|
236
240
|
# Filter.
|
@@ -288,7 +292,7 @@ class DatabaseError(DatabaseErrorSuper['rdb.Database']):
|
|
288
292
|
>>> func(*args, **kwargs)
|
289
293
|
"""
|
290
294
|
|
291
|
-
#
|
295
|
+
# Set parameter.
|
292
296
|
if issubclass(filter_type, BaseException):
|
293
297
|
filter_type = (filter_type,)
|
294
298
|
|
@@ -358,7 +362,7 @@ class DatabaseErrorAsync(DatabaseErrorSuper['rdb.DatabaseAsync']):
|
|
358
362
|
Asynchrouous check and build database tables, by `self.db_names`.
|
359
363
|
"""
|
360
364
|
|
361
|
-
#
|
365
|
+
# Set parameter.
|
362
366
|
tables, views_stats = self.handle_build_db()
|
363
367
|
|
364
368
|
# Build.
|
@@ -381,7 +385,7 @@ class DatabaseErrorAsync(DatabaseErrorSuper['rdb.DatabaseAsync']):
|
|
381
385
|
note : Exception note.
|
382
386
|
"""
|
383
387
|
|
384
|
-
#
|
388
|
+
# Set parameter.
|
385
389
|
data = self.handle_record(exc, stack, note)
|
386
390
|
|
387
391
|
# Insert.
|
@@ -408,7 +412,7 @@ class DatabaseErrorAsync(DatabaseErrorSuper['rdb.DatabaseAsync']):
|
|
408
412
|
filter_type : Exception types of not insert, but still throw exception.
|
409
413
|
"""
|
410
414
|
|
411
|
-
#
|
415
|
+
# Set parameter.
|
412
416
|
_, exc, stack = catch_exc()
|
413
417
|
|
414
418
|
# Filter.
|
@@ -467,7 +471,7 @@ class DatabaseErrorAsync(DatabaseErrorSuper['rdb.DatabaseAsync']):
|
|
467
471
|
>>> await func(*args, **kwargs)
|
468
472
|
"""
|
469
473
|
|
470
|
-
#
|
474
|
+
# Set parameter.
|
471
475
|
if issubclass(filter_type, BaseException):
|
472
476
|
filter_type = (filter_type,)
|
473
477
|
|