reydb 1.1.28__py3-none-any.whl → 1.1.29__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 CHANGED
@@ -17,5 +17,6 @@ rdb : Database methods.
17
17
  rexec : Database execute methods.
18
18
  rfile : Database file methods.
19
19
  rinfo : Database information methods.
20
+ rlog : Database log methods.
20
21
  rparam : Database parameter methods.
21
22
  """
reydb/rall.py CHANGED
@@ -16,4 +16,5 @@ from .rdb import *
16
16
  from .rexec import *
17
17
  from .rfile import *
18
18
  from .rinfo import *
19
+ from .rlog import *
19
20
  from .rparam import *
reydb/rbase.py CHANGED
@@ -13,11 +13,11 @@ from reykit.rbase import Base
13
13
 
14
14
 
15
15
  __all__ = (
16
- 'BaseDatabase',
16
+ 'DatabaseBase',
17
17
  )
18
18
 
19
19
 
20
- class BaseDatabase(Base):
20
+ class DatabaseBase(Base):
21
21
  """
22
22
  Database base type.
23
23
  """
reydb/rbuild.py CHANGED
@@ -14,13 +14,13 @@ from copy import deepcopy
14
14
  from reykit.rbase import throw
15
15
  from reykit.rstdout import ask
16
16
 
17
- from .rbase import BaseDatabase
18
- from .rconn import DBConnection
17
+ from .rbase import DatabaseBase
18
+ from .rconn import DatabaseConnection
19
19
  from .rdb import Database
20
20
 
21
21
 
22
22
  __all__ = (
23
- 'DBBuild',
23
+ 'DatabaseBuild',
24
24
  )
25
25
 
26
26
 
@@ -46,19 +46,19 @@ IndexSet = TypedDict(
46
46
  )
47
47
 
48
48
 
49
- class DBBuild(BaseDatabase):
49
+ class DatabaseBuild(DatabaseBase):
50
50
  """
51
51
  Database build type.
52
52
  """
53
53
 
54
54
 
55
- def __init__(self, rdatabase: Database | DBConnection) -> None:
55
+ def __init__(self, rdatabase: Database | DatabaseConnection) -> None:
56
56
  """
57
57
  Build instance attributes.
58
58
 
59
59
  Parameters
60
60
  ----------
61
- rdatabase : Database or DBConnection instance.
61
+ rdatabase : Database or DatabaseConnection instance.
62
62
  """
63
63
 
64
64
  # SQLite.
@@ -994,15 +994,18 @@ class DBBuild(BaseDatabase):
994
994
  self._schema = self.rdatabase.schema(False)
995
995
 
996
996
  # Judge.
997
- judge = not (
998
- (database_info := self._schema.get(database)) is None
999
- or (
1000
- table is not None
1001
- and (table_info := database_info.get(table)) is None
997
+ judge = (
998
+ database in self._schema
999
+ and (
1000
+ table is None
1001
+ or (
1002
+ (database_info := self._schema.get(database)) is not None
1003
+ and (table_info := database_info.get(table)) is not None
1004
+ )
1002
1005
  )
1003
- or (
1004
- column is not None
1005
- and column not in table_info
1006
+ and (
1007
+ column is None
1008
+ or column in table_info
1006
1009
  )
1007
1010
  )
1008
1011
 
reydb/rconn.py CHANGED
@@ -10,13 +10,9 @@
10
10
 
11
11
 
12
12
  from typing import Any, Self
13
- from types import TracebackType
14
- from sqlalchemy import text as sqlalchemy_text
15
13
  from sqlalchemy.engine.base import Connection
16
- from sqlalchemy.engine.cursor import CursorResult
17
14
  from sqlalchemy.sql.elements import TextClause
18
15
  from sqlalchemy.exc import OperationalError
19
- from pandas import DataFrame
20
16
  from reykit.rbase import get_first_notnone
21
17
  from reykit.rdata import objs_in
22
18
  from reykit.rstdout import echo
@@ -27,11 +23,11 @@ from .rdb import Result, Database
27
23
 
28
24
 
29
25
  __all__ = (
30
- 'DBConnection',
26
+ 'DatabaseConnection',
31
27
  )
32
28
 
33
29
 
34
- class DBConnection(Database):
30
+ class DatabaseConnection(Database):
35
31
  """
36
32
  Database connection type.
37
33
  """
@@ -177,7 +173,7 @@ class DBConnection(Database):
177
173
  ):
178
174
  text = 'Retrying...'
179
175
  title = 'Database Execute Operational Error'
180
- handler = lambda exc_report, *_: echo(exc_report, text, title=title, frame='top')
176
+ handler = lambda exc_text, *_: echo(exc_text, text, title=title, frame='top')
181
177
  executor = wrap_retry(self.executor, handler=handler, exception=OperationalError)
182
178
  result = executor(self.connection, sql, data, report)
183
179
 
@@ -236,8 +232,7 @@ class DBConnection(Database):
236
232
  def __exit__(
237
233
  self,
238
234
  exc_type: type[BaseException] | None,
239
- exc_instance: BaseException | None,
240
- exc_traceback: TracebackType | None
235
+ *_
241
236
  ) -> None:
242
237
  """
243
238
  Exit syntax `with`.
@@ -245,8 +240,6 @@ class DBConnection(Database):
245
240
  Parameters
246
241
  ----------
247
242
  exc_type : Exception type.
248
- exc_instance : Exception instance.
249
- exc_traceback : Exception traceback instance.
250
243
  """
251
244
 
252
245
  # Commit.
reydb/rdb.py CHANGED
@@ -27,7 +27,7 @@ from reykit.rtable import TableData, Table
27
27
  from reykit.rtext import join_data_text
28
28
  from reykit.rwrap import wrap_runtime, wrap_retry
29
29
 
30
- from .rbase import BaseDatabase
30
+ from .rbase import DatabaseBase
31
31
 
32
32
 
33
33
  __all__ = (
@@ -42,7 +42,7 @@ Result = Result_
42
42
  monkey_sqlalchemy_row_index_field()
43
43
 
44
44
 
45
- class Database(BaseDatabase):
45
+ class Database(DatabaseBase):
46
46
  """
47
47
  Database type.
48
48
 
@@ -885,7 +885,7 @@ class Database(BaseDatabase):
885
885
  ):
886
886
  text = 'Retrying...'
887
887
  title = 'Database Execute Operational Error'
888
- handler = lambda exc_report, *_: echo(exc_report, text, title=title, frame='top')
888
+ handler = lambda exc_text, *_: echo(exc_text, text, title=title, frame='top')
889
889
  executor = wrap_retry(self.executor, handler=handler, exception=OperationalError)
890
890
  result = executor(self.connection, sql, data, report)
891
891
 
@@ -1687,7 +1687,7 @@ class Database(BaseDatabase):
1687
1687
 
1688
1688
  def connect(self):
1689
1689
  """
1690
- Build instance attributes.
1690
+ Build `DatabaseConnection` instance.
1691
1691
 
1692
1692
  Returns
1693
1693
  -------
@@ -1695,10 +1695,10 @@ class Database(BaseDatabase):
1695
1695
  """
1696
1696
 
1697
1697
  # Import.
1698
- from .rconn import DBConnection
1698
+ from .rconn import DatabaseConnection
1699
1699
 
1700
1700
  # Build.
1701
- dbconnection = DBConnection(
1701
+ dbconnection = DatabaseConnection(
1702
1702
  self.engine.connect(),
1703
1703
  self
1704
1704
  )
@@ -1719,51 +1719,51 @@ class Database(BaseDatabase):
1719
1719
  --------
1720
1720
  Execute.
1721
1721
  >>> sql = 'select :value'
1722
- >>> result = DBExecute(sql, value=1)
1722
+ >>> result = DatabaseExecute(sql, value=1)
1723
1723
 
1724
1724
  Select.
1725
1725
  >>> field = ['id', 'value']
1726
1726
  >>> where = '`id` = ids'
1727
1727
  >>> ids = (1, 2)
1728
- >>> result = DBExecute.database.table(field, where, ids=ids)
1728
+ >>> result = DatabaseExecute.database.table(field, where, ids=ids)
1729
1729
 
1730
1730
  Insert.
1731
1731
  >>> data = [{'id': 1}, {'id': 2}]
1732
1732
  >>> duplicate = 'ignore'
1733
- >>> result = DBExecute.database.table + data
1734
- >>> result = DBExecute.database.table + (data, duplicate)
1735
- >>> result = DBExecute.database.table + {'data': data, 'duplicate': duplicate}
1733
+ >>> result = DatabaseExecute.database.table + data
1734
+ >>> result = DatabaseExecute.database.table + (data, duplicate)
1735
+ >>> result = DatabaseExecute.database.table + {'data': data, 'duplicate': duplicate}
1736
1736
 
1737
1737
  Update.
1738
1738
  >>> data = [{'name': 'a', 'id': 1}, {'name': 'b', 'id': 2}]
1739
1739
  >>> where_fields = 'id'
1740
- >>> result = DBExecute.database.table & data
1741
- >>> result = DBExecute.database.table & (data, where_fields)
1742
- >>> result = DBExecute.database.table & {'data': data, 'where_fields': where_fields}
1740
+ >>> result = DatabaseExecute.database.table & data
1741
+ >>> result = DatabaseExecute.database.table & (data, where_fields)
1742
+ >>> result = DatabaseExecute.database.table & {'data': data, 'where_fields': where_fields}
1743
1743
 
1744
1744
  Delete.
1745
1745
  >>> where = '`id` IN (1, 2)'
1746
1746
  >>> report = True
1747
- >>> result = DBExecute.database.table - where
1748
- >>> result = DBExecute.database.table - (where, report)
1749
- >>> result = DBExecute.database.table - {'where': where, 'report': report}
1747
+ >>> result = DatabaseExecute.database.table - where
1748
+ >>> result = DatabaseExecute.database.table - (where, report)
1749
+ >>> result = DatabaseExecute.database.table - {'where': where, 'report': report}
1750
1750
 
1751
1751
  Copy.
1752
1752
  >>> where = '`id` IN (1, 2)'
1753
1753
  >>> limit = 1
1754
- >>> result = DBExecute.database.table * where
1755
- >>> result = DBExecute.database.table * (where, limit)
1756
- >>> result = DBExecute.database.table * {'where': where, 'limit': limit}
1754
+ >>> result = DatabaseExecute.database.table * where
1755
+ >>> result = DatabaseExecute.database.table * (where, limit)
1756
+ >>> result = DatabaseExecute.database.table * {'where': where, 'limit': limit}
1757
1757
 
1758
1758
  Exist.
1759
1759
  >>> where = '`id` IN (1, 2)'
1760
1760
  >>> report = True
1761
- >>> result = where in DBExecute.database.table
1762
- >>> result = (where, report) in DBExecute.database.table
1763
- >>> result = {'where': where, 'report': report} in DBExecute.database.table
1761
+ >>> result = where in DatabaseExecute.database.table
1762
+ >>> result = (where, report) in DatabaseExecute.database.table
1763
+ >>> result = {'where': where, 'report': report} in DatabaseExecute.database.table
1764
1764
 
1765
1765
  Count.
1766
- >>> result = len(DBExecute.database.table)
1766
+ >>> result = len(DatabaseExecute.database.table)
1767
1767
 
1768
1768
  Default database.
1769
1769
  >>> field = ['id', 'value']
@@ -1772,10 +1772,10 @@ class Database(BaseDatabase):
1772
1772
  """
1773
1773
 
1774
1774
  # Import.
1775
- from .rexec import DBExecute
1775
+ from .rexec import DatabaseExecute
1776
1776
 
1777
1777
  # Build.
1778
- dbexecute = DBExecute(self)
1778
+ dbexecute = DatabaseExecute(self)
1779
1779
 
1780
1780
  return dbexecute
1781
1781
 
@@ -1857,7 +1857,7 @@ class Database(BaseDatabase):
1857
1857
  @property
1858
1858
  def info(self):
1859
1859
  """
1860
- Build instance attributes.
1860
+ Build `DatabaseInformationSchema` instance.
1861
1861
 
1862
1862
  Returns
1863
1863
  -------
@@ -1866,29 +1866,29 @@ class Database(BaseDatabase):
1866
1866
  Examples
1867
1867
  --------
1868
1868
  Get databases information of server.
1869
- >>> databases_info = DBISchema()
1869
+ >>> databases_info = DatabaseInformationSchema()
1870
1870
 
1871
1871
  Get tables information of database.
1872
- >>> tables_info = DBISchema.database()
1872
+ >>> tables_info = DatabaseInformationSchema.database()
1873
1873
 
1874
1874
  Get columns information of table.
1875
- >>> columns_info = DBISchema.database.table()
1875
+ >>> columns_info = DatabaseInformationSchema.database.table()
1876
1876
 
1877
1877
  Get database attribute.
1878
- >>> database_attr = DBISchema.database['attribute']
1878
+ >>> database_attr = DatabaseInformationSchema.database['attribute']
1879
1879
 
1880
1880
  Get table attribute.
1881
- >>> database_attr = DBISchema.database.table['attribute']
1881
+ >>> database_attr = DatabaseInformationSchema.database.table['attribute']
1882
1882
 
1883
1883
  Get column attribute.
1884
- >>> database_attr = DBISchema.database.table.column['attribute']
1884
+ >>> database_attr = DatabaseInformationSchema.database.table.column['attribute']
1885
1885
  """
1886
1886
 
1887
1887
  # Import.
1888
- from .rinfo import DBISchema
1888
+ from .rinfo import DatabaseInformationSchema
1889
1889
 
1890
1890
  # Build.
1891
- dbischema = DBISchema(self)
1891
+ dbischema = DatabaseInformationSchema(self)
1892
1892
 
1893
1893
  return dbischema
1894
1894
 
@@ -1896,7 +1896,7 @@ class Database(BaseDatabase):
1896
1896
  @property
1897
1897
  def build(self):
1898
1898
  """
1899
- Build instance attributes.
1899
+ Build `DatabaseBuild` instance.
1900
1900
 
1901
1901
  Returns
1902
1902
  -------
@@ -1904,10 +1904,10 @@ class Database(BaseDatabase):
1904
1904
  """
1905
1905
 
1906
1906
  # Import.
1907
- from .rbuild import DBBuild
1907
+ from .rbuild import DatabaseBuild
1908
1908
 
1909
1909
  # Build.
1910
- dbbuild = DBBuild(self)
1910
+ dbbuild = DatabaseBuild(self)
1911
1911
 
1912
1912
  return dbbuild
1913
1913
 
@@ -1915,7 +1915,7 @@ class Database(BaseDatabase):
1915
1915
  @property
1916
1916
  def file(self):
1917
1917
  """
1918
- Build instance attributes.
1918
+ Build `DatabaseFile` instance.
1919
1919
 
1920
1920
  Returns
1921
1921
  -------
@@ -1923,10 +1923,29 @@ class Database(BaseDatabase):
1923
1923
  """
1924
1924
 
1925
1925
  # Import.
1926
- from .rfile import DBFile
1926
+ from .rfile import DatabaseFile
1927
1927
 
1928
1928
  # Build.
1929
- dbfile = DBFile(self)
1929
+ dbfile = DatabaseFile(self)
1930
+
1931
+ return dbfile
1932
+
1933
+
1934
+ @property
1935
+ def log(self):
1936
+ """
1937
+ Build `DatabaseLog` instance.
1938
+
1939
+ Returns
1940
+ -------
1941
+ Database file instance.
1942
+ """
1943
+
1944
+ # Import.
1945
+ from .rlog import DatabaseLog
1946
+
1947
+ # Build.
1948
+ dbfile = DatabaseLog(self)
1930
1949
 
1931
1950
  return dbfile
1932
1951
 
@@ -1934,7 +1953,7 @@ class Database(BaseDatabase):
1934
1953
  @property
1935
1954
  def status(self):
1936
1955
  """
1937
- Build instance attributes.
1956
+ Build `DatabaseParameterStatus` or `DatabaseParameterPragma` instance.
1938
1957
 
1939
1958
  Returns
1940
1959
  -------
@@ -1942,17 +1961,17 @@ class Database(BaseDatabase):
1942
1961
  """
1943
1962
 
1944
1963
  # Import.
1945
- from .rparam import DBPStatus, DBPPragma
1964
+ from .rparam import DatabaseParameterStatus, DatabaseParameterPragma
1946
1965
 
1947
1966
  # Build.
1948
1967
 
1949
1968
  ## SQLite.
1950
1969
  if self.backend == 'sqlite':
1951
- dbp = DBPPragma(self)
1970
+ dbp = DatabaseParameterPragma(self)
1952
1971
 
1953
1972
  ## Other.
1954
1973
  else:
1955
- dbp = DBPStatus(self, False)
1974
+ dbp = DatabaseParameterStatus(self, False)
1956
1975
 
1957
1976
  return dbp
1958
1977
 
@@ -1960,7 +1979,7 @@ class Database(BaseDatabase):
1960
1979
  @property
1961
1980
  def global_status(self):
1962
1981
  """
1963
- Build global `database status parameters` instance.
1982
+ Build `DatabaseParameterStatus` or `DatabaseParameterPragma` instance.
1964
1983
 
1965
1984
  Returns
1966
1985
  -------
@@ -1968,17 +1987,17 @@ class Database(BaseDatabase):
1968
1987
  """
1969
1988
 
1970
1989
  # Import.
1971
- from .rparam import DBPStatus, DBPPragma
1990
+ from .rparam import DatabaseParameterStatus, DatabaseParameterPragma
1972
1991
 
1973
1992
  # Build.
1974
1993
 
1975
1994
  ## SQLite.
1976
1995
  if self.backend == 'sqlite':
1977
- dbp = DBPPragma(self)
1996
+ dbp = DatabaseParameterPragma(self)
1978
1997
 
1979
1998
  ## Other.
1980
1999
  else:
1981
- dbp = DBPStatus(self, True)
2000
+ dbp = DatabaseParameterStatus(self, True)
1982
2001
 
1983
2002
  return dbp
1984
2003
 
@@ -1986,7 +2005,7 @@ class Database(BaseDatabase):
1986
2005
  @property
1987
2006
  def variables(self):
1988
2007
  """
1989
- Build instance attributes.
2008
+ Build `DatabaseParameterVariable` or `DatabaseParameterPragma` instance.
1990
2009
 
1991
2010
  Returns
1992
2011
  -------
@@ -1994,17 +2013,17 @@ class Database(BaseDatabase):
1994
2013
  """
1995
2014
 
1996
2015
  # Import.
1997
- from .rparam import DBPVariable, DBPPragma
2016
+ from .rparam import DatabaseParameterVariable, DatabaseParameterPragma
1998
2017
 
1999
2018
  # Build.
2000
2019
 
2001
2020
  ## SQLite.
2002
2021
  if self.backend == 'sqlite':
2003
- dbp = DBPPragma(self)
2022
+ dbp = DatabaseParameterPragma(self)
2004
2023
 
2005
2024
  ## Other.
2006
2025
  else:
2007
- dbp = DBPVariable(self, False)
2026
+ dbp = DatabaseParameterVariable(self, False)
2008
2027
 
2009
2028
  return dbp
2010
2029
 
@@ -2020,17 +2039,17 @@ class Database(BaseDatabase):
2020
2039
  """
2021
2040
 
2022
2041
  # Import.
2023
- from .rparam import DBPVariable, DBPPragma
2042
+ from .rparam import DatabaseParameterVariable, DatabaseParameterPragma
2024
2043
 
2025
2044
  # Build.
2026
2045
 
2027
2046
  ## SQLite.
2028
2047
  if self.backend == 'sqlite':
2029
- dbp = DBPPragma(self)
2048
+ dbp = DatabaseParameterPragma(self)
2030
2049
 
2031
2050
  ## Other.
2032
2051
  else:
2033
- dbp = DBPVariable(self, True)
2052
+ dbp = DatabaseParameterVariable(self, True)
2034
2053
 
2035
2054
  return dbp
2036
2055
 
reydb/rexec.py CHANGED
@@ -13,17 +13,17 @@ from typing import Any, Self
13
13
  from reykit.rbase import throw
14
14
  from reykit.rtable import TableData
15
15
 
16
- from .rbase import BaseDatabase
17
- from .rconn import DBConnection
16
+ from .rbase import DatabaseBase
17
+ from .rconn import DatabaseConnection
18
18
  from .rdb import Database, Result
19
19
 
20
20
 
21
21
  __all__ = (
22
- 'DBExecute',
22
+ 'DatabaseExecute',
23
23
  )
24
24
 
25
25
 
26
- class DBExecute(BaseDatabase):
26
+ class DatabaseExecute(DatabaseBase):
27
27
  """
28
28
  Database execute type.
29
29
 
@@ -33,45 +33,45 @@ class DBExecute(BaseDatabase):
33
33
  >>> field = ['id', 'value']
34
34
  >>> where = '`id` = ids'
35
35
  >>> ids = (1, 2)
36
- >>> result = DBExecute.database.table(field, where, ids=ids)
36
+ >>> result = DatabaseExecute.database.table(field, where, ids=ids)
37
37
 
38
38
  Insert.
39
39
  >>> data = [{'id': 1}, {'id': 2}]
40
40
  >>> duplicate = 'ignore'
41
- >>> result = DBExecute.database.table + data
42
- >>> result = DBExecute.database.table + (data, duplicate)
43
- >>> result = DBExecute.database.table + {'data': data, 'duplicate': duplicate}
41
+ >>> result = DatabaseExecute.database.table + data
42
+ >>> result = DatabaseExecute.database.table + (data, duplicate)
43
+ >>> result = DatabaseExecute.database.table + {'data': data, 'duplicate': duplicate}
44
44
 
45
45
  Update.
46
46
  >>> data = [{'name': 'a', 'id': 1}, {'name': 'b', 'id': 2}]
47
47
  >>> where_fields = 'id'
48
- >>> result = DBExecute.database.table & data
49
- >>> result = DBExecute.database.table & (data, where_fields)
50
- >>> result = DBExecute.database.table & {'data': data, 'where_fields': where_fields}
48
+ >>> result = DatabaseExecute.database.table & data
49
+ >>> result = DatabaseExecute.database.table & (data, where_fields)
50
+ >>> result = DatabaseExecute.database.table & {'data': data, 'where_fields': where_fields}
51
51
 
52
52
  Delete.
53
53
  >>> where = '`id` IN (1, 2)'
54
54
  >>> report = True
55
- >>> result = DBExecute.database.table - where
56
- >>> result = DBExecute.database.table - (where, report)
57
- >>> result = DBExecute.database.table - {'where': where, 'report': report}
55
+ >>> result = DatabaseExecute.database.table - where
56
+ >>> result = DatabaseExecute.database.table - (where, report)
57
+ >>> result = DatabaseExecute.database.table - {'where': where, 'report': report}
58
58
 
59
59
  Copy.
60
60
  >>> where = '`id` IN (1, 2)'
61
61
  >>> limit = 1
62
- >>> result = DBExecute.database.table * where
63
- >>> result = DBExecute.database.table * (where, limit)
64
- >>> result = DBExecute.database.table * {'where': where, 'limit': limit}
62
+ >>> result = DatabaseExecute.database.table * where
63
+ >>> result = DatabaseExecute.database.table * (where, limit)
64
+ >>> result = DatabaseExecute.database.table * {'where': where, 'limit': limit}
65
65
 
66
66
  Exist.
67
67
  >>> where = '`id` IN (1, 2)'
68
68
  >>> report = True
69
- >>> result = where in DBExecute.database.table
70
- >>> result = (where, report) in DBExecute.database.table
71
- >>> result = {'where': where, 'report': report} in DBExecute.database.table
69
+ >>> result = where in DatabaseExecute.database.table
70
+ >>> result = (where, report) in DatabaseExecute.database.table
71
+ >>> result = {'where': where, 'report': report} in DatabaseExecute.database.table
72
72
 
73
73
  Count.
74
- >>> result = len(DBExecute.database.table)
74
+ >>> result = len(DatabaseExecute.database.table)
75
75
 
76
76
  Default database.
77
77
  >>> engine = Database(**server, database)
@@ -79,13 +79,13 @@ class DBExecute(BaseDatabase):
79
79
  """
80
80
 
81
81
 
82
- def __init__(self, rdatabase: Database | DBConnection) -> None:
82
+ def __init__(self, rdatabase: Database | DatabaseConnection) -> None:
83
83
  """
84
84
  Build instance attributes.
85
85
 
86
86
  Parameters
87
87
  ----------
88
- rdatabase : Database or DBConnection instance.
88
+ rdatabase : Database or DatabaseConnection instance.
89
89
  """
90
90
 
91
91
  # Set parameter.