reydb 1.1.61__py3-none-any.whl → 1.2.1__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 -2
- reydb/rall.py +1 -2
- reydb/rbase.py +0 -48
- reydb/rbuild.py +121 -313
- reydb/rconfig.py +53 -98
- reydb/rdb.py +68 -57
- reydb/rerror.py +305 -111
- reydb/rexec.py +224 -192
- reydb/{rparam.py → rinfo.py} +271 -56
- reydb/rorm.py +139 -115
- {reydb-1.1.61.dist-info → reydb-1.2.1.dist-info}/METADATA +1 -1
- reydb-1.2.1.dist-info/RECORD +15 -0
- reydb/rfile.py +0 -482
- reydb-1.1.61.dist-info/RECORD +0 -16
- {reydb-1.1.61.dist-info → reydb-1.2.1.dist-info}/WHEEL +0 -0
- {reydb-1.1.61.dist-info → reydb-1.2.1.dist-info}/licenses/LICENSE +0 -0
reydb/rconfig.py
CHANGED
@@ -20,6 +20,7 @@ from reykit.rbase import Null, throw
|
|
20
20
|
|
21
21
|
from . import rdb
|
22
22
|
from .rbase import DatabaseBase
|
23
|
+
from .rorm import DatabaseORM as orm
|
23
24
|
|
24
25
|
|
25
26
|
__all__ = (
|
@@ -41,85 +42,60 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
|
|
41
42
|
Database config super type.
|
42
43
|
Can create database used `self.build_db` method.
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
>>> config['key1'] = 1
|
48
|
-
>>> config['key2', 'note'] = 2
|
49
|
-
>>> config['key1'], config['key2']
|
50
|
-
(1, 2)
|
45
|
+
Attributes
|
46
|
+
----------
|
47
|
+
db_names : Database table name mapping dictionary.
|
51
48
|
"""
|
52
49
|
|
50
|
+
db_names = {
|
51
|
+
'config': 'config',
|
52
|
+
'stats_config': 'stats_config'
|
53
|
+
}
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
db: DatabaseT,
|
57
|
-
db_names: dict[str, str] | None = None
|
58
|
-
) -> None:
|
55
|
+
|
56
|
+
def __init__(self, db: DatabaseT) -> None:
|
59
57
|
"""
|
60
58
|
Build instance attributes.
|
61
59
|
|
62
60
|
Parameters
|
63
61
|
----------
|
64
62
|
db: Database instance.
|
65
|
-
db_names: Update build database table names.
|
66
63
|
"""
|
67
64
|
|
68
65
|
# Build.
|
69
66
|
self.db = db
|
70
|
-
self.db_names = {
|
71
|
-
'config': 'config',
|
72
|
-
'stats_config': 'stats_config'
|
73
|
-
}
|
74
|
-
if db_names is not None:
|
75
|
-
self.db_names.update(db_names)
|
76
|
-
|
77
|
-
|
78
|
-
class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
79
|
-
"""
|
80
|
-
Database config type.
|
81
|
-
Can create database used `self.build_db` method.
|
82
|
-
|
83
|
-
Examples
|
84
|
-
--------
|
85
|
-
>>> config = DatabaseConfig()
|
86
|
-
>>> config['key1'] = 1
|
87
|
-
>>> config['key2', 'note'] = 2
|
88
|
-
>>> config['key1'], config['key2']
|
89
|
-
(1, 2)
|
90
|
-
"""
|
91
67
|
|
92
68
|
|
93
|
-
def
|
69
|
+
def handle_build_db(self) -> None:
|
94
70
|
"""
|
95
|
-
|
71
|
+
Handle method of check and build database tables, by `self.db_names`.
|
96
72
|
"""
|
97
73
|
|
98
74
|
# Handle parameter.
|
99
75
|
|
100
76
|
## Table.
|
101
|
-
class Config(
|
77
|
+
class Config(orm.Model, table=True):
|
102
78
|
__name__ = self.db_names['config']
|
103
79
|
__comment__ = 'Config data table.'
|
104
|
-
create_time: Datetime =
|
105
|
-
update_time: Datetime =
|
106
|
-
key: str =
|
107
|
-
value: str =
|
108
|
-
type: str =
|
109
|
-
note: str =
|
80
|
+
create_time: Datetime = orm.Field(field_default='CURRENT_TIMESTAMP', not_null=True, index_n=True, comment='Config create time.')
|
81
|
+
update_time: Datetime = orm.Field(field_default='CURRENT_TIMESTAMP', index_n=True, comment='Config update time.')
|
82
|
+
key: str = orm.Field(field_type=orm.types.VARCHAR(50), key=True, not_null=True, comment='Config key.')
|
83
|
+
value: str = orm.Field(field_type=orm.types.TEXT, not_null=True, comment='Config value.')
|
84
|
+
type: str = orm.Field(field_type=orm.types.VARCHAR(50), not_null=True, comment='Config value type.')
|
85
|
+
note: str = orm.Field(field_type=orm.types.VARCHAR(500), comment='Config note.')
|
110
86
|
|
111
87
|
tables = [Config]
|
112
88
|
|
113
89
|
## View stats.
|
114
90
|
views_stats = [
|
115
91
|
{
|
116
|
-
'path':
|
92
|
+
'path': self.db_names['stats_config'],
|
117
93
|
'items': [
|
118
94
|
{
|
119
95
|
'name': 'count',
|
120
96
|
'select': (
|
121
97
|
'SELECT COUNT(1)\n'
|
122
|
-
f'FROM `{self.db_names['config']}`'
|
98
|
+
f'FROM `{self.db.database}`.`{self.db_names['config']}`'
|
123
99
|
),
|
124
100
|
'comment': 'Config count.'
|
125
101
|
},
|
@@ -127,7 +103,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
127
103
|
'name': 'last_create_time',
|
128
104
|
'select': (
|
129
105
|
'SELECT MAX(`create_time`)\n'
|
130
|
-
f'FROM `{self.db_names['config']}`'
|
106
|
+
f'FROM `{self.db.database}`.`{self.db_names['config']}`'
|
131
107
|
),
|
132
108
|
'comment': 'Config last record create time.'
|
133
109
|
},
|
@@ -135,15 +111,40 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
135
111
|
'name': 'last_update_time',
|
136
112
|
'select': (
|
137
113
|
'SELECT MAX(`update_time`)\n'
|
138
|
-
f'FROM `{self.db_names['config']}`'
|
114
|
+
f'FROM `{self.db.database}`.`{self.db_names['config']}`'
|
139
115
|
),
|
140
116
|
'comment': 'Config last record update time.'
|
141
117
|
}
|
142
118
|
]
|
143
119
|
}
|
144
|
-
|
145
120
|
]
|
146
121
|
|
122
|
+
return tables, views_stats
|
123
|
+
|
124
|
+
|
125
|
+
class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
126
|
+
"""
|
127
|
+
Database config type.
|
128
|
+
Can create database used `self.build_db` method.
|
129
|
+
|
130
|
+
Examples
|
131
|
+
--------
|
132
|
+
>>> config = DatabaseConfig()
|
133
|
+
>>> config['key1'] = 1
|
134
|
+
>>> config['key2', 'note'] = 2
|
135
|
+
>>> config['key1'], config['key2']
|
136
|
+
(1, 2)
|
137
|
+
"""
|
138
|
+
|
139
|
+
|
140
|
+
def build_db(self) -> None:
|
141
|
+
"""
|
142
|
+
Check and build database tables, by `self.db_names`.
|
143
|
+
"""
|
144
|
+
|
145
|
+
# Handle parameter.
|
146
|
+
tables, views_stats = self.handle_build_db()
|
147
|
+
|
147
148
|
# Build.
|
148
149
|
self.db.build.build(tables=tables, views_stats=views_stats, skip=True)
|
149
150
|
|
@@ -454,9 +455,9 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
454
455
|
Examples
|
455
456
|
--------
|
456
457
|
>>> config = DatabaseConfig()
|
457
|
-
>>> config['key1'] = 1
|
458
|
-
>>> config['key2', 'note'] = 2
|
459
|
-
>>> config['key1'], config['key2']
|
458
|
+
>>> await config['key1'] = 1
|
459
|
+
>>> await config['key2', 'note'] = 2
|
460
|
+
>>> await config['key1'], config['key2']
|
460
461
|
(1, 2)
|
461
462
|
"""
|
462
463
|
|
@@ -467,53 +468,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
467
468
|
"""
|
468
469
|
|
469
470
|
# Handle parameter.
|
470
|
-
|
471
|
-
## Table.
|
472
|
-
class Config(self.db.orm.Model, table=True):
|
473
|
-
__name__ = self.db_names['config']
|
474
|
-
__comment__ = 'Config data table.'
|
475
|
-
create_time: Datetime = self.db.orm.Field(not_null=True, field_default='CURRENT_TIMESTAMP', index_n=True, comment='Config create time.')
|
476
|
-
update_time: Datetime = self.db.orm.Field(field_default='CURRENT_TIMESTAMP', index_n=True, comment='Config update time.')
|
477
|
-
key: str = self.db.orm.Field(type=self.db.orm.types.VARCHAR(50), key=True, not_null=True, comment='Config key.')
|
478
|
-
value: str = self.db.orm.Field(type=self.db.orm.types.TEXT, not_null=True, comment='Config value.')
|
479
|
-
type: str = self.db.orm.Field(type=self.db.orm.types.VARCHAR(50), not_null=True, comment='Config value type.')
|
480
|
-
note: str = self.db.orm.Field(type=self.db.orm.types.VARCHAR(500), comment='Config note.')
|
481
|
-
|
482
|
-
tables = [Config]
|
483
|
-
|
484
|
-
## View stats.
|
485
|
-
views_stats = [
|
486
|
-
{
|
487
|
-
'path': (self.db.database, self.db_names['stats_config']),
|
488
|
-
'items': [
|
489
|
-
{
|
490
|
-
'name': 'count',
|
491
|
-
'select': (
|
492
|
-
'SELECT COUNT(1)\n'
|
493
|
-
f'FROM `{self.db_names['config']}`'
|
494
|
-
),
|
495
|
-
'comment': 'Config count.'
|
496
|
-
},
|
497
|
-
{
|
498
|
-
'name': 'last_create_time',
|
499
|
-
'select': (
|
500
|
-
'SELECT MAX(`create_time`)\n'
|
501
|
-
f'FROM `{self.db_names['config']}`'
|
502
|
-
),
|
503
|
-
'comment': 'Config last record create time.'
|
504
|
-
},
|
505
|
-
{
|
506
|
-
'name': 'last_update_time',
|
507
|
-
'select': (
|
508
|
-
'SELECT MAX(`update_time`)\n'
|
509
|
-
f'FROM `{self.db_names['config']}`'
|
510
|
-
),
|
511
|
-
'comment': 'Config last record update time.'
|
512
|
-
}
|
513
|
-
]
|
514
|
-
}
|
515
|
-
|
516
|
-
]
|
471
|
+
tables, views_stats = self.handle_build_db()
|
517
472
|
|
518
473
|
# Build.
|
519
474
|
await self.db.build.build(tables=tables, views_stats=views_stats, skip=True)
|
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,7 +109,7 @@ 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
|
|
@@ -110,9 +130,12 @@ 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
|
|
136
|
+
## Schema.
|
137
|
+
self._schema: dict[str, dict[str, list[str]]] | None = None
|
138
|
+
|
116
139
|
## Create engine.
|
117
140
|
self.engine = self.__create_engine()
|
118
141
|
|
@@ -336,22 +359,6 @@ class DatabaseSuper(
|
|
336
359
|
return build
|
337
360
|
|
338
361
|
|
339
|
-
@property
|
340
|
-
def file(self):
|
341
|
-
"""
|
342
|
-
Build database file instance.
|
343
|
-
|
344
|
-
Returns
|
345
|
-
-------
|
346
|
-
Instance.
|
347
|
-
"""
|
348
|
-
|
349
|
-
# Build.
|
350
|
-
dbfile = rfile.DatabaseFile(self)
|
351
|
-
|
352
|
-
return dbfile
|
353
|
-
|
354
|
-
|
355
362
|
@property
|
356
363
|
def error(self):
|
357
364
|
"""
|
@@ -363,9 +370,13 @@ class DatabaseSuper(
|
|
363
370
|
"""
|
364
371
|
|
365
372
|
# Build.
|
366
|
-
|
373
|
+
match self:
|
374
|
+
case Database():
|
375
|
+
error = rerror.DatabaseError(self)
|
376
|
+
case DatabaseAsync():
|
377
|
+
error = rerror.DatabaseErrorAsync(self)
|
367
378
|
|
368
|
-
return
|
379
|
+
return error
|
369
380
|
|
370
381
|
|
371
382
|
@property
|
@@ -389,7 +400,7 @@ class DatabaseSuper(
|
|
389
400
|
|
390
401
|
|
391
402
|
@property
|
392
|
-
def schema(self) ->
|
403
|
+
def schema(self) -> DatabaseInformationSchemaT:
|
393
404
|
"""
|
394
405
|
Build database schema instance.
|
395
406
|
|
@@ -401,15 +412,15 @@ class DatabaseSuper(
|
|
401
412
|
# Build.
|
402
413
|
match self:
|
403
414
|
case Database():
|
404
|
-
schema =
|
415
|
+
schema = rinfo.DatabaseInformationSchema(self)
|
405
416
|
case DatabaseAsync():
|
406
|
-
schema =
|
417
|
+
schema = rinfo.DatabaseInformationSchemaAsync(self)
|
407
418
|
|
408
419
|
return schema
|
409
420
|
|
410
421
|
|
411
422
|
@property
|
412
|
-
def var(self) ->
|
423
|
+
def var(self) -> DatabaseInformationParameterVariablesT:
|
413
424
|
"""
|
414
425
|
Build database parameters variable instance.
|
415
426
|
|
@@ -421,15 +432,15 @@ class DatabaseSuper(
|
|
421
432
|
# Build.
|
422
433
|
match self:
|
423
434
|
case Database():
|
424
|
-
var =
|
435
|
+
var = rinfo.DatabaseInformationParameterVariables(self)
|
425
436
|
case DatabaseAsync():
|
426
|
-
var =
|
437
|
+
var = rinfo.DatabaseInformationParameterVariablesAsync(self)
|
427
438
|
|
428
439
|
return var
|
429
440
|
|
430
441
|
|
431
442
|
@property
|
432
|
-
def stat(self) ->
|
443
|
+
def stat(self) -> DatabaseInformationParameterVariablesT:
|
433
444
|
"""
|
434
445
|
Build database parameters status instance.
|
435
446
|
|
@@ -441,15 +452,15 @@ class DatabaseSuper(
|
|
441
452
|
# Build.
|
442
453
|
match self:
|
443
454
|
case Database():
|
444
|
-
stat =
|
455
|
+
stat = rinfo.DatabaseInformationParameterStatus(self)
|
445
456
|
case DatabaseAsync():
|
446
|
-
stat =
|
457
|
+
stat = rinfo.DatabaseInformationParameterStatusAsync(self)
|
447
458
|
|
448
459
|
return stat
|
449
460
|
|
450
461
|
|
451
462
|
@property
|
452
|
-
def glob_var(self) ->
|
463
|
+
def glob_var(self) -> DatabaseInformationParameterVariablesGlobalT:
|
453
464
|
"""
|
454
465
|
Build global database parameters variable instance.
|
455
466
|
|
@@ -461,15 +472,15 @@ class DatabaseSuper(
|
|
461
472
|
# Build.
|
462
473
|
match self:
|
463
474
|
case Database():
|
464
|
-
var =
|
475
|
+
var = rinfo.DatabaseInformationParameterVariablesGlobal(self)
|
465
476
|
case DatabaseAsync():
|
466
|
-
var =
|
477
|
+
var = rinfo.DatabaseInformationParameterVariablesGlobalAsync(self)
|
467
478
|
|
468
479
|
return var
|
469
480
|
|
470
481
|
|
471
482
|
@property
|
472
|
-
def glob_stat(self) ->
|
483
|
+
def glob_stat(self) -> DatabaseInformationParameterStatusGlobalT:
|
473
484
|
"""
|
474
485
|
Build global database parameters status instance.
|
475
486
|
|
@@ -481,9 +492,9 @@ class DatabaseSuper(
|
|
481
492
|
# Build.
|
482
493
|
match self:
|
483
494
|
case Database():
|
484
|
-
stat =
|
495
|
+
stat = rinfo.DatabaseInformationParameterStatusGlobal(self)
|
485
496
|
case DatabaseAsync():
|
486
|
-
stat =
|
497
|
+
stat = rinfo.DatabaseInformationParameterStatusGlobalAsync(self)
|
487
498
|
|
488
499
|
return stat
|
489
500
|
|
@@ -496,11 +507,11 @@ class Database(
|
|
496
507
|
'rorm.DatabaseORM',
|
497
508
|
'rbuild.DatabaseBuild',
|
498
509
|
'rconfig.DatabaseConfig',
|
499
|
-
'
|
500
|
-
'
|
501
|
-
'
|
502
|
-
'
|
503
|
-
'
|
510
|
+
'rinfo.DatabaseInformationSchema',
|
511
|
+
'rinfo.DatabaseInformationParameterVariables',
|
512
|
+
'rinfo.DatabaseInformationParameterStatus',
|
513
|
+
'rinfo.DatabaseInformationParameterVariablesGlobal',
|
514
|
+
'rinfo.DatabaseInformationParameterStatusGlobal'
|
504
515
|
]
|
505
516
|
):
|
506
517
|
"""
|
@@ -516,11 +527,11 @@ class DatabaseAsync(
|
|
516
527
|
'rorm.DatabaseORMAsync',
|
517
528
|
'rbuild.DatabaseBuildAsync',
|
518
529
|
'rconfig.DatabaseConfigAsync',
|
519
|
-
'
|
520
|
-
'
|
521
|
-
'
|
522
|
-
'
|
523
|
-
'
|
530
|
+
'rinfo.DatabaseInformationSchemaAsync',
|
531
|
+
'rinfo.DatabaseInformationParameterVariablesAsync',
|
532
|
+
'rinfo.DatabaseInformationParameterStatusAsync',
|
533
|
+
'rinfo.DatabaseInformationParameterVariablesGlobalAsync',
|
534
|
+
'rinfo.DatabaseInformationParameterStatusGlobalAsync'
|
524
535
|
]
|
525
536
|
):
|
526
537
|
"""
|