reydb 1.2.17__py3-none-any.whl → 1.2.19__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/rconfig.py CHANGED
@@ -24,7 +24,7 @@ from .rbase import DatabaseBase
24
24
 
25
25
 
26
26
  __all__ = (
27
- 'DatabaseTableConfig',
27
+ 'DatabaseORMTableConfig',
28
28
  'DatabaseConfigSuper',
29
29
  'DatabaseConfig',
30
30
  'DatabaseConfigAsync'
@@ -38,9 +38,9 @@ ConfigValueT = TypeVar('T', bound=ConfigValue) # Any.
38
38
  DatabaseT = TypeVar('DatabaseT', 'rdb.Database', 'rdb.DatabaseAsync')
39
39
 
40
40
 
41
- class DatabaseTableConfig(rorm.Model, table=True):
41
+ class DatabaseORMTableConfig(rorm.Model, table=True):
42
42
  """
43
- Database `config` table model.
43
+ Database `config` table ORM model.
44
44
  """
45
45
 
46
46
  __name__ = 'config'
@@ -59,6 +59,8 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
59
59
  Can create database used `self.build_db` method.
60
60
  """
61
61
 
62
+ _checked: bool = False
63
+
62
64
 
63
65
  def __init__(self, db: DatabaseT) -> None:
64
66
  """
@@ -72,8 +74,16 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
72
74
  # Build.
73
75
  self.db = db
74
76
 
77
+ # Build Database.
78
+ if not self._checked:
79
+ if type(self) == DatabaseConfig:
80
+ self.build_db()
81
+ elif type(self) == DatabaseConfigAsync:
82
+ db.sync_database.config.build_db()
83
+ self._checked = True
84
+
75
85
 
76
- def handle_build_db(self) -> tuple[list[type[DatabaseTableConfig]], list[dict[str, Any]]] :
86
+ def handle_build_db(self) -> tuple[list[type[DatabaseORMTableConfig]], list[dict[str, Any]]] :
77
87
  """
78
88
  Handle method of check and build database tables.
79
89
 
@@ -86,7 +96,7 @@ class DatabaseConfigSuper(DatabaseBase, Generic[DatabaseT]):
86
96
  database = self.db.database
87
97
 
88
98
  ## Table.
89
- tables = [DatabaseTableConfig]
99
+ tables = [DatabaseORMTableConfig]
90
100
 
91
101
  ## View stats.
92
102
  views_stats = [
reydb/rdb.py CHANGED
@@ -9,7 +9,7 @@
9
9
  """
10
10
 
11
11
 
12
- from typing import TypeVar, Generic
12
+ from typing import TypeVar, Generic, overload
13
13
  from urllib.parse import quote as urllib_quote
14
14
  from pymysql.constants.CLIENT import MULTI_STATEMENTS
15
15
  from sqlalchemy import Engine, create_engine as sqlalchemy_create_engine
@@ -519,6 +519,30 @@ class Database(
519
519
  """
520
520
 
521
521
 
522
+ @property
523
+ def async_database(self) -> 'DatabaseAsync':
524
+ """
525
+ Same engine `DatabaseAsync` instance.
526
+ """
527
+
528
+ # Build.
529
+ db = DatabaseAsync(
530
+ self.host,
531
+ self.port,
532
+ self.username,
533
+ self.password,
534
+ self.database,
535
+ self.pool_size,
536
+ self.max_overflow,
537
+ self.pool_timeout,
538
+ self.pool_recycle,
539
+ self.echo,
540
+ **self.query
541
+ )
542
+
543
+ return db
544
+
545
+
522
546
  class DatabaseAsync(
523
547
  DatabaseSuper[
524
548
  AsyncEngine,
@@ -539,6 +563,30 @@ class DatabaseAsync(
539
563
  """
540
564
 
541
565
 
566
+ @property
567
+ def sync_database(self) -> Database:
568
+ """
569
+ Same engine `Database` instance.
570
+ """
571
+
572
+ # Build.
573
+ db = Database(
574
+ self.host,
575
+ self.port,
576
+ self.username,
577
+ self.password,
578
+ self.database,
579
+ self.pool_size,
580
+ self.max_overflow,
581
+ self.pool_timeout,
582
+ self.pool_recycle,
583
+ self.echo,
584
+ **self.query
585
+ )
586
+
587
+ return db
588
+
589
+
542
590
  async def dispose(self) -> None:
543
591
  """
544
592
  Dispose asynchronous connections.
reydb/rerror.py CHANGED
@@ -22,7 +22,7 @@ from .rbase import DatabaseBase
22
22
 
23
23
 
24
24
  __all__ = (
25
- 'DatabaseTableError',
25
+ 'DatabaseORMTableError',
26
26
  'DatabaseErrorSuper',
27
27
  'DatabaseError',
28
28
  'DatabaseErrorAsync'
@@ -32,9 +32,9 @@ __all__ = (
32
32
  DatabaseT = TypeVar('DatabaseT', 'rdb.Database', 'rdb.DatabaseAsync')
33
33
 
34
34
 
35
- class DatabaseTableError(rorm.Model, table=True):
35
+ class DatabaseORMTableError(rorm.Model, table=True):
36
36
  """
37
- Database `error` table model.
37
+ Database `error` table ORM model.
38
38
  """
39
39
 
40
40
  __name__ = 'error'
@@ -53,6 +53,8 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
53
53
  Can create database used `self.build_db` method.
54
54
  """
55
55
 
56
+ _checked: bool = False
57
+
56
58
 
57
59
  def __init__(self, db: DatabaseT) -> None:
58
60
  """
@@ -66,8 +68,16 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
66
68
  # Build.
67
69
  self.db = db
68
70
 
71
+ # Build Database.
72
+ if not self._checked:
73
+ if type(self) == DatabaseError:
74
+ self.build_db()
75
+ elif type(self) == DatabaseErrorAsync:
76
+ db.sync_database.error.build_db()
77
+ self._checked = True
78
+
69
79
 
70
- def handle_build_db(self) -> tuple[list[type[DatabaseTableError]], list[dict[str, Any]]]:
80
+ def handle_build_db(self) -> tuple[list[type[DatabaseORMTableError]], list[dict[str, Any]]]:
71
81
  """
72
82
  Handle method of check and build database tables.
73
83
 
@@ -80,7 +90,7 @@ class DatabaseErrorSuper(DatabaseBase, Generic[DatabaseT]):
80
90
  database = self.db.database
81
91
 
82
92
  ## Table.
83
- tables = [DatabaseTableError]
93
+ tables = [DatabaseORMTableError]
84
94
 
85
95
  ## View stats.
86
96
  views_stats = [
reydb/rexec.py CHANGED
@@ -28,7 +28,6 @@ from .rbase import DatabaseBase, handle_sql, handle_data
28
28
 
29
29
  __all__ = (
30
30
  'Result',
31
- 'ResultORM',
32
31
  'DatabaseExecuteSuper',
33
32
  'DatabaseExecute',
34
33
  'DatabaseExecuteAsync'