reydb 1.1.20__py3-none-any.whl → 1.1.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/rbuild.py CHANGED
@@ -67,6 +67,7 @@ class DBBuild(BaseDatabase):
67
67
 
68
68
  # Set attribute.
69
69
  self.rdatabase = rdatabase
70
+ self._schema: dict[str, dict[str, list[str]]] | None = None
70
71
 
71
72
 
72
73
  def create_database(
@@ -988,20 +989,21 @@ class DBBuild(BaseDatabase):
988
989
 
989
990
  # Handle parameter.
990
991
  database, table, column = self.rdatabase.extract_path(path, 'database')
992
+ if self._schema is None:
993
+ self._schema = self.rdatabase.schema(False)
991
994
 
992
995
  # Judge.
993
- if table is None:
994
- rinfo = self.rdatabase.info(database)
995
- elif column is None:
996
- rinfo = self.rdatabase.info(database)(table)
997
- else:
998
- rinfo = self.rdatabase.info(database)(table)(column)
999
- try:
1000
- rinfo['*']
1001
- except AssertionError:
1002
- judge = False
1003
- else:
1004
- judge = True
996
+ judge = not (
997
+ (database_info := self._schema.get(database)) is None
998
+ or (
999
+ table is not None
1000
+ and (table_info := database_info.get(table)) is None
1001
+ )
1002
+ or (
1003
+ column is not None
1004
+ and column not in table_info
1005
+ )
1006
+ )
1005
1007
 
1006
1008
  return judge
1007
1009
 
reydb/rdb.py CHANGED
@@ -1757,11 +1757,14 @@ class Database(BaseDatabase):
1757
1757
  return dbexecute
1758
1758
 
1759
1759
 
1760
- @property
1761
- def schema(self) -> dict[str, dict[str, list]]:
1760
+ def schema(self, filter_default: bool = True) -> dict[str, dict[str, list[str]]]:
1762
1761
  """
1763
1762
  Get schemata of databases and tables and columns.
1764
1763
 
1764
+ Parameters
1765
+ ----------
1766
+ filter_default : Whether filter default database.
1767
+
1765
1768
  Returns
1766
1769
  -------
1767
1770
  Schemata of databases and tables and columns.
@@ -1771,30 +1774,45 @@ class Database(BaseDatabase):
1771
1774
  if self.backend == 'sqlite':
1772
1775
  throw(AssertionError, self.drivername)
1773
1776
 
1774
- # Select.
1777
+ # Handle parameter.
1775
1778
  filter_db = (
1776
1779
  'information_schema',
1777
- 'mysql',
1778
1780
  'performance_schema',
1781
+ 'mysql',
1779
1782
  'sys'
1780
1783
  )
1781
- result = self.execute_select(
1782
- 'information_schema.COLUMNS',
1783
- ['TABLE_SCHEMA', 'TABLE_NAME', 'COLUMN_NAME'],
1784
- '`TABLE_SCHEMA` NOT IN :filter_db',
1785
- order='`TABLE_SCHEMA`, `TABLE_NAME`, `ORDINAL_POSITION`',
1786
- filter_db=filter_db
1784
+ if filter_default:
1785
+ where_database = 'WHERE `SCHEMA_NAME` NOT IN :filter_db\n'
1786
+ where_column = 'WHERE `TABLE_SCHEMA` NOT IN :filter_db\n'
1787
+ else:
1788
+ where_database = where_column = ''
1789
+
1790
+ # Select.
1791
+ sql = (
1792
+ 'SELECT GROUP_CONCAT(`SCHEMA_NAME`) AS `TABLE_SCHEMA`, NULL AS `TABLE_NAME`, NULL AS `COLUMN_NAME`\n'
1793
+ 'FROM `information_schema`.`SCHEMATA`\n'
1794
+ f'{where_database}'
1795
+ 'UNION ALL (\n'
1796
+ 'SELECT `TABLE_SCHEMA`, `TABLE_NAME`, `COLUMN_NAME`\n'
1797
+ 'FROM `information_schema`.`COLUMNS`\n'
1798
+ f'{where_column}'
1799
+ 'ORDER BY `TABLE_SCHEMA`, `TABLE_NAME`, `ORDINAL_POSITION`)'
1787
1800
  )
1801
+ result = self.execute(sql, filter_db=filter_db)
1788
1802
 
1789
1803
  # Convert.
1790
- database_dict = {}
1804
+ database_names, *_ = result.fetchone()
1805
+ database_names: list[str] = database_names.split(',')
1806
+ schema_dict = {}
1791
1807
  for database, table, column in result:
1808
+ if database in database_names:
1809
+ database_names.remove(database)
1792
1810
 
1793
1811
  ## Index database.
1794
- if database not in database_dict:
1795
- database_dict[database] = {table: [column]}
1812
+ if database not in schema_dict:
1813
+ schema_dict[database] = {table: [column]}
1796
1814
  continue
1797
- table_dict: dict = database_dict[database]
1815
+ table_dict: dict = schema_dict[database]
1798
1816
 
1799
1817
  ## Index table.
1800
1818
  if table not in table_dict:
@@ -1805,7 +1823,11 @@ class Database(BaseDatabase):
1805
1823
  ## Add column.
1806
1824
  column_list.append(column)
1807
1825
 
1808
- return database_dict
1826
+ ## Add empty database.
1827
+ for database_name in database_names:
1828
+ schema_dict[database_name] = None
1829
+
1830
+ return schema_dict
1809
1831
 
1810
1832
 
1811
1833
  @property
reydb/rfile.py CHANGED
@@ -52,10 +52,18 @@ class DBFile(BaseDatabase):
52
52
  # Set attribute.
53
53
  self.rdatabase = rdatabase
54
54
 
55
+ ## Database path name.
56
+ self.path_names = {
57
+ 'file': 'file',
58
+ 'file.information': 'information',
59
+ 'file.data': 'data',
60
+ 'file.stats': 'stats'
61
+ }
62
+
55
63
 
56
64
  def build(self) -> None:
57
65
  """
58
- Check and build all standard databases and tables.
66
+ Check and build all standard databases and tables, by `self.path_names`.
59
67
  """
60
68
 
61
69
  # Set parameter.
@@ -63,7 +71,7 @@ class DBFile(BaseDatabase):
63
71
  ## Database.
64
72
  databases = [
65
73
  {
66
- 'database': 'file'
74
+ 'name': self.path_names['file']
67
75
  }
68
76
  ]
69
77
 
@@ -72,7 +80,7 @@ class DBFile(BaseDatabase):
72
80
 
73
81
  ### 'information'.
74
82
  {
75
- 'path': ('file', 'information'),
83
+ 'path': (self.path_names['file'], self.path_names['file.information']),
76
84
  'fields': [
77
85
  {
78
86
  'name': 'create_time',
@@ -125,7 +133,7 @@ class DBFile(BaseDatabase):
125
133
 
126
134
  ### 'data'.
127
135
  {
128
- 'path': ('file', 'data'),
136
+ 'path': (self.path_names['file'], self.path_names['file.data']),
129
137
  'fields': [
130
138
  {
131
139
  'name': 'md5',
@@ -156,7 +164,7 @@ class DBFile(BaseDatabase):
156
164
 
157
165
  ### 'stats'.
158
166
  {
159
- 'path': ('file', 'stats'),
167
+ 'path': (self.path_names['file'], self.path_names['file.stats']),
160
168
  'items': [
161
169
  {
162
170
  'name': 'count',
@@ -264,7 +272,7 @@ class DBFile(BaseDatabase):
264
272
 
265
273
  # Exist.
266
274
  exist = conn.execute_exist(
267
- ('file', 'data'),
275
+ (self.path_names['file'], self.path_names['file.data']),
268
276
  '`md5` = :file_md5',
269
277
  file_md5=file_md5
270
278
  )
@@ -279,7 +287,7 @@ class DBFile(BaseDatabase):
279
287
  'bytes': file_bytes
280
288
  }
281
289
  conn.execute_insert(
282
- ('file', 'data'),
290
+ (self.path_names['file'], self.path_names['file.data']),
283
291
  data,
284
292
  'ignore'
285
293
  )
@@ -291,7 +299,7 @@ class DBFile(BaseDatabase):
291
299
  'note': note
292
300
  }
293
301
  conn.execute_insert(
294
- ('file', 'information'),
302
+ (self.path_names['file'], self.path_names['file.information']),
295
303
  data
296
304
  )
297
305
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reydb
3
- Version: 1.1.20
3
+ Version: 1.1.21
4
4
  Summary: Database method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reydb/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -1,14 +1,14 @@
1
1
  reydb/__init__.py,sha256=UetBDQylwFTWiPMKF1ZPW45A6mwYWWSYneTesl4xKBY,474
2
2
  reydb/rall.py,sha256=i6-ph2cahhTTF17DjUYf6KX3DNxhEvy6iedlSeF4ibI,341
3
3
  reydb/rbase.py,sha256=HMhxr7_TyzAusrv5dcc1hf3PmxGWj7m63kKcr5Ikbf4,312
4
- reydb/rbuild.py,sha256=hn6XUUk3vpIjh1p1HlNU46MMDggIGjTiBobhvq410yM,32214
4
+ reydb/rbuild.py,sha256=_K571-4uVp8qj56PNaXa4FjEWYPLiuxXmo0FiXX_JLk,32343
5
5
  reydb/rconn.py,sha256=52k8MceNF6PjAUXIkC6NoDqjhAD_RM2_mueWbMMfoPE,6567
6
- reydb/rdb.py,sha256=Nf_odkhBt1TamCKtkOs3Mnf0Qvy7vs0vMQ9fRJKgafM,59423
6
+ reydb/rdb.py,sha256=YWsHdxYqw8JXYrsJ-a9zS4eimwhcqM8hxpMmjchrpbw,60365
7
7
  reydb/rexec.py,sha256=kc5xSfuEDFW9rcAeJj_x6JWPDSYnHZQXcfSBXFGIhL8,8893
8
- reydb/rfile.py,sha256=R4IhRWI_VuZIqXQeqKInwExH6u5hLPOElTusdASK5Ec,11644
8
+ reydb/rfile.py,sha256=YD9EAglrWflWCjTiu9ze-ZKlm9x-WzKkXzfLie1kcAQ,12133
9
9
  reydb/rinfo.py,sha256=NhcFhzp9gQ49EpAqcFYXcG-FMUXu3qii8WGoHxN6UcQ,14250
10
10
  reydb/rparam.py,sha256=EVSz_D4wyiaj5ZKxvdDcECmpbriOUNBBFCzz4bnV6dY,6838
11
- reydb-1.1.20.dist-info/METADATA,sha256=TMsZaYKfws0lU5fppAfyqd1vA49Ma4zRexs-SuGVAMk,1550
12
- reydb-1.1.20.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
- reydb-1.1.20.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
14
- reydb-1.1.20.dist-info/RECORD,,
11
+ reydb-1.1.21.dist-info/METADATA,sha256=G2IEJUFMkTS4TlT2qUGBlsM7INOAif9xc97YFufvc6c,1550
12
+ reydb-1.1.21.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
13
+ reydb-1.1.21.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
14
+ reydb-1.1.21.dist-info/RECORD,,
File without changes