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/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 DatabaseT, DatabaseExecuteT, ConnectionT, TransactionT, DatabaseBase
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.conn: ConnectionT | None = None
57
- self.begin: TransactionT | None = None
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.conn is None:
110
- self.conn = self.db.engine.connect()
113
+ if self.connection is None:
114
+ self.connection = self.db.engine.connect()
111
115
 
112
- return self.conn
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.begin is None:
129
+ if self.transaction is None:
126
130
  conn = self.get_conn()
127
- self.begin = conn.begin()
131
+ self.transaction = conn.begin()
128
132
 
129
- return self.begin
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.begin is not None:
139
- self.begin.commit()
140
- self.begin = None
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.begin is not None:
150
- self.begin.rollback()
151
- self.begin = None
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.begin is not None:
161
- self.begin.close()
162
- self.begin = None
163
- if self.conn is not None:
164
- self.conn.close()
165
- self.conn = None
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.conn is None:
236
- self.conn = await self.db.engine.connect()
239
+ if self.connection is None:
240
+ self.connection = await self.db.engine.connect()
237
241
 
238
- return self.conn
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.begin is None:
255
+ if self.transaction is None:
252
256
  conn = await self.get_conn()
253
- self.begin = await conn.begin()
257
+ self.transaction = await conn.begin()
254
258
 
255
- return self.begin
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.begin is not None:
265
- await self.begin.commit()
266
- self.begin = None
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.begin is not None:
276
- await self.begin.rollback()
277
- self.begin = None
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.begin is not None:
287
- await self.begin.close()
288
- self.begin = None
289
- if self.conn is not None:
290
- await self.conn.close()
291
- self.conn = None
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, rinfo, rorm, rparam
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
- rbase.DatabaseConnectionT,
34
- rbase.DatabaseExecuteT,
35
- rbase.DatabaseSchemaT,
36
- rbase.DatabaseORMT
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) -> rbase.DatabaseConnectionT:
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) -> rbase.DatabaseExecuteT:
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) -> 'rbase.DatabaseORMT':
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
- dbbuild = rbuild.DatabaseBuild(self)
330
+ match self:
331
+ case Database():
332
+ build = rbuild.DatabaseBuild(self)
333
+ case DatabaseAsync():
334
+ build = rbuild.DatabaseBuildAsync(self)
313
335
 
314
- return dbbuild
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
- dbconfig = rconfig.DatabaseConfig(self)
361
-
362
- return dbconfig
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 dbischema
388
+ return config
399
389
 
400
390
 
401
391
  @property
402
- def schema(self) -> rbase.DatabaseSchemaT:
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 status(self):
412
+ def var(self) -> DatabaseParametersVariablesT:
423
413
  """
424
- Build database parameters status instance.
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
- dbps = rparam.DatabaseParametersStatus(self, False)
422
+ match self:
423
+ case Database():
424
+ var = rparam.DatabaseParametersVariables(self)
425
+ case DatabaseAsync():
426
+ var = rparam.DatabaseParametersVariablesAsync(self)
433
427
 
434
- return dbps
428
+ return var
435
429
 
436
430
 
437
431
  @property
438
- def status_global(self):
432
+ def stat(self) -> DatabaseParametersVariablesT:
439
433
  """
440
- Build global database parameters status instance.
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
- dbps = rparam.DatabaseParametersStatus(self, True)
442
+ match self:
443
+ case Database():
444
+ stat = rparam.DatabaseParametersStatus(self)
445
+ case DatabaseAsync():
446
+ stat = rparam.DatabaseParametersStatusAsync(self)
449
447
 
450
- return dbps
448
+ return stat
451
449
 
452
450
 
453
451
  @property
454
- def variables(self):
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
- dbpv = rparam.DatabaseParametersVariable(self, False)
462
+ match self:
463
+ case Database():
464
+ var = rparam.DatabaseParametersVariablesGlobal(self)
465
+ case DatabaseAsync():
466
+ var = rparam.DatabaseParametersVariablesGlobalAsync(self)
465
467
 
466
- return dbpv
468
+ return var
467
469
 
468
470
 
469
471
  @property
470
- def variables_global(self):
472
+ def glob_stat(self) -> DatabaseParametersStatusGlobalT:
471
473
  """
472
- Build global database parameters variable instance.
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
- ## SQLite.
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
- 'rorm.DatabaseORM'
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
- 'rorm.DatabaseORMAsync'
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 all standard databases and tables, by `self.db_names`.
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
- (self.db_names['base'], self.db_names['base.error']),
226
+ self.db_names['base.error'],
227
227
  data=data
228
228
  )
229
229