reydb 1.1.27__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 +1 -0
- reydb/rall.py +1 -0
- reydb/rbase.py +2 -2
- reydb/rbuild.py +17 -14
- reydb/rconn.py +4 -11
- reydb/rdb.py +76 -59
- reydb/rexec.py +23 -23
- reydb/rfile.py +40 -15
- reydb/rinfo.py +55 -55
- reydb/rlog.py +303 -0
- reydb/rparam.py +14 -13
- {reydb-1.1.27.dist-info → reydb-1.1.29.dist-info}/METADATA +1 -1
- reydb-1.1.29.dist-info/RECORD +15 -0
- reydb-1.1.27.dist-info/RECORD +0 -14
- {reydb-1.1.27.dist-info → reydb-1.1.29.dist-info}/WHEEL +0 -0
- {reydb-1.1.27.dist-info → reydb-1.1.29.dist-info}/licenses/LICENSE +0 -0
reydb/rfile.py
CHANGED
@@ -14,36 +14,33 @@ from datetime import datetime
|
|
14
14
|
from reykit.rbase import throw
|
15
15
|
from reykit.ros import File, Folder, get_md5
|
16
16
|
|
17
|
-
from .rbase import
|
18
|
-
from .rconn import
|
17
|
+
from .rbase import DatabaseBase
|
18
|
+
from .rconn import DatabaseConnection
|
19
19
|
from .rdb import Database
|
20
20
|
|
21
21
|
|
22
22
|
__all__ = (
|
23
|
-
'
|
23
|
+
'DatabaseFile',
|
24
24
|
)
|
25
25
|
|
26
26
|
|
27
27
|
FileInfo = TypedDict('FileInfo', {'create_time': datetime, 'md5': str, 'name': str | None, 'size': int, 'note': str | None})
|
28
28
|
|
29
29
|
|
30
|
-
class
|
30
|
+
class DatabaseFile(DatabaseBase):
|
31
31
|
"""
|
32
32
|
Database file type.
|
33
33
|
Can create database used `self.build` method.
|
34
34
|
"""
|
35
35
|
|
36
36
|
|
37
|
-
def __init__(
|
38
|
-
self,
|
39
|
-
database: Database | DBConnection
|
40
|
-
) -> None:
|
37
|
+
def __init__(self, database: Database | DatabaseConnection) -> None:
|
41
38
|
"""
|
42
39
|
Build instance attributes.
|
43
40
|
|
44
41
|
Parameters
|
45
42
|
----------
|
46
|
-
database : Database or
|
43
|
+
database : Database or DatabaseConnection instance.
|
47
44
|
"""
|
48
45
|
|
49
46
|
# SQLite.
|
@@ -51,7 +48,7 @@ class DBFile(BaseDatabase):
|
|
51
48
|
text='not suitable for SQLite databases'
|
52
49
|
throw(AssertionError, text=text)
|
53
50
|
|
54
|
-
#
|
51
|
+
# Build.
|
55
52
|
self.database = database
|
56
53
|
|
57
54
|
## Database path name.
|
@@ -64,7 +61,7 @@ class DBFile(BaseDatabase):
|
|
64
61
|
}
|
65
62
|
|
66
63
|
|
67
|
-
def
|
64
|
+
def build_db(self) -> None:
|
68
65
|
"""
|
69
66
|
Check and build all standard databases and tables, by `self.db_names`.
|
70
67
|
"""
|
@@ -203,7 +200,34 @@ class DBFile(BaseDatabase):
|
|
203
200
|
'comment': 'File information count.'
|
204
201
|
},
|
205
202
|
{
|
206
|
-
'name': '
|
203
|
+
'name': 'past_day_count',
|
204
|
+
'select': (
|
205
|
+
'SELECT COUNT(1)\n'
|
206
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.information']}`\n'
|
207
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) = 0'
|
208
|
+
),
|
209
|
+
'comment': 'File information count in the past day.'
|
210
|
+
},
|
211
|
+
{
|
212
|
+
'name': 'past_week_count',
|
213
|
+
'select': (
|
214
|
+
'SELECT COUNT(1)\n'
|
215
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.information']}`\n'
|
216
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 6'
|
217
|
+
),
|
218
|
+
'comment': 'File information count in the past week.'
|
219
|
+
},
|
220
|
+
{
|
221
|
+
'name': 'past_month_count',
|
222
|
+
'select': (
|
223
|
+
'SELECT COUNT(1)\n'
|
224
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.information']}`\n'
|
225
|
+
'WHERE TIMESTAMPDIFF(DAY, `create_time`, NOW()) <= 29'
|
226
|
+
),
|
227
|
+
'comment': 'File information count in the past month.'
|
228
|
+
},
|
229
|
+
{
|
230
|
+
'name': 'data_count',
|
207
231
|
'select': (
|
208
232
|
'SELECT COUNT(1)\n'
|
209
233
|
f'FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`'
|
@@ -211,7 +235,7 @@ class DBFile(BaseDatabase):
|
|
211
235
|
'comment': 'File data unique count.'
|
212
236
|
},
|
213
237
|
{
|
214
|
-
'name': '
|
238
|
+
'name': 'total_size',
|
215
239
|
'select': (
|
216
240
|
'SELECT FORMAT(SUM(`size`), 0)\n'
|
217
241
|
f'FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`'
|
@@ -219,7 +243,7 @@ class DBFile(BaseDatabase):
|
|
219
243
|
'comment': 'File total byte size.'
|
220
244
|
},
|
221
245
|
{
|
222
|
-
'name': '
|
246
|
+
'name': 'avg_size',
|
223
247
|
'select': (
|
224
248
|
'SELECT FORMAT(AVG(`size`), 0)\n'
|
225
249
|
f'FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`'
|
@@ -227,7 +251,7 @@ class DBFile(BaseDatabase):
|
|
227
251
|
'comment': 'File average byte size.'
|
228
252
|
},
|
229
253
|
{
|
230
|
-
'name': '
|
254
|
+
'name': 'max_size',
|
231
255
|
'select': (
|
232
256
|
'SELECT FORMAT(MAX(`size`), 0)\n'
|
233
257
|
f'FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`'
|
@@ -243,6 +267,7 @@ class DBFile(BaseDatabase):
|
|
243
267
|
'comment': 'File last record create time.'
|
244
268
|
}
|
245
269
|
]
|
270
|
+
|
246
271
|
}
|
247
272
|
|
248
273
|
]
|
reydb/rinfo.py
CHANGED
@@ -13,42 +13,42 @@ from __future__ import annotations
|
|
13
13
|
from typing import Any, Literal, overload
|
14
14
|
from reykit.rbase import throw
|
15
15
|
|
16
|
-
from .rbase import
|
17
|
-
from .rconn import
|
16
|
+
from .rbase import DatabaseBase
|
17
|
+
from .rconn import DatabaseConnection
|
18
18
|
from .rdb import Database
|
19
19
|
|
20
20
|
|
21
21
|
__all__ = (
|
22
|
-
'
|
23
|
-
'
|
24
|
-
'
|
25
|
-
'
|
26
|
-
'
|
22
|
+
'DatabaseInformation',
|
23
|
+
'DatabaseInformationSchema',
|
24
|
+
'DatabaseInformationDatabase',
|
25
|
+
'DatabaseInformationTable',
|
26
|
+
'DatabaseInformationColumn'
|
27
27
|
)
|
28
28
|
|
29
29
|
|
30
|
-
class
|
30
|
+
class DatabaseInformation(DatabaseBase):
|
31
31
|
"""
|
32
32
|
Database base information type.
|
33
33
|
"""
|
34
34
|
|
35
35
|
|
36
36
|
@overload
|
37
|
-
def __call__(self:
|
37
|
+
def __call__(self: DatabaseInformationSchema | DatabaseInformationSchema | DatabaseInformationDatabase | DatabaseInformationTable) -> list[dict]: ...
|
38
38
|
|
39
39
|
@overload
|
40
|
-
def __call__(self:
|
40
|
+
def __call__(self: DatabaseInformationSchema, name: str) -> DatabaseInformationDatabase: ...
|
41
41
|
|
42
42
|
@overload
|
43
|
-
def __call__(self:
|
43
|
+
def __call__(self: DatabaseInformationDatabase, name: str) -> DatabaseInformationTable: ...
|
44
44
|
|
45
45
|
@overload
|
46
|
-
def __call__(self:
|
46
|
+
def __call__(self: DatabaseInformationTable, name: str) -> DatabaseInformationColumn: ...
|
47
47
|
|
48
48
|
@overload
|
49
|
-
def __call__(self:
|
49
|
+
def __call__(self: DatabaseInformationColumn) -> dict: ...
|
50
50
|
|
51
|
-
def __call__(self, name: str | None = None) ->
|
51
|
+
def __call__(self, name: str | None = None) -> DatabaseInformationDatabase | DatabaseInformationTable | DatabaseInformationColumn | list[dict] | dict:
|
52
52
|
"""
|
53
53
|
Get information table or subclass instance.
|
54
54
|
|
@@ -127,15 +127,15 @@ class DBInformation(BaseDatabase):
|
|
127
127
|
|
128
128
|
|
129
129
|
@overload
|
130
|
-
def __getattr__(self:
|
130
|
+
def __getattr__(self: DatabaseInformationSchema, name: str) -> DatabaseInformationDatabase: ...
|
131
131
|
|
132
132
|
@overload
|
133
|
-
def __getattr__(self:
|
133
|
+
def __getattr__(self: DatabaseInformationDatabase, name: str) -> DatabaseInformationTable: ...
|
134
134
|
|
135
135
|
@overload
|
136
|
-
def __getattr__(self:
|
136
|
+
def __getattr__(self: DatabaseInformationTable, name: str) -> DatabaseInformationColumn: ...
|
137
137
|
|
138
|
-
def __getattr__(self, name: str) ->
|
138
|
+
def __getattr__(self, name: str) -> DatabaseInformationDatabase | DatabaseInformationTable | DatabaseInformationColumn:
|
139
139
|
"""
|
140
140
|
Build subclass instance.
|
141
141
|
|
@@ -150,57 +150,57 @@ class DBInformation(BaseDatabase):
|
|
150
150
|
|
151
151
|
# Build.
|
152
152
|
match self:
|
153
|
-
case
|
154
|
-
table =
|
155
|
-
case
|
156
|
-
table =
|
157
|
-
case
|
158
|
-
table =
|
153
|
+
case DatabaseInformationSchema():
|
154
|
+
table = DatabaseInformationDatabase(self._rdatabase, name)
|
155
|
+
case DatabaseInformationDatabase():
|
156
|
+
table = DatabaseInformationTable(self._rdatabase, self._database_name, name)
|
157
|
+
case DatabaseInformationTable():
|
158
|
+
table = DatabaseInformationColumn(self._rdatabase, self._database_name, self._table_name, name)
|
159
159
|
case _:
|
160
160
|
raise AssertionError("class '%s' does not have this method" % type(self).__name__)
|
161
161
|
|
162
162
|
return table
|
163
163
|
|
164
164
|
|
165
|
-
class
|
165
|
+
class DatabaseInformationSchema(DatabaseInformation):
|
166
166
|
"""
|
167
167
|
Database information schema type.
|
168
168
|
|
169
169
|
Examples
|
170
170
|
--------
|
171
171
|
Get databases information of server.
|
172
|
-
>>> databases_info =
|
172
|
+
>>> databases_info = DatabaseInformationSchema()
|
173
173
|
|
174
174
|
Get tables information of database.
|
175
|
-
>>> tables_info =
|
175
|
+
>>> tables_info = DatabaseInformationSchema.database()
|
176
176
|
|
177
177
|
Get columns information of table.
|
178
|
-
>>> columns_info =
|
178
|
+
>>> columns_info = DatabaseInformationSchema.database.table()
|
179
179
|
|
180
180
|
Get column information.
|
181
|
-
>>> column_info =
|
181
|
+
>>> column_info = DatabaseInformationSchema.database.table.column()
|
182
182
|
|
183
183
|
Get database attribute.
|
184
|
-
>>> database_attr =
|
184
|
+
>>> database_attr = DatabaseInformationSchema.database['attribute']
|
185
185
|
|
186
186
|
Get table attribute.
|
187
|
-
>>> database_attr =
|
187
|
+
>>> database_attr = DatabaseInformationSchema.database.table['attribute']
|
188
188
|
|
189
189
|
Get column attribute.
|
190
|
-
>>> database_attr =
|
190
|
+
>>> database_attr = DatabaseInformationSchema.database.table.column['attribute']
|
191
191
|
"""
|
192
192
|
|
193
193
|
|
194
194
|
def __init__(
|
195
195
|
self,
|
196
|
-
rdatabase: Database |
|
196
|
+
rdatabase: Database | DatabaseConnection
|
197
197
|
) -> None:
|
198
198
|
"""
|
199
199
|
Build instance attributes.
|
200
200
|
|
201
201
|
Parameters
|
202
202
|
----------
|
203
|
-
rdatabase : Database or
|
203
|
+
rdatabase : Database or DatabaseConnection instance.
|
204
204
|
"""
|
205
205
|
|
206
206
|
# Set parameter.
|
@@ -233,35 +233,35 @@ class DBISchema(DBInformation):
|
|
233
233
|
return info_table
|
234
234
|
|
235
235
|
|
236
|
-
class
|
236
|
+
class DatabaseInformationDatabase(DatabaseInformation):
|
237
237
|
"""
|
238
238
|
Database information database type.
|
239
239
|
|
240
240
|
Examples
|
241
241
|
--------
|
242
242
|
Get tables information of database.
|
243
|
-
>>> tables_info =
|
243
|
+
>>> tables_info = DatabaseInformationDatabase()
|
244
244
|
|
245
245
|
Get columns information of table.
|
246
|
-
>>> columns_info =
|
246
|
+
>>> columns_info = DatabaseInformationDatabase.table()
|
247
247
|
|
248
248
|
Get column information.
|
249
|
-
>>> column_info =
|
249
|
+
>>> column_info = DatabaseInformationDatabase.table.column()
|
250
250
|
|
251
251
|
Get database attribute.
|
252
|
-
>>> database_attr =
|
252
|
+
>>> database_attr = DatabaseInformationDatabase['attribute']
|
253
253
|
|
254
254
|
Get table attribute.
|
255
|
-
>>> database_attr =
|
255
|
+
>>> database_attr = DatabaseInformationDatabase.table['attribute']
|
256
256
|
|
257
257
|
Get column attribute.
|
258
|
-
>>> database_attr =
|
258
|
+
>>> database_attr = DatabaseInformationDatabase.table.column['attribute']
|
259
259
|
"""
|
260
260
|
|
261
261
|
|
262
262
|
def __init__(
|
263
263
|
self,
|
264
|
-
rdatabase: Database |
|
264
|
+
rdatabase: Database | DatabaseConnection,
|
265
265
|
database_name: str
|
266
266
|
) -> None:
|
267
267
|
"""
|
@@ -269,7 +269,7 @@ class DBIDatabase(DBInformation):
|
|
269
269
|
|
270
270
|
Parameters
|
271
271
|
----------
|
272
|
-
rdatabase : Database or
|
272
|
+
rdatabase : Database or DatabaseConnection instance.
|
273
273
|
database_name : Database name.
|
274
274
|
"""
|
275
275
|
|
@@ -352,29 +352,29 @@ class DBIDatabase(DBInformation):
|
|
352
352
|
return info_table
|
353
353
|
|
354
354
|
|
355
|
-
class
|
355
|
+
class DatabaseInformationTable(DatabaseInformation):
|
356
356
|
"""
|
357
357
|
Database information table type.
|
358
358
|
|
359
359
|
Examples
|
360
360
|
--------
|
361
361
|
Get columns information of table.
|
362
|
-
>>> columns_info =
|
362
|
+
>>> columns_info = DatabaseInformationTable()
|
363
363
|
|
364
364
|
Get column information.
|
365
|
-
>>> column_info =
|
365
|
+
>>> column_info = DatabaseInformationTable.column()
|
366
366
|
|
367
367
|
Get table attribute.
|
368
|
-
>>> database_attr =
|
368
|
+
>>> database_attr = DatabaseInformationTable['attribute']
|
369
369
|
|
370
370
|
Get column attribute.
|
371
|
-
>>> database_attr =
|
371
|
+
>>> database_attr = DatabaseInformationTable.column['attribute']
|
372
372
|
"""
|
373
373
|
|
374
374
|
|
375
375
|
def __init__(
|
376
376
|
self,
|
377
|
-
rdatabase: Database |
|
377
|
+
rdatabase: Database | DatabaseConnection,
|
378
378
|
database_name: str,
|
379
379
|
table_name: str
|
380
380
|
) -> None:
|
@@ -383,7 +383,7 @@ class DBITable(DBInformation):
|
|
383
383
|
|
384
384
|
Parameters
|
385
385
|
----------
|
386
|
-
rdatabase : Database or
|
386
|
+
rdatabase : Database or DatabaseConnection instance.
|
387
387
|
database_name : Database name.
|
388
388
|
table_name : Table name.
|
389
389
|
"""
|
@@ -473,23 +473,23 @@ class DBITable(DBInformation):
|
|
473
473
|
return info_table
|
474
474
|
|
475
475
|
|
476
|
-
class
|
476
|
+
class DatabaseInformationColumn(DatabaseInformation):
|
477
477
|
"""
|
478
478
|
Database information column type.
|
479
479
|
|
480
480
|
Examples
|
481
481
|
--------
|
482
482
|
Get column information.
|
483
|
-
>>> column_info =
|
483
|
+
>>> column_info = DatabaseInformationColumn()
|
484
484
|
|
485
485
|
Get column attribute.
|
486
|
-
>>> database_attr =
|
486
|
+
>>> database_attr = DatabaseInformationColumn['attribute']
|
487
487
|
"""
|
488
488
|
|
489
489
|
|
490
490
|
def __init__(
|
491
491
|
self,
|
492
|
-
rdatabase: Database |
|
492
|
+
rdatabase: Database | DatabaseConnection,
|
493
493
|
database_name: str,
|
494
494
|
table_name: str,
|
495
495
|
column_name: str
|
@@ -499,7 +499,7 @@ class DBIColumn(DBInformation):
|
|
499
499
|
|
500
500
|
Parameters
|
501
501
|
----------
|
502
|
-
rdatabase : Database or
|
502
|
+
rdatabase : Database or DatabaseConnection instance.
|
503
503
|
database_name : Database name.
|
504
504
|
table_name : Table name.
|
505
505
|
column_name : Column name.
|