reydb 1.1.56__py3-none-any.whl → 1.1.58__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 +3 -0
- reydb/rbase.py +12 -4
- reydb/rbuild.py +3 -3
- reydb/rconfig.py +5 -4
- reydb/rconn.py +44 -60
- reydb/rdb.py +155 -330
- reydb/rerror.py +3 -3
- reydb/rexec.py +40 -77
- reydb/rfile.py +3 -3
- reydb/rinfo.py +9 -9
- reydb/rorm.py +13 -13
- reydb/rparam.py +166 -83
- {reydb-1.1.56.dist-info → reydb-1.1.58.dist-info}/METADATA +2 -1
- reydb-1.1.58.dist-info/RECORD +17 -0
- reydb-1.1.56.dist-info/RECORD +0 -17
- {reydb-1.1.56.dist-info → reydb-1.1.58.dist-info}/WHEEL +0 -0
- {reydb-1.1.56.dist-info → reydb-1.1.58.dist-info}/licenses/LICENSE +0 -0
reydb/rparam.py
CHANGED
@@ -9,20 +9,179 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import overload
|
12
|
+
from typing import Generic, overload
|
13
13
|
|
14
|
-
from .
|
15
|
-
from .
|
14
|
+
from . import rdb
|
15
|
+
from .rbase import DatabaseT, DatabaseBase
|
16
|
+
from .rexec import Result
|
16
17
|
|
17
18
|
|
18
19
|
__all__ = (
|
20
|
+
'DatabaseSchema',
|
19
21
|
'DatabaseParameters',
|
20
22
|
'DatabaseParametersStatus',
|
21
|
-
'DatabaseParametersVariable'
|
22
|
-
'DatabaseParametersPragma'
|
23
|
+
'DatabaseParametersVariable'
|
23
24
|
)
|
24
25
|
|
25
26
|
|
27
|
+
class DatabaseSchemaSuper(DatabaseBase, Generic[DatabaseT]):
|
28
|
+
"""
|
29
|
+
Database schema super type.
|
30
|
+
"""
|
31
|
+
|
32
|
+
|
33
|
+
def __init__(self, db: DatabaseT) -> None:
|
34
|
+
"""
|
35
|
+
Build instance attributes.
|
36
|
+
|
37
|
+
Parameters
|
38
|
+
----------
|
39
|
+
db: Database instance.
|
40
|
+
"""
|
41
|
+
|
42
|
+
# Set parameter.
|
43
|
+
self.db = db
|
44
|
+
|
45
|
+
|
46
|
+
def _call__before(self, filter_default: bool = True) -> tuple[str, tuple[str, ...]]:
|
47
|
+
"""
|
48
|
+
Before handle of call method.
|
49
|
+
|
50
|
+
Parameters
|
51
|
+
----------
|
52
|
+
filter_default : Whether filter default database.
|
53
|
+
|
54
|
+
Returns
|
55
|
+
-------
|
56
|
+
Parameter `sql` and `filter_db`.
|
57
|
+
"""
|
58
|
+
|
59
|
+
# Handle parameter.
|
60
|
+
filter_db = (
|
61
|
+
'information_schema',
|
62
|
+
'performance_schema',
|
63
|
+
'mysql',
|
64
|
+
'sys'
|
65
|
+
)
|
66
|
+
if filter_default:
|
67
|
+
where_database = 'WHERE `SCHEMA_NAME` NOT IN :filter_db\n'
|
68
|
+
where_column = ' WHERE `TABLE_SCHEMA` NOT IN :filter_db\n'
|
69
|
+
else:
|
70
|
+
where_database = where_column = ''
|
71
|
+
|
72
|
+
# Select.
|
73
|
+
sql = (
|
74
|
+
'SELECT GROUP_CONCAT(`SCHEMA_NAME`) AS `TABLE_SCHEMA`, NULL AS `TABLE_NAME`, NULL AS `COLUMN_NAME`\n'
|
75
|
+
'FROM `information_schema`.`SCHEMATA`\n'
|
76
|
+
f'{where_database}'
|
77
|
+
'UNION ALL (\n'
|
78
|
+
' SELECT `TABLE_SCHEMA`, `TABLE_NAME`, `COLUMN_NAME`\n'
|
79
|
+
' FROM `information_schema`.`COLUMNS`\n'
|
80
|
+
f'{where_column}'
|
81
|
+
' ORDER BY `TABLE_SCHEMA`, `TABLE_NAME`, `ORDINAL_POSITION`\n'
|
82
|
+
')'
|
83
|
+
)
|
84
|
+
|
85
|
+
return sql, filter_db
|
86
|
+
|
87
|
+
|
88
|
+
def _call__after(self, result: Result) -> dict[str, dict[str, list[str]]]:
|
89
|
+
"""
|
90
|
+
After handle of call method.
|
91
|
+
|
92
|
+
Parameters
|
93
|
+
----------
|
94
|
+
result : Database select result.
|
95
|
+
|
96
|
+
Returns
|
97
|
+
-------
|
98
|
+
Parameter `schema_dict`.
|
99
|
+
"""
|
100
|
+
|
101
|
+
# Convert.
|
102
|
+
database_names, *_ = result.fetchone()
|
103
|
+
database_names: list[str] = database_names.split(',')
|
104
|
+
schema_dict = {}
|
105
|
+
for database, table, column in result:
|
106
|
+
if database in database_names:
|
107
|
+
database_names.remove(database)
|
108
|
+
|
109
|
+
## Index database.
|
110
|
+
if database not in schema_dict:
|
111
|
+
schema_dict[database] = {table: [column]}
|
112
|
+
continue
|
113
|
+
table_dict: dict = schema_dict[database]
|
114
|
+
|
115
|
+
## Index table.
|
116
|
+
if table not in table_dict:
|
117
|
+
table_dict[table] = [column]
|
118
|
+
continue
|
119
|
+
column_list: list = table_dict[table]
|
120
|
+
|
121
|
+
## Add column.
|
122
|
+
column_list.append(column)
|
123
|
+
|
124
|
+
## Add empty database.
|
125
|
+
for name in database_names:
|
126
|
+
schema_dict[name] = None
|
127
|
+
|
128
|
+
return schema_dict
|
129
|
+
|
130
|
+
|
131
|
+
class DatabaseSchema(DatabaseSchemaSuper['rdb.Database']):
|
132
|
+
"""
|
133
|
+
Database schema type.
|
134
|
+
"""
|
135
|
+
|
136
|
+
|
137
|
+
def __call__(self, filter_default: bool = True) -> dict[str, dict[str, list[str]]]:
|
138
|
+
"""
|
139
|
+
Get schemata of databases and tables and columns.
|
140
|
+
|
141
|
+
Parameters
|
142
|
+
----------
|
143
|
+
filter_default : Whether filter default database.
|
144
|
+
|
145
|
+
Returns
|
146
|
+
-------
|
147
|
+
Schemata of databases and tables and columns.
|
148
|
+
"""
|
149
|
+
|
150
|
+
# Get.
|
151
|
+
sql, filter_db = self._call__before(filter_default)
|
152
|
+
result = self.db.execute(sql, filter_db=filter_db)
|
153
|
+
schema_dict = self._call__after(result)
|
154
|
+
|
155
|
+
return schema_dict
|
156
|
+
|
157
|
+
|
158
|
+
class DatabaseSchemaAsync(DatabaseSchemaSuper['rdb.DatabaseAsync']):
|
159
|
+
"""
|
160
|
+
Asynchronous database schema type.
|
161
|
+
"""
|
162
|
+
|
163
|
+
|
164
|
+
async def __call__(self, filter_default: bool = True) -> dict[str, dict[str, list[str]]]:
|
165
|
+
"""
|
166
|
+
Asynchronous get schemata of databases and tables and columns.
|
167
|
+
|
168
|
+
Parameters
|
169
|
+
----------
|
170
|
+
filter_default : Whether filter default database.
|
171
|
+
|
172
|
+
Returns
|
173
|
+
-------
|
174
|
+
Schemata of databases and tables and columns.
|
175
|
+
"""
|
176
|
+
|
177
|
+
# Get.
|
178
|
+
sql, filter_db = self._call__before(filter_default)
|
179
|
+
result = await self.db.execute(sql, filter_db=filter_db)
|
180
|
+
schema_dict = self._call__after(result)
|
181
|
+
|
182
|
+
return schema_dict
|
183
|
+
|
184
|
+
|
26
185
|
class DatabaseParameters(DatabaseBase):
|
27
186
|
"""
|
28
187
|
Database parameters type.
|
@@ -31,7 +190,7 @@ class DatabaseParameters(DatabaseBase):
|
|
31
190
|
|
32
191
|
def __init__(
|
33
192
|
self,
|
34
|
-
db: Database,
|
193
|
+
db: 'rdb.Database',
|
35
194
|
global_: bool
|
36
195
|
) -> None:
|
37
196
|
"""
|
@@ -39,7 +198,7 @@ class DatabaseParameters(DatabaseBase):
|
|
39
198
|
|
40
199
|
Parameters
|
41
200
|
----------
|
42
|
-
db:
|
201
|
+
db: Database instance.
|
43
202
|
global\\_ : Whether base global.
|
44
203
|
"""
|
45
204
|
|
@@ -244,79 +403,3 @@ class DatabaseParametersVariable(DatabaseParameters):
|
|
244
403
|
|
245
404
|
# Execute SQL.
|
246
405
|
self.db.execute(sql)
|
247
|
-
|
248
|
-
|
249
|
-
class DatabaseParametersPragma(DatabaseParameters):
|
250
|
-
"""
|
251
|
-
Database parameters pragma type.
|
252
|
-
"""
|
253
|
-
|
254
|
-
|
255
|
-
def __init__(
|
256
|
-
self,
|
257
|
-
db: Database
|
258
|
-
) -> None:
|
259
|
-
"""
|
260
|
-
Build instance attributes.
|
261
|
-
|
262
|
-
Parameters
|
263
|
-
----------
|
264
|
-
db: `Database` instance.
|
265
|
-
"""
|
266
|
-
|
267
|
-
# Set parameter.
|
268
|
-
self.db = db
|
269
|
-
|
270
|
-
|
271
|
-
def get(self, key: str) -> str | None:
|
272
|
-
"""
|
273
|
-
Get parameter.
|
274
|
-
|
275
|
-
Parameters
|
276
|
-
----------
|
277
|
-
key : Parameter key.
|
278
|
-
|
279
|
-
Returns
|
280
|
-
-------
|
281
|
-
Variables of database.
|
282
|
-
"""
|
283
|
-
|
284
|
-
# Generate SQL.
|
285
|
-
sql = f'PRAGMA %s' % key
|
286
|
-
|
287
|
-
# Execute SQL.
|
288
|
-
result = self.db.execute(sql)
|
289
|
-
row = result.first()
|
290
|
-
if row is None:
|
291
|
-
variables = None
|
292
|
-
else:
|
293
|
-
variables = row[0]
|
294
|
-
|
295
|
-
return variables
|
296
|
-
|
297
|
-
|
298
|
-
def update(self, params: dict[str, str | float]) -> None:
|
299
|
-
"""
|
300
|
-
Update parameter.
|
301
|
-
|
302
|
-
Parameters
|
303
|
-
----------
|
304
|
-
params : Update parameter key value pairs.
|
305
|
-
"""
|
306
|
-
|
307
|
-
# Generate SQL.
|
308
|
-
sql_set_list = [
|
309
|
-
'PRAGMA %s = %s' % (
|
310
|
-
key,
|
311
|
-
(
|
312
|
-
value
|
313
|
-
if type(value) in (int, float)
|
314
|
-
else "'%s'" % value
|
315
|
-
)
|
316
|
-
)
|
317
|
-
for key, value in params.items()
|
318
|
-
]
|
319
|
-
sql = ';\n'.join(sql_set_list)
|
320
|
-
|
321
|
-
# Execute SQL.
|
322
|
-
self.db.execute(sql)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: reydb
|
3
|
-
Version: 1.1.
|
3
|
+
Version: 1.1.58
|
4
4
|
Summary: Database method set.
|
5
5
|
Project-URL: homepage, https://github.com/reyxbo/reydb/
|
6
6
|
Author-email: Rey <reyxbo@163.com>
|
@@ -14,6 +14,7 @@ License: Copyright 2025 ReyXBo
|
|
14
14
|
License-File: LICENSE
|
15
15
|
Keywords: database,db,rey,reyxbo
|
16
16
|
Requires-Python: >=3.12
|
17
|
+
Requires-Dist: aiomysql
|
17
18
|
Requires-Dist: pydantic
|
18
19
|
Requires-Dist: pymysql
|
19
20
|
Requires-Dist: reykit
|
@@ -0,0 +1,17 @@
|
|
1
|
+
reydb/__init__.py,sha256=h6duExQWsPCz3qKnTIHTslmqcBC63HCQvwiumg8oCVc,620
|
2
|
+
reydb/rall.py,sha256=GsXHqvT1k--U53HpDY4SALjIHN8rwgSxeXpJjH5gq2E,409
|
3
|
+
reydb/rbase.py,sha256=n1e7olB_9FCOzrBIDm-jwTVtoUR935sYTQ9FpuxSXGE,9390
|
4
|
+
reydb/rbuild.py,sha256=agCVP5MehdAkNGevOdioZgagFZyNxAjMHuKn7jIxTCg,31848
|
5
|
+
reydb/rconfig.py,sha256=4-SRhwhd3GqGiRhwbAjCfxVz6tBOQ2ab6n_lrb35rUE,12694
|
6
|
+
reydb/rconn.py,sha256=SWiKB9XZ4o5RT6M6L2vwp5bGYaZfrhGBSjfBOvwoq74,6513
|
7
|
+
reydb/rdb.py,sha256=pShuWWxsliXS1QZNZaxvrArtO0RIp0kwQ6Xwl9eWBVo,11502
|
8
|
+
reydb/rerror.py,sha256=f713YXSwWgls5352KvvX9LiTT_PcsPjZcSjZnFbFbVo,9939
|
9
|
+
reydb/rexec.py,sha256=o-VnFDprMeaQlQIX5_cHXHHchR5hRHWeJuFIqhVjBQ0,52835
|
10
|
+
reydb/rfile.py,sha256=N-uJRT2PFDNv1gKyHAb9t8n8xPOdic3SpzML-C0Bi-0,15180
|
11
|
+
reydb/rinfo.py,sha256=qW9QoGuMaMO2Fr76FCETE0TES_4CscagAceZtXc2qsU,12749
|
12
|
+
reydb/rorm.py,sha256=Jvv2D2bGFle-P34j00er2hwrrSChfDvsCvdQNpkSRPQ,23691
|
13
|
+
reydb/rparam.py,sha256=2S3uuZ42ieGbc-0W202h6aM-chDMbp4qr-AWzOtk7vk,9629
|
14
|
+
reydb-1.1.58.dist-info/METADATA,sha256=ItDedY0Q2A3dIPqyv9Bcs7DojtgQxBgZi_3JuBvObP8,1622
|
15
|
+
reydb-1.1.58.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
reydb-1.1.58.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
+
reydb-1.1.58.dist-info/RECORD,,
|
reydb-1.1.56.dist-info/RECORD
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
reydb/__init__.py,sha256=vwShFPkCDpLTrVGCq1AZgKCGQ8tBBodCxrvrib9ptrs,574
|
2
|
-
reydb/rall.py,sha256=GsXHqvT1k--U53HpDY4SALjIHN8rwgSxeXpJjH5gq2E,409
|
3
|
-
reydb/rbase.py,sha256=rgAkEHLXDoMfiNCN2ckPQD-Eyd1tp0f122LEbI7L1Qg,8947
|
4
|
-
reydb/rbuild.py,sha256=6N8aLqCeX8JnOwQstVA2AuM0Rl5kUHx5Enrm2GGcGvo,31852
|
5
|
-
reydb/rconfig.py,sha256=UTpJ9psCrQlFx3FJ5_B8WkURRQ5PD6ZHLYg7MQRebmU,12659
|
6
|
-
reydb/rconn.py,sha256=VgzoI5gMHi5yMyUpLsPuMmuFkYDHCc0uuRXh_yUPY94,6551
|
7
|
-
reydb/rdb.py,sha256=p0JOcuA1peG9aZ1FIDMZ6z7-PY5_Pup-OM291NUIl28,15937
|
8
|
-
reydb/rerror.py,sha256=Lsl7UECYdIFYjd9t7RhvNcHdyGStI3gffm8zmkK1DEc,9943
|
9
|
-
reydb/rexec.py,sha256=sTb9IOldf6USK-Qo9xV03wHlniU7xAQHYZZKT3B0jPA,54099
|
10
|
-
reydb/rfile.py,sha256=RI1jMsNNJWvdky3oRV1Gw-9-tc1F92QjD24s2eusCVI,15184
|
11
|
-
reydb/rinfo.py,sha256=4btKBBZzVXGuPsmswqXDxvjZQuAc9raQ0tpXvmft71s,12741
|
12
|
-
reydb/rorm.py,sha256=JUwKZ9OgrI_FvTwTDfZhozpJB1v1xk_o3ESPLGTXXYI,23693
|
13
|
-
reydb/rparam.py,sha256=six7wwQRKycoscv-AGyQqsPjA4_TZgcGQ_jk7FZytQs,6803
|
14
|
-
reydb-1.1.56.dist-info/METADATA,sha256=9jzfWPm0Mi2zoM-j6JG8XC0NWfjl9HfcN87p5IIIFeU,1598
|
15
|
-
reydb-1.1.56.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
-
reydb-1.1.56.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
17
|
-
reydb-1.1.56.dist-info/RECORD,,
|
File without changes
|
File without changes
|