reydb 1.1.59__py3-none-any.whl → 1.1.60__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 +0 -10
- reydb/rbuild.py +677 -177
- reydb/rconfig.py +34 -90
- reydb/rconn.py +44 -40
- reydb/rdb.py +28 -14
- reydb/rerror.py +2 -2
- reydb/rexec.py +64 -45
- reydb/rfile.py +4 -4
- reydb/rorm.py +29 -19
- reydb/rparam.py +5 -2
- {reydb-1.1.59.dist-info → reydb-1.1.60.dist-info}/METADATA +1 -1
- reydb-1.1.60.dist-info/RECORD +17 -0
- reydb-1.1.59.dist-info/RECORD +0 -17
- {reydb-1.1.59.dist-info → reydb-1.1.60.dist-info}/WHEEL +0 -0
- {reydb-1.1.59.dist-info → reydb-1.1.60.dist-info}/licenses/LICENSE +0 -0
reydb/rconfig.py
CHANGED
@@ -49,109 +49,54 @@ class DatabaseConfig(DatabaseBase):
|
|
49
49
|
"""
|
50
50
|
|
51
51
|
|
52
|
-
def __init__(
|
52
|
+
def __init__(
|
53
|
+
self,
|
54
|
+
db: 'rdb.Database',
|
55
|
+
db_names: dict[str, str] | None = None
|
56
|
+
) -> None:
|
53
57
|
"""
|
54
58
|
Build instance attributes.
|
55
59
|
|
56
60
|
Parameters
|
57
61
|
----------
|
58
62
|
db: Database instance.
|
63
|
+
db_names: Update build database table names.
|
59
64
|
"""
|
60
65
|
|
61
66
|
# Build.
|
62
67
|
self.db = db
|
63
|
-
|
64
|
-
## Database path name.
|
65
68
|
self.db_names = {
|
66
|
-
'
|
67
|
-
'
|
68
|
-
'base.stats_config': 'stats_config'
|
69
|
+
'config': 'config',
|
70
|
+
'stats_config': 'stats_config'
|
69
71
|
}
|
72
|
+
if db_names is not None:
|
73
|
+
self.db_names.update(db_names)
|
70
74
|
|
71
75
|
|
72
76
|
def build_db(self) -> None:
|
73
77
|
"""
|
74
|
-
Check and build
|
78
|
+
Check and build database tables, by `self.db_names`.
|
75
79
|
"""
|
76
80
|
|
77
|
-
#
|
78
|
-
|
79
|
-
## Database.
|
80
|
-
databases = [
|
81
|
-
{
|
82
|
-
'name': self.db_names['base']
|
83
|
-
}
|
84
|
-
]
|
81
|
+
# Handle parameter.
|
85
82
|
|
86
83
|
## Table.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
},
|
99
|
-
{
|
100
|
-
'name': 'update_time',
|
101
|
-
'type': 'datetime',
|
102
|
-
'constraint': 'DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP',
|
103
|
-
'comment': 'Config update time.'
|
104
|
-
},
|
105
|
-
{
|
106
|
-
'name': 'key',
|
107
|
-
'type': 'varchar(50)',
|
108
|
-
'constraint': 'NOT NULL',
|
109
|
-
'comment': 'Config key.'
|
110
|
-
},
|
111
|
-
{
|
112
|
-
'name': 'value',
|
113
|
-
'type': 'text',
|
114
|
-
'constraint': 'NOT NULL',
|
115
|
-
'comment': 'Config value.'
|
116
|
-
},
|
117
|
-
{
|
118
|
-
'name': 'type',
|
119
|
-
'type': 'varchar(50)',
|
120
|
-
'constraint': 'NOT NULL',
|
121
|
-
'comment': 'Config value type.'
|
122
|
-
},
|
123
|
-
{
|
124
|
-
'name': 'note',
|
125
|
-
'type': 'varchar(500)',
|
126
|
-
'comment': 'Config note.'
|
127
|
-
}
|
128
|
-
],
|
129
|
-
'primary': 'key',
|
130
|
-
'indexes': [
|
131
|
-
{
|
132
|
-
'name': 'n_create_time',
|
133
|
-
'fields': 'create_time',
|
134
|
-
'type': 'noraml',
|
135
|
-
'comment': 'Config create time normal index.'
|
136
|
-
},
|
137
|
-
{
|
138
|
-
'name': 'n_update_time',
|
139
|
-
'fields': 'update_time',
|
140
|
-
'type': 'noraml',
|
141
|
-
'comment': 'Config update time normal index.'
|
142
|
-
}
|
143
|
-
],
|
144
|
-
'comment': 'Config data table.'
|
145
|
-
}
|
146
|
-
|
147
|
-
]
|
84
|
+
class Config(self.db.orm.Model, table=True):
|
85
|
+
__name__ = self.db_names['config']
|
86
|
+
__commment__ = 'Config data table.'
|
87
|
+
create_time: datetime = self.db.orm.Field(not_null=True, field_default='CURRENT_TIMESTAMP', index_n=True, comment='Config create time.')
|
88
|
+
update_time: datetime = self.db.orm.Field(field_default='CURRENT_TIMESTAMP', index_n=True, comment='Config update time.')
|
89
|
+
key = self.db.orm.Field(type=self.db.orm.types.VARCHAR(50), key=True, not_null=True, comment='Config key.')
|
90
|
+
value = self.db.orm.Field(type=self.db.orm.types.TEXT, not_null=True, comment='Config value.')
|
91
|
+
type = self.db.orm.Field(type=self.db.orm.types.VARCHAR(50), not_null=True, comment='Config value type.')
|
92
|
+
note = self.db.orm.Field(type=self.db.orm.types.VARCHAR(500), comment='Config note.')
|
93
|
+
|
94
|
+
tables = [Config]
|
148
95
|
|
149
96
|
## View stats.
|
150
97
|
views_stats = [
|
151
|
-
|
152
|
-
### 'stats_config'.
|
153
98
|
{
|
154
|
-
'path':
|
99
|
+
'path': self.db_names['stats_config'],
|
155
100
|
'items': [
|
156
101
|
{
|
157
102
|
'name': 'count',
|
@@ -178,13 +123,12 @@ class DatabaseConfig(DatabaseBase):
|
|
178
123
|
'comment': 'Config last record update time.'
|
179
124
|
}
|
180
125
|
]
|
181
|
-
|
182
126
|
}
|
183
127
|
|
184
128
|
]
|
185
129
|
|
186
130
|
# Build.
|
187
|
-
self.db.build.build(
|
131
|
+
self.db.build.build(tables=tables, views_stats=views_stats)
|
188
132
|
|
189
133
|
|
190
134
|
@property
|
@@ -199,7 +143,7 @@ class DatabaseConfig(DatabaseBase):
|
|
199
143
|
|
200
144
|
# Get.
|
201
145
|
result = self.db.execute.select(
|
202
|
-
|
146
|
+
self.db_names['config'],
|
203
147
|
['key', 'value', 'type', 'note'],
|
204
148
|
order='IFNULL(`update_time`, `create_time`) DESC'
|
205
149
|
)
|
@@ -235,7 +179,7 @@ class DatabaseConfig(DatabaseBase):
|
|
235
179
|
# Get.
|
236
180
|
where = '`key` = :key'
|
237
181
|
result = self.db.execute.select(
|
238
|
-
|
182
|
+
self.db_names['config'],
|
239
183
|
'`value`',
|
240
184
|
where,
|
241
185
|
limit=1,
|
@@ -281,7 +225,7 @@ class DatabaseConfig(DatabaseBase):
|
|
281
225
|
'note': default_note
|
282
226
|
}
|
283
227
|
result = self.db.execute.insert(
|
284
|
-
|
228
|
+
self.db_names['config'],
|
285
229
|
data,
|
286
230
|
'ignore'
|
287
231
|
)
|
@@ -322,7 +266,7 @@ class DatabaseConfig(DatabaseBase):
|
|
322
266
|
|
323
267
|
# Update.
|
324
268
|
self.db.execute.insert(
|
325
|
-
|
269
|
+
self.db_names['config'],
|
326
270
|
data,
|
327
271
|
'update'
|
328
272
|
)
|
@@ -345,7 +289,7 @@ class DatabaseConfig(DatabaseBase):
|
|
345
289
|
where = '`key` in :key'
|
346
290
|
limit = None
|
347
291
|
result = self.db.execute.delete(
|
348
|
-
|
292
|
+
self.db_names['base.config'],
|
349
293
|
where,
|
350
294
|
limit=limit,
|
351
295
|
key=key
|
@@ -367,7 +311,7 @@ class DatabaseConfig(DatabaseBase):
|
|
367
311
|
|
368
312
|
# Get.
|
369
313
|
result = self.db.execute.select(
|
370
|
-
|
314
|
+
self.db_names['config'],
|
371
315
|
['key', 'value']
|
372
316
|
)
|
373
317
|
|
@@ -393,7 +337,7 @@ class DatabaseConfig(DatabaseBase):
|
|
393
337
|
|
394
338
|
# Get.
|
395
339
|
result = self.db.execute.select(
|
396
|
-
|
340
|
+
self.db_names['config'],
|
397
341
|
'`key`'
|
398
342
|
)
|
399
343
|
|
@@ -418,7 +362,7 @@ class DatabaseConfig(DatabaseBase):
|
|
418
362
|
|
419
363
|
# Get.
|
420
364
|
result = self.db.execute.select(
|
421
|
-
|
365
|
+
self.db_names['config'],
|
422
366
|
'`value`'
|
423
367
|
)
|
424
368
|
|
@@ -480,7 +424,7 @@ class DatabaseConfig(DatabaseBase):
|
|
480
424
|
'note': note
|
481
425
|
}
|
482
426
|
self.db.execute.insert(
|
483
|
-
|
427
|
+
self.db_names['config'],
|
484
428
|
data,
|
485
429
|
'update'
|
486
430
|
)
|
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
@@ -26,14 +26,22 @@ __all__ = (
|
|
26
26
|
)
|
27
27
|
|
28
28
|
|
29
|
+
DatabaseConnectionT = TypeVar('DatabaseConnectionT', 'rconn.DatabaseConnection', 'rconn.DatabaseConnectionAsync')
|
30
|
+
DatabaseExecuteT = TypeVar('DatabaseExecuteT', 'rexec.DatabaseExecute', 'rexec.DatabaseExecuteAsync')
|
31
|
+
DatabaseSchemaT = TypeVar('DatabaseSchemaT', 'rparam.DatabaseSchema', 'rparam.DatabaseSchemaAsync')
|
32
|
+
DatabaseORMT = TypeVar('DatabaseORMT', 'rorm.DatabaseORM', 'rorm.DatabaseORMAsync')
|
33
|
+
DatabaseBuildT = TypeVar('DatabaseBuildT')
|
34
|
+
|
35
|
+
|
29
36
|
class DatabaseSuper(
|
30
37
|
rbase.DatabaseBase,
|
31
38
|
Generic[
|
32
39
|
rbase.EngineT,
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
40
|
+
DatabaseConnectionT,
|
41
|
+
DatabaseExecuteT,
|
42
|
+
DatabaseSchemaT,
|
43
|
+
DatabaseORMT,
|
44
|
+
DatabaseBuildT
|
37
45
|
]
|
38
46
|
):
|
39
47
|
"""
|
@@ -71,7 +79,7 @@ class DatabaseSuper(
|
|
71
79
|
pool_recycle : Number of seconds `recycle` connection.
|
72
80
|
- `None | Literal[-1]`: No recycle.
|
73
81
|
- `int`: Use this value.
|
74
|
-
report : Whether report SQL execute information.
|
82
|
+
report : Whether report SQL execute information, not include ORM execute.
|
75
83
|
query : Remote server database parameters.
|
76
84
|
"""
|
77
85
|
|
@@ -238,7 +246,7 @@ class DatabaseSuper(
|
|
238
246
|
return keep_n, overflow_n
|
239
247
|
|
240
248
|
|
241
|
-
def connect(self, autocommit: bool = False) ->
|
249
|
+
def connect(self, autocommit: bool = False) -> DatabaseConnectionT:
|
242
250
|
"""
|
243
251
|
Build database connection instance.
|
244
252
|
|
@@ -262,7 +270,7 @@ class DatabaseSuper(
|
|
262
270
|
|
263
271
|
|
264
272
|
@property
|
265
|
-
def execute(self) ->
|
273
|
+
def execute(self) -> DatabaseExecuteT:
|
266
274
|
"""
|
267
275
|
Build database execute instance.
|
268
276
|
|
@@ -279,7 +287,7 @@ class DatabaseSuper(
|
|
279
287
|
|
280
288
|
|
281
289
|
@property
|
282
|
-
def orm(self) ->
|
290
|
+
def orm(self) -> DatabaseORMT:
|
283
291
|
"""
|
284
292
|
Build database ORM instance.
|
285
293
|
|
@@ -299,7 +307,7 @@ class DatabaseSuper(
|
|
299
307
|
|
300
308
|
|
301
309
|
@property
|
302
|
-
def build(self):
|
310
|
+
def build(self) -> DatabaseBuildT:
|
303
311
|
"""
|
304
312
|
Build database build instance.
|
305
313
|
|
@@ -309,9 +317,13 @@ class DatabaseSuper(
|
|
309
317
|
"""
|
310
318
|
|
311
319
|
# Build.
|
312
|
-
|
320
|
+
match self:
|
321
|
+
case Database():
|
322
|
+
build = rbuild.DatabaseBuild(self)
|
323
|
+
case DatabaseAsync():
|
324
|
+
build = rbuild.DatabaseBuildAsync(self)
|
313
325
|
|
314
|
-
return
|
326
|
+
return build
|
315
327
|
|
316
328
|
|
317
329
|
@property
|
@@ -399,7 +411,7 @@ class DatabaseSuper(
|
|
399
411
|
|
400
412
|
|
401
413
|
@property
|
402
|
-
def schema(self) ->
|
414
|
+
def schema(self) -> DatabaseSchemaT:
|
403
415
|
"""
|
404
416
|
Build database schema instance.
|
405
417
|
|
@@ -490,7 +502,8 @@ class Database(
|
|
490
502
|
'rconn.DatabaseConnection',
|
491
503
|
'rexec.DatabaseExecute',
|
492
504
|
'rparam.DatabaseSchema',
|
493
|
-
'rorm.DatabaseORM'
|
505
|
+
'rorm.DatabaseORM',
|
506
|
+
'rbuild.DatabaseBuild'
|
494
507
|
]
|
495
508
|
):
|
496
509
|
"""
|
@@ -504,7 +517,8 @@ class DatabaseAsync(
|
|
504
517
|
'rconn.DatabaseConnectionAsync',
|
505
518
|
'rexec.DatabaseExecuteAsync',
|
506
519
|
'rparam.DatabaseSchemaAsync',
|
507
|
-
'rorm.DatabaseORMAsync'
|
520
|
+
'rorm.DatabaseORMAsync',
|
521
|
+
'rbuild.DatabaseBuildAsync'
|
508
522
|
]
|
509
523
|
):
|
510
524
|
"""
|
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
|
|