reydb 1.2.19__py3-none-any.whl → 1.2.21__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 +3 -1
- reydb/rall.py +2 -1
- reydb/rbase.py +1 -1
- reydb/rbuild.py +51 -51
- reydb/rconfig.py +29 -29
- reydb/rconn.py +15 -15
- reydb/rdb.py +60 -519
- reydb/rengine.py +596 -0
- reydb/rerror.py +14 -14
- reydb/rexec.py +8 -8
- reydb/rinfo.py +32 -32
- reydb/rorm.py +17 -17
- {reydb-1.2.19.dist-info → reydb-1.2.21.dist-info}/METADATA +1 -1
- reydb-1.2.21.dist-info/RECORD +16 -0
- reydb-1.2.19.dist-info/RECORD +0 -15
- {reydb-1.2.19.dist-info → reydb-1.2.21.dist-info}/WHEEL +0 -0
- {reydb-1.2.19.dist-info → reydb-1.2.21.dist-info}/licenses/LICENSE +0 -0
reydb/rconfig.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
4
|
"""
|
5
|
-
@Time : 2025-08-22
|
5
|
+
@Time : 2025-08-22
|
6
6
|
@Author : Rey
|
7
7
|
@Contact : reyxbo@163.com
|
8
8
|
@Explain : Database config methods.
|
@@ -18,7 +18,7 @@ from datetime import (
|
|
18
18
|
)
|
19
19
|
from reykit.rbase import Null, throw
|
20
20
|
|
21
|
-
from . import
|
21
|
+
from . import rengine
|
22
22
|
from . import rorm
|
23
23
|
from .rbase import DatabaseBase
|
24
24
|
|
@@ -35,7 +35,7 @@ type ConfigValue = bool | str | int | float | list | tuple | dict | set | Dateti
|
|
35
35
|
ConfigRow = TypedDict('ConfigRow', {'key': str, 'value': ConfigValue, 'note': str | None})
|
36
36
|
type ConfigTable = list[ConfigRow]
|
37
37
|
ConfigValueT = TypeVar('T', bound=ConfigValue) # Any.
|
38
|
-
|
38
|
+
DatabaseEngineT = TypeVar('DatabaseEngineT', 'rengine.DatabaseEngine', 'rengine.DatabaseEngineAsync')
|
39
39
|
|
40
40
|
|
41
41
|
class DatabaseORMTableConfig(rorm.Model, table=True):
|
@@ -53,7 +53,7 @@ class DatabaseORMTableConfig(rorm.Model, table=True):
|
|
53
53
|
note: str = rorm.Field(rorm.types.VARCHAR(500), comment='Config note.')
|
54
54
|
|
55
55
|
|
56
|
-
class DatabaseConfigSuper(DatabaseBase, Generic[
|
56
|
+
class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseEngineT]):
|
57
57
|
"""
|
58
58
|
Database config super type.
|
59
59
|
Can create database used `self.build_db` method.
|
@@ -62,24 +62,24 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
|
|
62
62
|
_checked: bool = False
|
63
63
|
|
64
64
|
|
65
|
-
def __init__(self,
|
65
|
+
def __init__(self, engine: DatabaseEngineT) -> None:
|
66
66
|
"""
|
67
67
|
Build instance attributes.
|
68
68
|
|
69
69
|
Parameters
|
70
70
|
----------
|
71
|
-
|
71
|
+
engine: Database engine.
|
72
72
|
"""
|
73
73
|
|
74
74
|
# Build.
|
75
|
-
self.
|
75
|
+
self.engine = engine
|
76
76
|
|
77
77
|
# Build Database.
|
78
78
|
if not self._checked:
|
79
79
|
if type(self) == DatabaseConfig:
|
80
80
|
self.build_db()
|
81
81
|
elif type(self) == DatabaseConfigAsync:
|
82
|
-
|
82
|
+
engine.sync_engine.config.build_db()
|
83
83
|
self._checked = True
|
84
84
|
|
85
85
|
|
@@ -93,7 +93,7 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
|
|
93
93
|
"""
|
94
94
|
|
95
95
|
# Parameter.
|
96
|
-
database = self.
|
96
|
+
database = self.engine.database
|
97
97
|
|
98
98
|
## Table.
|
99
99
|
tables = [DatabaseORMTableConfig]
|
@@ -134,7 +134,7 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
|
|
134
134
|
return tables, views_stats
|
135
135
|
|
136
136
|
|
137
|
-
class DatabaseConfig(DatabaseConfigSuper['
|
137
|
+
class DatabaseConfig(DatabaseConfigSuper['rengine.DatabaseEngine']):
|
138
138
|
"""
|
139
139
|
Database config type.
|
140
140
|
Can create database used `self.build_db` method.
|
@@ -158,7 +158,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
158
158
|
tables, views_stats = self.handle_build_db()
|
159
159
|
|
160
160
|
# Build.
|
161
|
-
self.
|
161
|
+
self.engine.build.build(tables=tables, views_stats=views_stats, skip=True)
|
162
162
|
|
163
163
|
|
164
164
|
def data(self) -> ConfigTable:
|
@@ -171,7 +171,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
171
171
|
"""
|
172
172
|
|
173
173
|
# Get.
|
174
|
-
result = self.
|
174
|
+
result = self.engine.execute.select(
|
175
175
|
'config',
|
176
176
|
['key', 'value', 'note'],
|
177
177
|
order='IFNULL(`update_time`, `create_time`) DESC'
|
@@ -207,7 +207,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
207
207
|
|
208
208
|
# Get.
|
209
209
|
where = '`key` = :key'
|
210
|
-
result = self.
|
210
|
+
result = self.engine.execute.select(
|
211
211
|
'config',
|
212
212
|
'`value`',
|
213
213
|
where,
|
@@ -253,7 +253,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
253
253
|
'type': type(default).__name__,
|
254
254
|
'note': note
|
255
255
|
}
|
256
|
-
result = self.
|
256
|
+
result = self.engine.execute.insert(
|
257
257
|
'config',
|
258
258
|
data,
|
259
259
|
'ignore'
|
@@ -286,7 +286,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
286
286
|
row['type'] = type(row['value']).__name__
|
287
287
|
|
288
288
|
# Update.
|
289
|
-
self.
|
289
|
+
self.engine.execute.insert(
|
290
290
|
'config',
|
291
291
|
data,
|
292
292
|
'update'
|
@@ -309,7 +309,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
309
309
|
else:
|
310
310
|
where = '`key` in :key'
|
311
311
|
limit = None
|
312
|
-
result = self.
|
312
|
+
result = self.engine.execute.delete(
|
313
313
|
'config',
|
314
314
|
where,
|
315
315
|
limit=limit,
|
@@ -331,7 +331,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
331
331
|
"""
|
332
332
|
|
333
333
|
# Get.
|
334
|
-
result = self.
|
334
|
+
result = self.engine.execute.select(
|
335
335
|
'config',
|
336
336
|
['key', 'value']
|
337
337
|
)
|
@@ -357,7 +357,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
357
357
|
"""
|
358
358
|
|
359
359
|
# Get.
|
360
|
-
result = self.
|
360
|
+
result = self.engine.execute.select(
|
361
361
|
'config',
|
362
362
|
'`key`'
|
363
363
|
)
|
@@ -382,7 +382,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
382
382
|
"""
|
383
383
|
|
384
384
|
# Get.
|
385
|
-
result = self.
|
385
|
+
result = self.engine.execute.select(
|
386
386
|
'config',
|
387
387
|
'`value`'
|
388
388
|
)
|
@@ -450,7 +450,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
450
450
|
self.update(data)
|
451
451
|
|
452
452
|
|
453
|
-
class DatabaseConfigAsync(DatabaseConfigSuper['
|
453
|
+
class DatabaseConfigAsync(DatabaseConfigSuper['rengine.DatabaseEngineAsync']):
|
454
454
|
"""
|
455
455
|
Asynchronous database config type.
|
456
456
|
Can create database used `self.build_db` method.
|
@@ -474,7 +474,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
474
474
|
tables, views_stats = self.handle_build_db()
|
475
475
|
|
476
476
|
# Build.
|
477
|
-
await self.
|
477
|
+
await self.engine.build.build(tables=tables, views_stats=views_stats, skip=True)
|
478
478
|
|
479
479
|
|
480
480
|
async def data(self) -> ConfigTable:
|
@@ -487,7 +487,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
487
487
|
"""
|
488
488
|
|
489
489
|
# Get.
|
490
|
-
result = await self.
|
490
|
+
result = await self.engine.execute.select(
|
491
491
|
'config',
|
492
492
|
['key', 'value', 'note'],
|
493
493
|
order='IFNULL(`update_time`, `create_time`) DESC'
|
@@ -523,7 +523,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
523
523
|
|
524
524
|
# Get.
|
525
525
|
where = '`key` = :key'
|
526
|
-
result = await self.
|
526
|
+
result = await self.engine.execute.select(
|
527
527
|
'config',
|
528
528
|
'`value`',
|
529
529
|
where,
|
@@ -569,7 +569,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
569
569
|
'type': type(default).__name__,
|
570
570
|
'note': note
|
571
571
|
}
|
572
|
-
result = await self.
|
572
|
+
result = await self.engine.execute.insert(
|
573
573
|
'config',
|
574
574
|
data,
|
575
575
|
'ignore'
|
@@ -602,7 +602,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
602
602
|
row['type'] = type(row['value']).__name__
|
603
603
|
|
604
604
|
# Update.
|
605
|
-
await self.
|
605
|
+
await self.engine.execute.insert(
|
606
606
|
'config',
|
607
607
|
data,
|
608
608
|
'update'
|
@@ -625,7 +625,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
625
625
|
else:
|
626
626
|
where = '`key` in :key'
|
627
627
|
limit = None
|
628
|
-
result = await self.
|
628
|
+
result = await self.engine.execute.delete(
|
629
629
|
'config',
|
630
630
|
where,
|
631
631
|
limit=limit,
|
@@ -647,7 +647,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
647
647
|
"""
|
648
648
|
|
649
649
|
# Get.
|
650
|
-
result = await self.
|
650
|
+
result = await self.engine.execute.select(
|
651
651
|
'config',
|
652
652
|
['key', 'value']
|
653
653
|
)
|
@@ -673,7 +673,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
673
673
|
"""
|
674
674
|
|
675
675
|
# Get.
|
676
|
-
result = await self.
|
676
|
+
result = await self.engine.execute.select(
|
677
677
|
'config',
|
678
678
|
'`key`'
|
679
679
|
)
|
@@ -698,7 +698,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
698
698
|
"""
|
699
699
|
|
700
700
|
# Get.
|
701
|
-
result = await self.
|
701
|
+
result = await self.engine.execute.select(
|
702
702
|
'config',
|
703
703
|
'`value`'
|
704
704
|
)
|
reydb/rconn.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
4
|
"""
|
5
|
-
@Time : 2022-12-05
|
5
|
+
@Time : 2022-12-05
|
6
6
|
@Author : Rey
|
7
7
|
@Contact : reyxbo@163.com
|
8
8
|
@Explain : Database connection methods.
|
@@ -13,7 +13,7 @@ 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
|
-
from . import
|
16
|
+
from . import rengine, rexec
|
17
17
|
from .rbase import ConnectionT, TransactionT, DatabaseBase
|
18
18
|
|
19
19
|
|
@@ -24,11 +24,11 @@ __all__ = (
|
|
24
24
|
)
|
25
25
|
|
26
26
|
|
27
|
-
|
27
|
+
DatabaseEngineT = TypeVar('DatabaseEngineT', 'rengine.DatabaseEngine', 'rengine.DatabaseEngineAsync')
|
28
28
|
DatabaseExecuteT = TypeVar('DatabaseExecuteT', 'rexec.DatabaseExecute', 'rexec.DatabaseExecuteAsync')
|
29
29
|
|
30
30
|
|
31
|
-
class DatabaseConnectionSuper(DatabaseBase, Generic[
|
31
|
+
class DatabaseConnectionSuper(DatabaseBase, Generic[DatabaseEngineT, DatabaseExecuteT, ConnectionT, TransactionT]):
|
32
32
|
"""
|
33
33
|
Database connection super type.
|
34
34
|
"""
|
@@ -36,7 +36,7 @@ class DatabaseConnectionSuper(DatabaseBase, Generic[DatabaseT, DatabaseExecuteT,
|
|
36
36
|
|
37
37
|
def __init__(
|
38
38
|
self,
|
39
|
-
|
39
|
+
engine: DatabaseEngineT,
|
40
40
|
autocommit: bool
|
41
41
|
) -> None:
|
42
42
|
"""
|
@@ -44,24 +44,24 @@ class DatabaseConnectionSuper(DatabaseBase, Generic[DatabaseT, DatabaseExecuteT,
|
|
44
44
|
|
45
45
|
Parameters
|
46
46
|
----------
|
47
|
-
|
47
|
+
engine : Database engine.
|
48
48
|
autocommit: Whether automatic commit execute.
|
49
49
|
"""
|
50
50
|
|
51
51
|
# Build.
|
52
|
-
self.
|
52
|
+
self.engine = engine
|
53
53
|
self.autocommit = autocommit
|
54
|
-
match
|
55
|
-
case
|
54
|
+
match self.engine:
|
55
|
+
case rengine.DatabaseEngine():
|
56
56
|
exec = rexec.DatabaseExecute(self)
|
57
|
-
case
|
57
|
+
case rengine.DatabaseEngineAsync():
|
58
58
|
exec = rexec.DatabaseExecuteAsync(self)
|
59
59
|
self.execute: DatabaseExecuteT = exec
|
60
60
|
self.connection: ConnectionT | None = None
|
61
61
|
self.transaction: TransactionT | None = None
|
62
62
|
|
63
63
|
|
64
|
-
class DatabaseConnection(DatabaseConnectionSuper['
|
64
|
+
class DatabaseConnection(DatabaseConnectionSuper['rengine.DatabaseEngine', 'rexec.DatabaseExecute', Connection, Transaction]):
|
65
65
|
"""
|
66
66
|
Database connection type.
|
67
67
|
"""
|
@@ -111,7 +111,7 @@ class DatabaseConnection(DatabaseConnectionSuper['rdb.Database', 'rexec.Database
|
|
111
111
|
|
112
112
|
# Create.
|
113
113
|
if self.connection is None:
|
114
|
-
self.connection = self.
|
114
|
+
self.connection = self.engine.engine.connect()
|
115
115
|
|
116
116
|
return self.connection
|
117
117
|
|
@@ -186,7 +186,7 @@ class DatabaseConnection(DatabaseConnectionSuper['rdb.Database', 'rexec.Database
|
|
186
186
|
return insert_id
|
187
187
|
|
188
188
|
|
189
|
-
class DatabaseConnectionAsync(DatabaseConnectionSuper['
|
189
|
+
class DatabaseConnectionAsync(DatabaseConnectionSuper['rengine.DatabaseEngineAsync', 'rexec.DatabaseExecuteAsync', AsyncConnection, AsyncTransaction]):
|
190
190
|
"""
|
191
191
|
Asynchronous database connection type.
|
192
192
|
"""
|
@@ -223,7 +223,7 @@ class DatabaseConnectionAsync(DatabaseConnectionSuper['rdb.DatabaseAsync', 'rexe
|
|
223
223
|
|
224
224
|
# Close.
|
225
225
|
await self.close()
|
226
|
-
await self.
|
226
|
+
await self.engine.dispose()
|
227
227
|
|
228
228
|
|
229
229
|
async def get_conn(self) -> AsyncConnection:
|
@@ -237,7 +237,7 @@ class DatabaseConnectionAsync(DatabaseConnectionSuper['rdb.DatabaseAsync', 'rexe
|
|
237
237
|
|
238
238
|
# Create.
|
239
239
|
if self.connection is None:
|
240
|
-
self.connection = await self.
|
240
|
+
self.connection = await self.engine.engine.connect()
|
241
241
|
|
242
242
|
return self.connection
|
243
243
|
|