reydb 1.1.59__py3-none-any.whl → 1.1.61__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 +0 -1
- reydb/rall.py +0 -1
- reydb/rbase.py +0 -10
- reydb/rbuild.py +683 -177
- reydb/rconfig.py +435 -104
- reydb/rconn.py +44 -40
- reydb/rdb.py +88 -72
- reydb/rerror.py +2 -2
- reydb/rexec.py +89 -121
- reydb/rfile.py +4 -4
- reydb/rorm.py +41 -24
- reydb/rparam.py +191 -56
- {reydb-1.1.59.dist-info → reydb-1.1.61.dist-info}/METADATA +1 -1
- reydb-1.1.61.dist-info/RECORD +16 -0
- reydb/rinfo.py +0 -499
- reydb-1.1.59.dist-info/RECORD +0 -17
- {reydb-1.1.59.dist-info → reydb-1.1.61.dist-info}/WHEEL +0 -0
- {reydb-1.1.59.dist-info → reydb-1.1.61.dist-info}/licenses/LICENSE +0 -0
reydb/rconn.py
CHANGED
@@ -9,12 +9,12 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import Self, Generic
|
12
|
+
from typing import Self, TypeVar, Generic
|
13
13
|
from sqlalchemy import Connection, Transaction
|
14
14
|
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncTransaction
|
15
15
|
|
16
16
|
from . import rdb, rexec
|
17
|
-
from .rbase import
|
17
|
+
from .rbase import ConnectionT, TransactionT, DatabaseBase
|
18
18
|
|
19
19
|
|
20
20
|
__all__ = (
|
@@ -24,6 +24,10 @@ __all__ = (
|
|
24
24
|
)
|
25
25
|
|
26
26
|
|
27
|
+
DatabaseT = TypeVar('DatabaseT', 'rdb.Database', 'rdb.DatabaseAsync')
|
28
|
+
DatabaseExecuteT = TypeVar('DatabaseExecuteT', 'rexec.DatabaseExecute', 'rexec.DatabaseExecuteAsync')
|
29
|
+
|
30
|
+
|
27
31
|
class DatabaseConnectionSuper(DatabaseBase, Generic[DatabaseT, DatabaseExecuteT, ConnectionT, TransactionT]):
|
28
32
|
"""
|
29
33
|
Database connection super type.
|
@@ -53,8 +57,8 @@ class DatabaseConnectionSuper(DatabaseBase, Generic[DatabaseT, DatabaseExecuteT,
|
|
53
57
|
case rdb.DatabaseAsync():
|
54
58
|
exec = rexec.DatabaseExecuteAsync(self)
|
55
59
|
self.execute: DatabaseExecuteT = exec
|
56
|
-
self.
|
57
|
-
self.
|
60
|
+
self.connection: ConnectionT | None = None
|
61
|
+
self.transaction: TransactionT | None = None
|
58
62
|
|
59
63
|
|
60
64
|
class DatabaseConnection(DatabaseConnectionSuper['rdb.Database', 'rexec.DatabaseExecute', Connection, Transaction]):
|
@@ -106,10 +110,10 @@ class DatabaseConnection(DatabaseConnectionSuper['rdb.Database', 'rexec.Database
|
|
106
110
|
"""
|
107
111
|
|
108
112
|
# Create.
|
109
|
-
if self.
|
110
|
-
self.
|
113
|
+
if self.connection is None:
|
114
|
+
self.connection = self.db.engine.connect()
|
111
115
|
|
112
|
-
return self.
|
116
|
+
return self.connection
|
113
117
|
|
114
118
|
|
115
119
|
def get_begin(self) -> Transaction:
|
@@ -122,11 +126,11 @@ class DatabaseConnection(DatabaseConnectionSuper['rdb.Database', 'rexec.Database
|
|
122
126
|
"""
|
123
127
|
|
124
128
|
# Create.
|
125
|
-
if self.
|
129
|
+
if self.transaction is None:
|
126
130
|
conn = self.get_conn()
|
127
|
-
self.
|
131
|
+
self.transaction = conn.begin()
|
128
132
|
|
129
|
-
return self.
|
133
|
+
return self.transaction
|
130
134
|
|
131
135
|
|
132
136
|
def commit(self) -> None:
|
@@ -135,9 +139,9 @@ class DatabaseConnection(DatabaseConnectionSuper['rdb.Database', 'rexec.Database
|
|
135
139
|
"""
|
136
140
|
|
137
141
|
# Commit.
|
138
|
-
if self.
|
139
|
-
self.
|
140
|
-
self.
|
142
|
+
if self.transaction is not None:
|
143
|
+
self.transaction.commit()
|
144
|
+
self.transaction = None
|
141
145
|
|
142
146
|
|
143
147
|
def rollback(self) -> None:
|
@@ -146,9 +150,9 @@ class DatabaseConnection(DatabaseConnectionSuper['rdb.Database', 'rexec.Database
|
|
146
150
|
"""
|
147
151
|
|
148
152
|
# Rollback.
|
149
|
-
if self.
|
150
|
-
self.
|
151
|
-
self.
|
153
|
+
if self.transaction is not None:
|
154
|
+
self.transaction.rollback()
|
155
|
+
self.transaction = None
|
152
156
|
|
153
157
|
|
154
158
|
def close(self) -> None:
|
@@ -157,12 +161,12 @@ class DatabaseConnection(DatabaseConnectionSuper['rdb.Database', 'rexec.Database
|
|
157
161
|
"""
|
158
162
|
|
159
163
|
# Close.
|
160
|
-
if self.
|
161
|
-
self.
|
162
|
-
self.
|
163
|
-
if self.
|
164
|
-
self.
|
165
|
-
self.
|
164
|
+
if self.transaction is not None:
|
165
|
+
self.transaction.close()
|
166
|
+
self.transaction = None
|
167
|
+
if self.connection is not None:
|
168
|
+
self.connection.close()
|
169
|
+
self.connection = None
|
166
170
|
|
167
171
|
|
168
172
|
def insert_id(self) -> int:
|
@@ -232,10 +236,10 @@ class DatabaseConnectionAsync(DatabaseConnectionSuper['rdb.DatabaseAsync', 'rexe
|
|
232
236
|
"""
|
233
237
|
|
234
238
|
# Create.
|
235
|
-
if self.
|
236
|
-
self.
|
239
|
+
if self.connection is None:
|
240
|
+
self.connection = await self.db.engine.connect()
|
237
241
|
|
238
|
-
return self.
|
242
|
+
return self.connection
|
239
243
|
|
240
244
|
|
241
245
|
async def get_begin(self) -> AsyncTransaction:
|
@@ -248,11 +252,11 @@ class DatabaseConnectionAsync(DatabaseConnectionSuper['rdb.DatabaseAsync', 'rexe
|
|
248
252
|
"""
|
249
253
|
|
250
254
|
# Create.
|
251
|
-
if self.
|
255
|
+
if self.transaction is None:
|
252
256
|
conn = await self.get_conn()
|
253
|
-
self.
|
257
|
+
self.transaction = await conn.begin()
|
254
258
|
|
255
|
-
return self.
|
259
|
+
return self.transaction
|
256
260
|
|
257
261
|
|
258
262
|
async def commit(self) -> None:
|
@@ -261,9 +265,9 @@ class DatabaseConnectionAsync(DatabaseConnectionSuper['rdb.DatabaseAsync', 'rexe
|
|
261
265
|
"""
|
262
266
|
|
263
267
|
# Commit.
|
264
|
-
if self.
|
265
|
-
await self.
|
266
|
-
self.
|
268
|
+
if self.transaction is not None:
|
269
|
+
await self.transaction.commit()
|
270
|
+
self.transaction = None
|
267
271
|
|
268
272
|
|
269
273
|
async def rollback(self) -> None:
|
@@ -272,9 +276,9 @@ class DatabaseConnectionAsync(DatabaseConnectionSuper['rdb.DatabaseAsync', 'rexe
|
|
272
276
|
"""
|
273
277
|
|
274
278
|
# Rollback.
|
275
|
-
if self.
|
276
|
-
await self.
|
277
|
-
self.
|
279
|
+
if self.transaction is not None:
|
280
|
+
await self.transaction.rollback()
|
281
|
+
self.transaction = None
|
278
282
|
|
279
283
|
|
280
284
|
async def close(self) -> None:
|
@@ -283,12 +287,12 @@ class DatabaseConnectionAsync(DatabaseConnectionSuper['rdb.DatabaseAsync', 'rexe
|
|
283
287
|
"""
|
284
288
|
|
285
289
|
# Close.
|
286
|
-
if self.
|
287
|
-
await self.
|
288
|
-
self.
|
289
|
-
if self.
|
290
|
-
await self.
|
291
|
-
self.
|
290
|
+
if self.transaction is not None:
|
291
|
+
await self.transaction.close()
|
292
|
+
self.transaction = None
|
293
|
+
if self.connection is not None:
|
294
|
+
await self.connection.close()
|
295
|
+
self.connection = None
|
292
296
|
|
293
297
|
|
294
298
|
async def insert_id(self) -> int:
|
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, rfile,
|
19
|
+
from . import rbase, rbuild, rconfig, rconn, rerror, rexec, rfile, rorm, rparam
|
20
20
|
|
21
21
|
|
22
22
|
__all__ = (
|
@@ -26,14 +26,32 @@ __all__ = (
|
|
26
26
|
)
|
27
27
|
|
28
28
|
|
29
|
+
DatabaseConnectionT = TypeVar('DatabaseConnectionT', 'rconn.DatabaseConnection', 'rconn.DatabaseConnectionAsync')
|
30
|
+
DatabaseExecuteT = TypeVar('DatabaseExecuteT', 'rexec.DatabaseExecute', 'rexec.DatabaseExecuteAsync')
|
31
|
+
DatabaseORMT = TypeVar('DatabaseORMT', 'rorm.DatabaseORM', 'rorm.DatabaseORMAsync')
|
32
|
+
DatabaseBuildT = TypeVar('DatabaseBuildT', 'rbuild.DatabaseBuild', 'rbuild.DatabaseBuildAsync')
|
33
|
+
DatabaseConfigT = TypeVar('DatabaseConfigT', 'rconfig.DatabaseConfig', 'rconfig.DatabaseConfigAsync')
|
34
|
+
DatabaseSchemaT = TypeVar('DatabaseSchemaT', 'rparam.DatabaseSchema', 'rparam.DatabaseSchemaAsync')
|
35
|
+
DatabaseParametersVariablesT = TypeVar('DatabaseParametersVariablesT', 'rparam.DatabaseParametersVariables', 'rparam.DatabaseParametersVariablesAsync')
|
36
|
+
DatabaseParametersStatusT = TypeVar('DatabaseParametersStatusT', 'rparam.DatabaseParametersStatus', 'rparam.DatabaseParametersStatusAsync')
|
37
|
+
DatabaseParametersVariablesGlobalT = TypeVar('DatabaseParametersVariablesGlobalT', 'rparam.DatabaseParametersVariablesGlobal', 'rparam.DatabaseParametersVariablesGlobalAsync')
|
38
|
+
DatabaseParametersStatusGlobalT = TypeVar('DatabaseParametersStatusGlobalT', 'rparam.DatabaseParametersStatusGlobal', 'rparam.DatabaseParametersStatusGlobalAsync')
|
39
|
+
|
40
|
+
|
29
41
|
class DatabaseSuper(
|
30
42
|
rbase.DatabaseBase,
|
31
43
|
Generic[
|
32
44
|
rbase.EngineT,
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
45
|
+
DatabaseConnectionT,
|
46
|
+
DatabaseExecuteT,
|
47
|
+
DatabaseORMT,
|
48
|
+
DatabaseBuildT,
|
49
|
+
DatabaseConfigT,
|
50
|
+
DatabaseSchemaT,
|
51
|
+
DatabaseParametersVariablesT,
|
52
|
+
DatabaseParametersStatusT,
|
53
|
+
DatabaseParametersVariablesGlobalT,
|
54
|
+
DatabaseParametersStatusGlobalT
|
37
55
|
]
|
38
56
|
):
|
39
57
|
"""
|
@@ -71,7 +89,7 @@ class DatabaseSuper(
|
|
71
89
|
pool_recycle : Number of seconds `recycle` connection.
|
72
90
|
- `None | Literal[-1]`: No recycle.
|
73
91
|
- `int`: Use this value.
|
74
|
-
report : Whether report SQL execute information.
|
92
|
+
report : Whether report SQL execute information, not include ORM execute.
|
75
93
|
query : Remote server database parameters.
|
76
94
|
"""
|
77
95
|
|
@@ -238,7 +256,7 @@ class DatabaseSuper(
|
|
238
256
|
return keep_n, overflow_n
|
239
257
|
|
240
258
|
|
241
|
-
def connect(self, autocommit: bool = False) ->
|
259
|
+
def connect(self, autocommit: bool = False) -> DatabaseConnectionT:
|
242
260
|
"""
|
243
261
|
Build database connection instance.
|
244
262
|
|
@@ -262,7 +280,7 @@ class DatabaseSuper(
|
|
262
280
|
|
263
281
|
|
264
282
|
@property
|
265
|
-
def execute(self) ->
|
283
|
+
def execute(self) -> DatabaseExecuteT:
|
266
284
|
"""
|
267
285
|
Build database execute instance.
|
268
286
|
|
@@ -279,7 +297,7 @@ class DatabaseSuper(
|
|
279
297
|
|
280
298
|
|
281
299
|
@property
|
282
|
-
def orm(self) ->
|
300
|
+
def orm(self) -> DatabaseORMT:
|
283
301
|
"""
|
284
302
|
Build database ORM instance.
|
285
303
|
|
@@ -299,7 +317,7 @@ class DatabaseSuper(
|
|
299
317
|
|
300
318
|
|
301
319
|
@property
|
302
|
-
def build(self):
|
320
|
+
def build(self) -> DatabaseBuildT:
|
303
321
|
"""
|
304
322
|
Build database build instance.
|
305
323
|
|
@@ -309,9 +327,13 @@ class DatabaseSuper(
|
|
309
327
|
"""
|
310
328
|
|
311
329
|
# Build.
|
312
|
-
|
330
|
+
match self:
|
331
|
+
case Database():
|
332
|
+
build = rbuild.DatabaseBuild(self)
|
333
|
+
case DatabaseAsync():
|
334
|
+
build = rbuild.DatabaseBuildAsync(self)
|
313
335
|
|
314
|
-
return
|
336
|
+
return build
|
315
337
|
|
316
338
|
|
317
339
|
@property
|
@@ -347,7 +369,7 @@ class DatabaseSuper(
|
|
347
369
|
|
348
370
|
|
349
371
|
@property
|
350
|
-
def config(self):
|
372
|
+
def config(self) -> DatabaseConfigT:
|
351
373
|
"""
|
352
374
|
Build database config instance.
|
353
375
|
|
@@ -357,49 +379,17 @@ class DatabaseSuper(
|
|
357
379
|
"""
|
358
380
|
|
359
381
|
# Build.
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
@property
|
366
|
-
def info(self):
|
367
|
-
"""
|
368
|
-
Build database information schema instance.
|
369
|
-
|
370
|
-
Returns
|
371
|
-
-------
|
372
|
-
Instance.
|
373
|
-
|
374
|
-
Examples
|
375
|
-
--------
|
376
|
-
Get databases information of server.
|
377
|
-
>>> databases_info = DatabaseInformationSchema()
|
378
|
-
|
379
|
-
Get tables information of database.
|
380
|
-
>>> tables_info = DatabaseInformationSchema.database()
|
381
|
-
|
382
|
-
Get columns information of table.
|
383
|
-
>>> columns_info = DatabaseInformationSchema.database.table()
|
384
|
-
|
385
|
-
Get database attribute.
|
386
|
-
>>> database_attr = DatabaseInformationSchema.database['attribute']
|
387
|
-
|
388
|
-
Get table attribute.
|
389
|
-
>>> database_attr = DatabaseInformationSchema.database.table['attribute']
|
390
|
-
|
391
|
-
Get column attribute.
|
392
|
-
>>> database_attr = DatabaseInformationSchema.database.table.column['attribute']
|
393
|
-
"""
|
394
|
-
|
395
|
-
# Build.
|
396
|
-
dbischema = rinfo.DatabaseInformationSchema(self)
|
382
|
+
match self:
|
383
|
+
case Database():
|
384
|
+
config = rconfig.DatabaseConfig(self)
|
385
|
+
case DatabaseAsync():
|
386
|
+
config = rconfig.DatabaseConfigAsync(self)
|
397
387
|
|
398
|
-
return
|
388
|
+
return config
|
399
389
|
|
400
390
|
|
401
391
|
@property
|
402
|
-
def schema(self) ->
|
392
|
+
def schema(self) -> DatabaseSchemaT:
|
403
393
|
"""
|
404
394
|
Build database schema instance.
|
405
395
|
|
@@ -419,9 +409,9 @@ class DatabaseSuper(
|
|
419
409
|
|
420
410
|
|
421
411
|
@property
|
422
|
-
def
|
412
|
+
def var(self) -> DatabaseParametersVariablesT:
|
423
413
|
"""
|
424
|
-
Build database parameters
|
414
|
+
Build database parameters variable instance.
|
425
415
|
|
426
416
|
Returns
|
427
417
|
-------
|
@@ -429,15 +419,19 @@ class DatabaseSuper(
|
|
429
419
|
"""
|
430
420
|
|
431
421
|
# Build.
|
432
|
-
|
422
|
+
match self:
|
423
|
+
case Database():
|
424
|
+
var = rparam.DatabaseParametersVariables(self)
|
425
|
+
case DatabaseAsync():
|
426
|
+
var = rparam.DatabaseParametersVariablesAsync(self)
|
433
427
|
|
434
|
-
return
|
428
|
+
return var
|
435
429
|
|
436
430
|
|
437
431
|
@property
|
438
|
-
def
|
432
|
+
def stat(self) -> DatabaseParametersVariablesT:
|
439
433
|
"""
|
440
|
-
Build
|
434
|
+
Build database parameters status instance.
|
441
435
|
|
442
436
|
Returns
|
443
437
|
-------
|
@@ -445,15 +439,19 @@ class DatabaseSuper(
|
|
445
439
|
"""
|
446
440
|
|
447
441
|
# Build.
|
448
|
-
|
442
|
+
match self:
|
443
|
+
case Database():
|
444
|
+
stat = rparam.DatabaseParametersStatus(self)
|
445
|
+
case DatabaseAsync():
|
446
|
+
stat = rparam.DatabaseParametersStatusAsync(self)
|
449
447
|
|
450
|
-
return
|
448
|
+
return stat
|
451
449
|
|
452
450
|
|
453
451
|
@property
|
454
|
-
def
|
452
|
+
def glob_var(self) -> DatabaseParametersVariablesGlobalT:
|
455
453
|
"""
|
456
|
-
Build database parameters variable instance.
|
454
|
+
Build global database parameters variable instance.
|
457
455
|
|
458
456
|
Returns
|
459
457
|
-------
|
@@ -461,15 +459,19 @@ class DatabaseSuper(
|
|
461
459
|
"""
|
462
460
|
|
463
461
|
# Build.
|
464
|
-
|
462
|
+
match self:
|
463
|
+
case Database():
|
464
|
+
var = rparam.DatabaseParametersVariablesGlobal(self)
|
465
|
+
case DatabaseAsync():
|
466
|
+
var = rparam.DatabaseParametersVariablesGlobalAsync(self)
|
465
467
|
|
466
|
-
return
|
468
|
+
return var
|
467
469
|
|
468
470
|
|
469
471
|
@property
|
470
|
-
def
|
472
|
+
def glob_stat(self) -> DatabaseParametersStatusGlobalT:
|
471
473
|
"""
|
472
|
-
Build global database parameters
|
474
|
+
Build global database parameters status instance.
|
473
475
|
|
474
476
|
Returns
|
475
477
|
-------
|
@@ -477,11 +479,13 @@ class DatabaseSuper(
|
|
477
479
|
"""
|
478
480
|
|
479
481
|
# Build.
|
482
|
+
match self:
|
483
|
+
case Database():
|
484
|
+
stat = rparam.DatabaseParametersStatusGlobal(self)
|
485
|
+
case DatabaseAsync():
|
486
|
+
stat = rparam.DatabaseParametersStatusGlobalAsync(self)
|
480
487
|
|
481
|
-
|
482
|
-
dbpv = rparam.DatabaseParametersVariable(self, True)
|
483
|
-
|
484
|
-
return dbpv
|
488
|
+
return stat
|
485
489
|
|
486
490
|
|
487
491
|
class Database(
|
@@ -489,8 +493,14 @@ class Database(
|
|
489
493
|
Engine,
|
490
494
|
'rconn.DatabaseConnection',
|
491
495
|
'rexec.DatabaseExecute',
|
496
|
+
'rorm.DatabaseORM',
|
497
|
+
'rbuild.DatabaseBuild',
|
498
|
+
'rconfig.DatabaseConfig',
|
492
499
|
'rparam.DatabaseSchema',
|
493
|
-
'
|
500
|
+
'rparam.DatabaseParametersVariables',
|
501
|
+
'rparam.DatabaseParametersStatus',
|
502
|
+
'rparam.DatabaseParametersVariablesGlobal',
|
503
|
+
'rparam.DatabaseParametersStatusGlobal'
|
494
504
|
]
|
495
505
|
):
|
496
506
|
"""
|
@@ -503,8 +513,14 @@ class DatabaseAsync(
|
|
503
513
|
AsyncEngine,
|
504
514
|
'rconn.DatabaseConnectionAsync',
|
505
515
|
'rexec.DatabaseExecuteAsync',
|
516
|
+
'rorm.DatabaseORMAsync',
|
517
|
+
'rbuild.DatabaseBuildAsync',
|
518
|
+
'rconfig.DatabaseConfigAsync',
|
506
519
|
'rparam.DatabaseSchemaAsync',
|
507
|
-
'
|
520
|
+
'rparam.DatabaseParametersVariablesAsync',
|
521
|
+
'rparam.DatabaseParametersStatusAsync',
|
522
|
+
'rparam.DatabaseParametersVariablesGlobalAsync',
|
523
|
+
'rparam.DatabaseParametersStatusGlobalAsync'
|
508
524
|
]
|
509
525
|
):
|
510
526
|
"""
|
reydb/rerror.py
CHANGED
@@ -53,7 +53,7 @@ class DatabaseError(DatabaseBase):
|
|
53
53
|
|
54
54
|
def build_db(self) -> None:
|
55
55
|
"""
|
56
|
-
Check and build
|
56
|
+
Check and build database tables, by `self.db_names`.
|
57
57
|
"""
|
58
58
|
|
59
59
|
# Set parameter.
|
@@ -223,7 +223,7 @@ class DatabaseError(DatabaseBase):
|
|
223
223
|
|
224
224
|
# Insert.
|
225
225
|
self.db.execute.insert(
|
226
|
-
|
226
|
+
self.db_names['base.error'],
|
227
227
|
data=data
|
228
228
|
)
|
229
229
|
|