reydb 1.1.57__py3-none-any.whl → 1.1.58__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/rbase.py +1 -0
- reydb/rbuild.py +1 -1
- reydb/rconfig.py +3 -2
- reydb/rconn.py +1 -1
- reydb/rdb.py +84 -113
- reydb/rerror.py +1 -1
- reydb/rexec.py +5 -5
- reydb/rfile.py +1 -1
- reydb/rinfo.py +4 -4
- reydb/rorm.py +4 -4
- reydb/rparam.py +164 -81
- {reydb-1.1.57.dist-info → reydb-1.1.58.dist-info}/METADATA +2 -1
- reydb-1.1.58.dist-info/RECORD +17 -0
- reydb-1.1.57.dist-info/RECORD +0 -17
- {reydb-1.1.57.dist-info → reydb-1.1.58.dist-info}/WHEEL +0 -0
- {reydb-1.1.57.dist-info → reydb-1.1.58.dist-info}/licenses/LICENSE +0 -0
reydb/rbase.py
CHANGED
@@ -39,6 +39,7 @@ TransactionT = TypeVar('TransactionT', Transaction, AsyncTransaction)
|
|
39
39
|
DatabaseT = TypeVar('DatabaseT')
|
40
40
|
DatabaseConnectionT = TypeVar('DatabaseConnectionT')
|
41
41
|
DatabaseExecuteT = TypeVar('DatabaseExecuteT')
|
42
|
+
DatabaseSchemaT = TypeVar('DatabaseSchemaT')
|
42
43
|
|
43
44
|
|
44
45
|
URLParameters = TypedDict(
|
reydb/rbuild.py
CHANGED
reydb/rconfig.py
CHANGED
@@ -20,6 +20,7 @@ from datetime import (
|
|
20
20
|
from reykit.rbase import Null, throw
|
21
21
|
|
22
22
|
from . import rdb
|
23
|
+
from .rbase import DatabaseBase
|
23
24
|
|
24
25
|
|
25
26
|
__all__ = (
|
@@ -33,7 +34,7 @@ type ConfigTable = list[ConfigRow]
|
|
33
34
|
ConfigValueT = TypeVar('T', bound=ConfigValue) # Any.
|
34
35
|
|
35
36
|
|
36
|
-
class DatabaseConfig(
|
37
|
+
class DatabaseConfig(DatabaseBase):
|
37
38
|
"""
|
38
39
|
Database config type.
|
39
40
|
Can create database used `self.build_db` method.
|
@@ -54,7 +55,7 @@ class DatabaseConfig(object):
|
|
54
55
|
|
55
56
|
Parameters
|
56
57
|
----------
|
57
|
-
db:
|
58
|
+
db: Database instance.
|
58
59
|
"""
|
59
60
|
|
60
61
|
# Build.
|
reydb/rconn.py
CHANGED
reydb/rdb.py
CHANGED
@@ -21,12 +21,20 @@ from . import rbase, rbuild, rconfig, rconn, rerror, rexec, rfile, rinfo, rorm,
|
|
21
21
|
|
22
22
|
__all__ = (
|
23
23
|
'DatabaseSuper',
|
24
|
-
'
|
25
|
-
'
|
24
|
+
'Database',
|
25
|
+
'DatabaseAsync'
|
26
26
|
)
|
27
27
|
|
28
28
|
|
29
|
-
class DatabaseSuper(
|
29
|
+
class DatabaseSuper(
|
30
|
+
rbase.DatabaseBase,
|
31
|
+
Generic[
|
32
|
+
rbase.EngineT,
|
33
|
+
rbase.DatabaseConnectionT,
|
34
|
+
rbase.DatabaseExecuteT,
|
35
|
+
rbase.DatabaseSchemaT
|
36
|
+
]
|
37
|
+
):
|
30
38
|
"""
|
31
39
|
Database super type, based `MySQL`.
|
32
40
|
"""
|
@@ -108,7 +116,6 @@ class DatabaseSuper(rbase.DatabaseBase, Generic[rbase.EngineT, rbase.DatabaseCon
|
|
108
116
|
if key not in filter_key
|
109
117
|
}
|
110
118
|
info['conn_count'] = self.conn_count
|
111
|
-
info['aconn_count'] = self.aconn_count
|
112
119
|
text = join_data_text(info)
|
113
120
|
|
114
121
|
return text
|
@@ -230,76 +237,6 @@ class DatabaseSuper(rbase.DatabaseBase, Generic[rbase.EngineT, rbase.DatabaseCon
|
|
230
237
|
return keep_n, overflow_n
|
231
238
|
|
232
239
|
|
233
|
-
def schema(self, filter_default: bool = True) -> dict[str, dict[str, list[str]]]:
|
234
|
-
"""
|
235
|
-
Get schemata of databases and tables and columns.
|
236
|
-
|
237
|
-
Parameters
|
238
|
-
----------
|
239
|
-
filter_default : Whether filter default database.
|
240
|
-
|
241
|
-
Returns
|
242
|
-
-------
|
243
|
-
Schemata of databases and tables and columns.
|
244
|
-
"""
|
245
|
-
|
246
|
-
# Handle parameter.
|
247
|
-
filter_db = (
|
248
|
-
'information_schema',
|
249
|
-
'performance_schema',
|
250
|
-
'mysql',
|
251
|
-
'sys'
|
252
|
-
)
|
253
|
-
if filter_default:
|
254
|
-
where_database = 'WHERE `SCHEMA_NAME` NOT IN :filter_db\n'
|
255
|
-
where_column = ' WHERE `TABLE_SCHEMA` NOT IN :filter_db\n'
|
256
|
-
else:
|
257
|
-
where_database = where_column = ''
|
258
|
-
|
259
|
-
# Select.
|
260
|
-
sql = (
|
261
|
-
'SELECT GROUP_CONCAT(`SCHEMA_NAME`) AS `TABLE_SCHEMA`, NULL AS `TABLE_NAME`, NULL AS `COLUMN_NAME`\n'
|
262
|
-
'FROM `information_schema`.`SCHEMATA`\n'
|
263
|
-
f'{where_database}'
|
264
|
-
'UNION ALL (\n'
|
265
|
-
' SELECT `TABLE_SCHEMA`, `TABLE_NAME`, `COLUMN_NAME`\n'
|
266
|
-
' FROM `information_schema`.`COLUMNS`\n'
|
267
|
-
f'{where_column}'
|
268
|
-
' ORDER BY `TABLE_SCHEMA`, `TABLE_NAME`, `ORDINAL_POSITION`\n'
|
269
|
-
')'
|
270
|
-
)
|
271
|
-
result = self.execute(sql, filter_db=filter_db)
|
272
|
-
|
273
|
-
# Convert.
|
274
|
-
database_names, *_ = result.fetchone()
|
275
|
-
database_names: list[str] = database_names.split(',')
|
276
|
-
schema_dict = {}
|
277
|
-
for database, table, column in result:
|
278
|
-
if database in database_names:
|
279
|
-
database_names.remove(database)
|
280
|
-
|
281
|
-
## Index database.
|
282
|
-
if database not in schema_dict:
|
283
|
-
schema_dict[database] = {table: [column]}
|
284
|
-
continue
|
285
|
-
table_dict: dict = schema_dict[database]
|
286
|
-
|
287
|
-
## Index table.
|
288
|
-
if table not in table_dict:
|
289
|
-
table_dict[table] = [column]
|
290
|
-
continue
|
291
|
-
column_list: list = table_dict[table]
|
292
|
-
|
293
|
-
## Add column.
|
294
|
-
column_list.append(column)
|
295
|
-
|
296
|
-
## Add empty database.
|
297
|
-
for name in database_names:
|
298
|
-
schema_dict[name] = None
|
299
|
-
|
300
|
-
return schema_dict
|
301
|
-
|
302
|
-
|
303
240
|
def connect(self, autocommit: bool = False) -> rbase.DatabaseConnectionT:
|
304
241
|
"""
|
305
242
|
Build database connection instance.
|
@@ -357,45 +294,41 @@ class DatabaseSuper(rbase.DatabaseBase, Generic[rbase.EngineT, rbase.DatabaseCon
|
|
357
294
|
|
358
295
|
|
359
296
|
@property
|
360
|
-
def
|
297
|
+
def build(self):
|
361
298
|
"""
|
362
|
-
Build database
|
299
|
+
Build database build instance.
|
363
300
|
|
364
301
|
Returns
|
365
302
|
-------
|
366
303
|
Instance.
|
304
|
+
"""
|
367
305
|
|
368
|
-
|
369
|
-
|
370
|
-
Get databases information of server.
|
371
|
-
>>> databases_info = DatabaseInformationSchema()
|
372
|
-
|
373
|
-
Get tables information of database.
|
374
|
-
>>> tables_info = DatabaseInformationSchema.database()
|
306
|
+
# Build.
|
307
|
+
dbbuild = rbuild.DatabaseBuild(self)
|
375
308
|
|
376
|
-
|
377
|
-
>>> columns_info = DatabaseInformationSchema.database.table()
|
309
|
+
return dbbuild
|
378
310
|
|
379
|
-
Get database attribute.
|
380
|
-
>>> database_attr = DatabaseInformationSchema.database['attribute']
|
381
311
|
|
382
|
-
|
383
|
-
|
312
|
+
@property
|
313
|
+
def file(self):
|
314
|
+
"""
|
315
|
+
Build database file instance.
|
384
316
|
|
385
|
-
|
386
|
-
|
317
|
+
Returns
|
318
|
+
-------
|
319
|
+
Instance.
|
387
320
|
"""
|
388
321
|
|
389
322
|
# Build.
|
390
|
-
|
323
|
+
dbfile = rfile.DatabaseFile(self)
|
391
324
|
|
392
|
-
return
|
325
|
+
return dbfile
|
393
326
|
|
394
327
|
|
395
328
|
@property
|
396
|
-
def
|
329
|
+
def error(self):
|
397
330
|
"""
|
398
|
-
Build database
|
331
|
+
Build database error instance.
|
399
332
|
|
400
333
|
Returns
|
401
334
|
-------
|
@@ -403,15 +336,15 @@ class DatabaseSuper(rbase.DatabaseBase, Generic[rbase.EngineT, rbase.DatabaseCon
|
|
403
336
|
"""
|
404
337
|
|
405
338
|
# Build.
|
406
|
-
|
339
|
+
dbfile = rerror.DatabaseError(self)
|
407
340
|
|
408
|
-
return
|
341
|
+
return dbfile
|
409
342
|
|
410
343
|
|
411
344
|
@property
|
412
|
-
def
|
345
|
+
def config(self):
|
413
346
|
"""
|
414
|
-
Build database
|
347
|
+
Build database config instance.
|
415
348
|
|
416
349
|
Returns
|
417
350
|
-------
|
@@ -419,31 +352,51 @@ class DatabaseSuper(rbase.DatabaseBase, Generic[rbase.EngineT, rbase.DatabaseCon
|
|
419
352
|
"""
|
420
353
|
|
421
354
|
# Build.
|
422
|
-
|
355
|
+
dbconfig = rconfig.DatabaseConfig(self)
|
423
356
|
|
424
|
-
return
|
357
|
+
return dbconfig
|
425
358
|
|
426
359
|
|
427
360
|
@property
|
428
|
-
def
|
361
|
+
def info(self):
|
429
362
|
"""
|
430
|
-
Build database
|
363
|
+
Build database information schema instance.
|
431
364
|
|
432
365
|
Returns
|
433
366
|
-------
|
434
367
|
Instance.
|
368
|
+
|
369
|
+
Examples
|
370
|
+
--------
|
371
|
+
Get databases information of server.
|
372
|
+
>>> databases_info = DatabaseInformationSchema()
|
373
|
+
|
374
|
+
Get tables information of database.
|
375
|
+
>>> tables_info = DatabaseInformationSchema.database()
|
376
|
+
|
377
|
+
Get columns information of table.
|
378
|
+
>>> columns_info = DatabaseInformationSchema.database.table()
|
379
|
+
|
380
|
+
Get database attribute.
|
381
|
+
>>> database_attr = DatabaseInformationSchema.database['attribute']
|
382
|
+
|
383
|
+
Get table attribute.
|
384
|
+
>>> database_attr = DatabaseInformationSchema.database.table['attribute']
|
385
|
+
|
386
|
+
Get column attribute.
|
387
|
+
>>> database_attr = DatabaseInformationSchema.database.table.column['attribute']
|
435
388
|
"""
|
436
389
|
|
437
390
|
# Build.
|
438
|
-
|
391
|
+
dbischema = rinfo.DatabaseInformationSchema(self)
|
439
392
|
|
440
|
-
return
|
393
|
+
return dbischema
|
441
394
|
|
442
395
|
|
443
396
|
@property
|
444
|
-
def
|
397
|
+
def schema(self) -> rbase.DatabaseSchemaT:
|
445
398
|
"""
|
446
|
-
Build database
|
399
|
+
Build database schema instance.
|
447
400
|
|
448
401
|
Returns
|
449
402
|
-------
|
@@ -451,9 +404,13 @@ class DatabaseSuper(rbase.DatabaseBase, Generic[rbase.EngineT, rbase.DatabaseCon
|
|
451
404
|
"""
|
452
405
|
|
453
406
|
# Build.
|
454
|
-
|
407
|
+
match self:
|
408
|
+
case Database():
|
409
|
+
schema = rparam.DatabaseSchema(self)
|
410
|
+
case DatabaseAsync():
|
411
|
+
schema = rparam.DatabaseSchemaAsync(self)
|
455
412
|
|
456
|
-
return
|
413
|
+
return schema
|
457
414
|
|
458
415
|
|
459
416
|
@property
|
@@ -473,7 +430,7 @@ class DatabaseSuper(rbase.DatabaseBase, Generic[rbase.EngineT, rbase.DatabaseCon
|
|
473
430
|
|
474
431
|
|
475
432
|
@property
|
476
|
-
def
|
433
|
+
def status_global(self):
|
477
434
|
"""
|
478
435
|
Build global database parameters status instance.
|
479
436
|
|
@@ -505,7 +462,7 @@ class DatabaseSuper(rbase.DatabaseBase, Generic[rbase.EngineT, rbase.DatabaseCon
|
|
505
462
|
|
506
463
|
|
507
464
|
@property
|
508
|
-
def
|
465
|
+
def variables_global(self):
|
509
466
|
"""
|
510
467
|
Build global database parameters variable instance.
|
511
468
|
|
@@ -522,13 +479,27 @@ class DatabaseSuper(rbase.DatabaseBase, Generic[rbase.EngineT, rbase.DatabaseCon
|
|
522
479
|
return dbpv
|
523
480
|
|
524
481
|
|
525
|
-
class Database(
|
482
|
+
class Database(
|
483
|
+
DatabaseSuper[
|
484
|
+
Engine,
|
485
|
+
'rconn.DatabaseConnection',
|
486
|
+
'rexec.DatabaseExecute',
|
487
|
+
'rparam.DatabaseSchema'
|
488
|
+
]
|
489
|
+
):
|
526
490
|
"""
|
527
491
|
Database type, based `MySQL`.
|
528
492
|
"""
|
529
493
|
|
530
494
|
|
531
|
-
class DatabaseAsync(
|
495
|
+
class DatabaseAsync(
|
496
|
+
DatabaseSuper[
|
497
|
+
AsyncEngine,
|
498
|
+
'rconn.DatabaseConnectionAsync',
|
499
|
+
'rexec.DatabaseExecuteAsync',
|
500
|
+
'rparam.DatabaseSchemaAsync'
|
501
|
+
]
|
502
|
+
):
|
532
503
|
"""
|
533
504
|
Asynchronous database type, based `MySQL`.
|
534
505
|
"""
|
reydb/rerror.py
CHANGED
reydb/rexec.py
CHANGED
@@ -83,7 +83,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
83
83
|
|
84
84
|
Returns
|
85
85
|
-------
|
86
|
-
|
86
|
+
Parameter `sql` and `data` and `report`.
|
87
87
|
"""
|
88
88
|
|
89
89
|
# Handle parameter.
|
@@ -136,7 +136,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
136
136
|
|
137
137
|
Returns
|
138
138
|
-------
|
139
|
-
|
139
|
+
Parameter `sql`.
|
140
140
|
"""
|
141
141
|
|
142
142
|
# Generate SQL.
|
@@ -226,7 +226,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
226
226
|
|
227
227
|
Returns
|
228
228
|
-------
|
229
|
-
|
229
|
+
Parameter `sql` and `kwdata`.
|
230
230
|
"""
|
231
231
|
|
232
232
|
# Handle parameter.
|
@@ -363,7 +363,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
363
363
|
|
364
364
|
Returns
|
365
365
|
-------
|
366
|
-
|
366
|
+
Parameter `sql` and `data`.
|
367
367
|
"""
|
368
368
|
|
369
369
|
# Handle parameter.
|
@@ -547,7 +547,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
547
547
|
|
548
548
|
Returns
|
549
549
|
-------
|
550
|
-
|
550
|
+
Parameter `sql`.
|
551
551
|
"""
|
552
552
|
|
553
553
|
# Handle parameter.
|
reydb/rfile.py
CHANGED
reydb/rinfo.py
CHANGED
@@ -197,7 +197,7 @@ class DatabaseInformationSchema(DatabaseInformation):
|
|
197
197
|
|
198
198
|
Parameters
|
199
199
|
----------
|
200
|
-
db:
|
200
|
+
db: Database instance.
|
201
201
|
"""
|
202
202
|
|
203
203
|
# Set parameter.
|
@@ -261,7 +261,7 @@ class DatabaseInformationDatabase(DatabaseInformation):
|
|
261
261
|
|
262
262
|
Parameters
|
263
263
|
----------
|
264
|
-
db:
|
264
|
+
db: Database instance.
|
265
265
|
database : Database name.
|
266
266
|
"""
|
267
267
|
|
@@ -357,7 +357,7 @@ class DatabaseInformationTable(DatabaseInformation):
|
|
357
357
|
|
358
358
|
Parameters
|
359
359
|
----------
|
360
|
-
db:
|
360
|
+
db: Database instance.
|
361
361
|
database : Database name.
|
362
362
|
table : Table name.
|
363
363
|
"""
|
@@ -452,7 +452,7 @@ class DatabaseInformationColumn(DatabaseInformation):
|
|
452
452
|
|
453
453
|
Parameters
|
454
454
|
----------
|
455
|
-
db:
|
455
|
+
db: Database instance.
|
456
456
|
database : Database name.
|
457
457
|
table : Table name.
|
458
458
|
column : Column name.
|
reydb/rorm.py
CHANGED
@@ -375,7 +375,7 @@ class DatabaseORM(DatabaseORMBase):
|
|
375
375
|
|
376
376
|
Parameters
|
377
377
|
----------
|
378
|
-
db:
|
378
|
+
db: Database instance.
|
379
379
|
"""
|
380
380
|
|
381
381
|
# Build.
|
@@ -391,7 +391,7 @@ class DatabaseORM(DatabaseORMBase):
|
|
391
391
|
|
392
392
|
def session(self, autocommit: bool = False):
|
393
393
|
"""
|
394
|
-
Build
|
394
|
+
Build DataBase ORM session instance.
|
395
395
|
|
396
396
|
Parameters
|
397
397
|
----------
|
@@ -472,7 +472,7 @@ class DatabaseORMSession(DatabaseORMBase):
|
|
472
472
|
|
473
473
|
Parameters
|
474
474
|
----------
|
475
|
-
orm :
|
475
|
+
orm : Database ORM instance.
|
476
476
|
autocommit: Whether automatic commit execute.
|
477
477
|
"""
|
478
478
|
|
@@ -897,7 +897,7 @@ class DatabaseORMStatement(DatabaseORMBase):
|
|
897
897
|
|
898
898
|
Parameters
|
899
899
|
----------
|
900
|
-
sess :
|
900
|
+
sess : DataBase ORM session instance.
|
901
901
|
model : ORM model instance.
|
902
902
|
"""
|
903
903
|
|
reydb/rparam.py
CHANGED
@@ -9,20 +9,179 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import overload
|
12
|
+
from typing import Generic, overload
|
13
13
|
|
14
14
|
from . import rdb
|
15
|
-
from .rbase import DatabaseBase
|
15
|
+
from .rbase import DatabaseT, DatabaseBase
|
16
|
+
from .rexec import Result
|
16
17
|
|
17
18
|
|
18
19
|
__all__ = (
|
20
|
+
'DatabaseSchema',
|
19
21
|
'DatabaseParameters',
|
20
22
|
'DatabaseParametersStatus',
|
21
|
-
'DatabaseParametersVariable'
|
22
|
-
'DatabaseParametersPragma'
|
23
|
+
'DatabaseParametersVariable'
|
23
24
|
)
|
24
25
|
|
25
26
|
|
27
|
+
class DatabaseSchemaSuper(DatabaseBase, Generic[DatabaseT]):
|
28
|
+
"""
|
29
|
+
Database schema super type.
|
30
|
+
"""
|
31
|
+
|
32
|
+
|
33
|
+
def __init__(self, db: DatabaseT) -> None:
|
34
|
+
"""
|
35
|
+
Build instance attributes.
|
36
|
+
|
37
|
+
Parameters
|
38
|
+
----------
|
39
|
+
db: Database instance.
|
40
|
+
"""
|
41
|
+
|
42
|
+
# Set parameter.
|
43
|
+
self.db = db
|
44
|
+
|
45
|
+
|
46
|
+
def _call__before(self, filter_default: bool = True) -> tuple[str, tuple[str, ...]]:
|
47
|
+
"""
|
48
|
+
Before handle of call method.
|
49
|
+
|
50
|
+
Parameters
|
51
|
+
----------
|
52
|
+
filter_default : Whether filter default database.
|
53
|
+
|
54
|
+
Returns
|
55
|
+
-------
|
56
|
+
Parameter `sql` and `filter_db`.
|
57
|
+
"""
|
58
|
+
|
59
|
+
# Handle parameter.
|
60
|
+
filter_db = (
|
61
|
+
'information_schema',
|
62
|
+
'performance_schema',
|
63
|
+
'mysql',
|
64
|
+
'sys'
|
65
|
+
)
|
66
|
+
if filter_default:
|
67
|
+
where_database = 'WHERE `SCHEMA_NAME` NOT IN :filter_db\n'
|
68
|
+
where_column = ' WHERE `TABLE_SCHEMA` NOT IN :filter_db\n'
|
69
|
+
else:
|
70
|
+
where_database = where_column = ''
|
71
|
+
|
72
|
+
# Select.
|
73
|
+
sql = (
|
74
|
+
'SELECT GROUP_CONCAT(`SCHEMA_NAME`) AS `TABLE_SCHEMA`, NULL AS `TABLE_NAME`, NULL AS `COLUMN_NAME`\n'
|
75
|
+
'FROM `information_schema`.`SCHEMATA`\n'
|
76
|
+
f'{where_database}'
|
77
|
+
'UNION ALL (\n'
|
78
|
+
' SELECT `TABLE_SCHEMA`, `TABLE_NAME`, `COLUMN_NAME`\n'
|
79
|
+
' FROM `information_schema`.`COLUMNS`\n'
|
80
|
+
f'{where_column}'
|
81
|
+
' ORDER BY `TABLE_SCHEMA`, `TABLE_NAME`, `ORDINAL_POSITION`\n'
|
82
|
+
')'
|
83
|
+
)
|
84
|
+
|
85
|
+
return sql, filter_db
|
86
|
+
|
87
|
+
|
88
|
+
def _call__after(self, result: Result) -> dict[str, dict[str, list[str]]]:
|
89
|
+
"""
|
90
|
+
After handle of call method.
|
91
|
+
|
92
|
+
Parameters
|
93
|
+
----------
|
94
|
+
result : Database select result.
|
95
|
+
|
96
|
+
Returns
|
97
|
+
-------
|
98
|
+
Parameter `schema_dict`.
|
99
|
+
"""
|
100
|
+
|
101
|
+
# Convert.
|
102
|
+
database_names, *_ = result.fetchone()
|
103
|
+
database_names: list[str] = database_names.split(',')
|
104
|
+
schema_dict = {}
|
105
|
+
for database, table, column in result:
|
106
|
+
if database in database_names:
|
107
|
+
database_names.remove(database)
|
108
|
+
|
109
|
+
## Index database.
|
110
|
+
if database not in schema_dict:
|
111
|
+
schema_dict[database] = {table: [column]}
|
112
|
+
continue
|
113
|
+
table_dict: dict = schema_dict[database]
|
114
|
+
|
115
|
+
## Index table.
|
116
|
+
if table not in table_dict:
|
117
|
+
table_dict[table] = [column]
|
118
|
+
continue
|
119
|
+
column_list: list = table_dict[table]
|
120
|
+
|
121
|
+
## Add column.
|
122
|
+
column_list.append(column)
|
123
|
+
|
124
|
+
## Add empty database.
|
125
|
+
for name in database_names:
|
126
|
+
schema_dict[name] = None
|
127
|
+
|
128
|
+
return schema_dict
|
129
|
+
|
130
|
+
|
131
|
+
class DatabaseSchema(DatabaseSchemaSuper['rdb.Database']):
|
132
|
+
"""
|
133
|
+
Database schema type.
|
134
|
+
"""
|
135
|
+
|
136
|
+
|
137
|
+
def __call__(self, filter_default: bool = True) -> dict[str, dict[str, list[str]]]:
|
138
|
+
"""
|
139
|
+
Get schemata of databases and tables and columns.
|
140
|
+
|
141
|
+
Parameters
|
142
|
+
----------
|
143
|
+
filter_default : Whether filter default database.
|
144
|
+
|
145
|
+
Returns
|
146
|
+
-------
|
147
|
+
Schemata of databases and tables and columns.
|
148
|
+
"""
|
149
|
+
|
150
|
+
# Get.
|
151
|
+
sql, filter_db = self._call__before(filter_default)
|
152
|
+
result = self.db.execute(sql, filter_db=filter_db)
|
153
|
+
schema_dict = self._call__after(result)
|
154
|
+
|
155
|
+
return schema_dict
|
156
|
+
|
157
|
+
|
158
|
+
class DatabaseSchemaAsync(DatabaseSchemaSuper['rdb.DatabaseAsync']):
|
159
|
+
"""
|
160
|
+
Asynchronous database schema type.
|
161
|
+
"""
|
162
|
+
|
163
|
+
|
164
|
+
async def __call__(self, filter_default: bool = True) -> dict[str, dict[str, list[str]]]:
|
165
|
+
"""
|
166
|
+
Asynchronous get schemata of databases and tables and columns.
|
167
|
+
|
168
|
+
Parameters
|
169
|
+
----------
|
170
|
+
filter_default : Whether filter default database.
|
171
|
+
|
172
|
+
Returns
|
173
|
+
-------
|
174
|
+
Schemata of databases and tables and columns.
|
175
|
+
"""
|
176
|
+
|
177
|
+
# Get.
|
178
|
+
sql, filter_db = self._call__before(filter_default)
|
179
|
+
result = await self.db.execute(sql, filter_db=filter_db)
|
180
|
+
schema_dict = self._call__after(result)
|
181
|
+
|
182
|
+
return schema_dict
|
183
|
+
|
184
|
+
|
26
185
|
class DatabaseParameters(DatabaseBase):
|
27
186
|
"""
|
28
187
|
Database parameters type.
|
@@ -39,7 +198,7 @@ class DatabaseParameters(DatabaseBase):
|
|
39
198
|
|
40
199
|
Parameters
|
41
200
|
----------
|
42
|
-
db:
|
201
|
+
db: Database instance.
|
43
202
|
global\\_ : Whether base global.
|
44
203
|
"""
|
45
204
|
|
@@ -244,79 +403,3 @@ class DatabaseParametersVariable(DatabaseParameters):
|
|
244
403
|
|
245
404
|
# Execute SQL.
|
246
405
|
self.db.execute(sql)
|
247
|
-
|
248
|
-
|
249
|
-
class DatabaseParametersPragma(DatabaseParameters):
|
250
|
-
"""
|
251
|
-
Database parameters pragma type.
|
252
|
-
"""
|
253
|
-
|
254
|
-
|
255
|
-
def __init__(
|
256
|
-
self,
|
257
|
-
db: 'rdb.Database'
|
258
|
-
) -> None:
|
259
|
-
"""
|
260
|
-
Build instance attributes.
|
261
|
-
|
262
|
-
Parameters
|
263
|
-
----------
|
264
|
-
db: `Database` instance.
|
265
|
-
"""
|
266
|
-
|
267
|
-
# Set parameter.
|
268
|
-
self.db = db
|
269
|
-
|
270
|
-
|
271
|
-
def get(self, key: str) -> str | None:
|
272
|
-
"""
|
273
|
-
Get parameter.
|
274
|
-
|
275
|
-
Parameters
|
276
|
-
----------
|
277
|
-
key : Parameter key.
|
278
|
-
|
279
|
-
Returns
|
280
|
-
-------
|
281
|
-
Variables of database.
|
282
|
-
"""
|
283
|
-
|
284
|
-
# Generate SQL.
|
285
|
-
sql = f'PRAGMA %s' % key
|
286
|
-
|
287
|
-
# Execute SQL.
|
288
|
-
result = self.db.execute(sql)
|
289
|
-
row = result.first()
|
290
|
-
if row is None:
|
291
|
-
variables = None
|
292
|
-
else:
|
293
|
-
variables = row[0]
|
294
|
-
|
295
|
-
return variables
|
296
|
-
|
297
|
-
|
298
|
-
def update(self, params: dict[str, str | float]) -> None:
|
299
|
-
"""
|
300
|
-
Update parameter.
|
301
|
-
|
302
|
-
Parameters
|
303
|
-
----------
|
304
|
-
params : Update parameter key value pairs.
|
305
|
-
"""
|
306
|
-
|
307
|
-
# Generate SQL.
|
308
|
-
sql_set_list = [
|
309
|
-
'PRAGMA %s = %s' % (
|
310
|
-
key,
|
311
|
-
(
|
312
|
-
value
|
313
|
-
if type(value) in (int, float)
|
314
|
-
else "'%s'" % value
|
315
|
-
)
|
316
|
-
)
|
317
|
-
for key, value in params.items()
|
318
|
-
]
|
319
|
-
sql = ';\n'.join(sql_set_list)
|
320
|
-
|
321
|
-
# Execute SQL.
|
322
|
-
self.db.execute(sql)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: reydb
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.58
|
4
4
|
Summary: Database method set.
|
5
5
|
Project-URL: homepage, https://github.com/reyxbo/reydb/
|
6
6
|
Author-email: Rey <reyxbo@163.com>
|
@@ -14,6 +14,7 @@ License: Copyright 2025 ReyXBo
|
|
14
14
|
License-File: LICENSE
|
15
15
|
Keywords: database,db,rey,reyxbo
|
16
16
|
Requires-Python: >=3.12
|
17
|
+
Requires-Dist: aiomysql
|
17
18
|
Requires-Dist: pydantic
|
18
19
|
Requires-Dist: pymysql
|
19
20
|
Requires-Dist: reykit
|
@@ -0,0 +1,17 @@
|
|
1
|
+
reydb/__init__.py,sha256=h6duExQWsPCz3qKnTIHTslmqcBC63HCQvwiumg8oCVc,620
|
2
|
+
reydb/rall.py,sha256=GsXHqvT1k--U53HpDY4SALjIHN8rwgSxeXpJjH5gq2E,409
|
3
|
+
reydb/rbase.py,sha256=n1e7olB_9FCOzrBIDm-jwTVtoUR935sYTQ9FpuxSXGE,9390
|
4
|
+
reydb/rbuild.py,sha256=agCVP5MehdAkNGevOdioZgagFZyNxAjMHuKn7jIxTCg,31848
|
5
|
+
reydb/rconfig.py,sha256=4-SRhwhd3GqGiRhwbAjCfxVz6tBOQ2ab6n_lrb35rUE,12694
|
6
|
+
reydb/rconn.py,sha256=SWiKB9XZ4o5RT6M6L2vwp5bGYaZfrhGBSjfBOvwoq74,6513
|
7
|
+
reydb/rdb.py,sha256=pShuWWxsliXS1QZNZaxvrArtO0RIp0kwQ6Xwl9eWBVo,11502
|
8
|
+
reydb/rerror.py,sha256=f713YXSwWgls5352KvvX9LiTT_PcsPjZcSjZnFbFbVo,9939
|
9
|
+
reydb/rexec.py,sha256=o-VnFDprMeaQlQIX5_cHXHHchR5hRHWeJuFIqhVjBQ0,52835
|
10
|
+
reydb/rfile.py,sha256=N-uJRT2PFDNv1gKyHAb9t8n8xPOdic3SpzML-C0Bi-0,15180
|
11
|
+
reydb/rinfo.py,sha256=qW9QoGuMaMO2Fr76FCETE0TES_4CscagAceZtXc2qsU,12749
|
12
|
+
reydb/rorm.py,sha256=Jvv2D2bGFle-P34j00er2hwrrSChfDvsCvdQNpkSRPQ,23691
|
13
|
+
reydb/rparam.py,sha256=2S3uuZ42ieGbc-0W202h6aM-chDMbp4qr-AWzOtk7vk,9629
|
14
|
+
reydb-1.1.58.dist-info/METADATA,sha256=ItDedY0Q2A3dIPqyv9Bcs7DojtgQxBgZi_3JuBvObP8,1622
|
15
|
+
reydb-1.1.58.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
reydb-1.1.58.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
+
reydb-1.1.58.dist-info/RECORD,,
|
reydb-1.1.57.dist-info/RECORD
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
reydb/__init__.py,sha256=h6duExQWsPCz3qKnTIHTslmqcBC63HCQvwiumg8oCVc,620
|
2
|
-
reydb/rall.py,sha256=GsXHqvT1k--U53HpDY4SALjIHN8rwgSxeXpJjH5gq2E,409
|
3
|
-
reydb/rbase.py,sha256=oMxftAVOPrX-8EcIzBUpTZ2aVbMJzxBkMlgjJN1Ilv0,9344
|
4
|
-
reydb/rbuild.py,sha256=6K6u8GKECiYakvJ0mmQJduwN4oDLnBS6S0A1AG5A4fA,31850
|
5
|
-
reydb/rconfig.py,sha256=OGVv6JT3_hN1nxI4B0oxC8281_vMQxjQbLjxGEDP5LE,12657
|
6
|
-
reydb/rconn.py,sha256=N9KzvhG_1b_e0vXSfifFV2Yq2Tf2QFAsHQcCOZglGlI,6534
|
7
|
-
reydb/rdb.py,sha256=cxacqHUegl_30NQRXSCMtqFrUCACye-Nt_pteU4Mw3Y,13187
|
8
|
-
reydb/rerror.py,sha256=5n0poj6uLpKwmvlXVvfsFMqJ9NuVJ1HshoJgC8yQxLs,9941
|
9
|
-
reydb/rexec.py,sha256=-Oo1qnK4gjWlGqvYz8zYyack1QySGQZcv5SApVp-EQU,52840
|
10
|
-
reydb/rfile.py,sha256=VcjQtsH-xQbWFkk0gpJ8s66jYxwAfiAJkHJ-V-5jQIw,15182
|
11
|
-
reydb/rinfo.py,sha256=jvFzK-zO2PP1ph7lo12tsvkP8cshoRe4rPdq0DiU44g,12757
|
12
|
-
reydb/rorm.py,sha256=NiJoub0Ixm2TVCTajq6ktM3Oj5VQ2WBfoyn-QBGO6OQ,23694
|
13
|
-
reydb/rparam.py,sha256=XqVQa_026dtpwuGDgJIm9Rtgd2pB34h3TL8cFKmf3uw,6807
|
14
|
-
reydb-1.1.57.dist-info/METADATA,sha256=-rJlF25mWNFLY3I6njiz9YMEr0w6jLG5jRmW4Dp_9SY,1598
|
15
|
-
reydb-1.1.57.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
-
reydb-1.1.57.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
-
reydb-1.1.57.dist-info/RECORD,,
|
File without changes
|
File without changes
|