reydb 1.1.23__py3-none-any.whl → 1.1.24__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/rfile.py
CHANGED
@@ -29,41 +29,43 @@ FileInfo = TypedDict('FileInfo', {'create_time': datetime, 'md5': str, 'name': s
|
|
29
29
|
class DBFile(BaseDatabase):
|
30
30
|
"""
|
31
31
|
Database file type.
|
32
|
+
Can create database used `self.build` method.
|
32
33
|
"""
|
33
34
|
|
34
35
|
|
35
36
|
def __init__(
|
36
37
|
self,
|
37
|
-
|
38
|
+
database: Database | DBConnection
|
38
39
|
) -> None:
|
39
40
|
"""
|
40
41
|
Build instance attributes.
|
41
42
|
|
42
43
|
Parameters
|
43
44
|
----------
|
44
|
-
|
45
|
+
database : Database or DBConnection instance.
|
45
46
|
"""
|
46
47
|
|
47
48
|
# SQLite.
|
48
|
-
if
|
49
|
+
if database.backend == 'sqlite':
|
49
50
|
text='not suitable for SQLite databases'
|
50
51
|
throw(AssertionError, text=text)
|
51
52
|
|
52
53
|
# Set attribute.
|
53
|
-
self.
|
54
|
+
self.database = database
|
54
55
|
|
55
56
|
## Database path name.
|
56
|
-
self.
|
57
|
+
self.db_names = {
|
57
58
|
'file': 'file',
|
58
59
|
'file.information': 'information',
|
59
60
|
'file.data': 'data',
|
60
|
-
'file.stats': 'stats'
|
61
|
+
'file.stats': 'stats',
|
62
|
+
'file.data_information': 'data_information'
|
61
63
|
}
|
62
64
|
|
63
65
|
|
64
66
|
def build(self) -> None:
|
65
67
|
"""
|
66
|
-
Check and build all standard databases and tables, by `self.
|
68
|
+
Check and build all standard databases and tables, by `self.db_names`.
|
67
69
|
"""
|
68
70
|
|
69
71
|
# Set parameter.
|
@@ -71,7 +73,7 @@ class DBFile(BaseDatabase):
|
|
71
73
|
## Database.
|
72
74
|
databases = [
|
73
75
|
{
|
74
|
-
'name': self.
|
76
|
+
'name': self.db_names['file']
|
75
77
|
}
|
76
78
|
]
|
77
79
|
|
@@ -80,7 +82,7 @@ class DBFile(BaseDatabase):
|
|
80
82
|
|
81
83
|
### 'information'.
|
82
84
|
{
|
83
|
-
'path': (self.
|
85
|
+
'path': (self.db_names['file'], self.db_names['file.information']),
|
84
86
|
'fields': [
|
85
87
|
{
|
86
88
|
'name': 'create_time',
|
@@ -92,7 +94,7 @@ class DBFile(BaseDatabase):
|
|
92
94
|
'name': 'file_id',
|
93
95
|
'type': 'mediumint unsigned',
|
94
96
|
'constraint': 'NOT NULL AUTO_INCREMENT',
|
95
|
-
'comment': 'File
|
97
|
+
'comment': 'File ID.'
|
96
98
|
},
|
97
99
|
{
|
98
100
|
'name': 'md5',
|
@@ -133,7 +135,7 @@ class DBFile(BaseDatabase):
|
|
133
135
|
|
134
136
|
### 'data'.
|
135
137
|
{
|
136
|
-
'path': (self.
|
138
|
+
'path': (self.db_names['file'], self.db_names['file.data']),
|
137
139
|
'fields': [
|
138
140
|
{
|
139
141
|
'name': 'md5',
|
@@ -165,17 +167,17 @@ class DBFile(BaseDatabase):
|
|
165
167
|
|
166
168
|
### Data information.
|
167
169
|
{
|
168
|
-
'path': ('file', 'data_information'),
|
170
|
+
'path': (self.db_names['file'], self.db_names['file.data_information']),
|
169
171
|
'select': (
|
170
172
|
'SELECT `b`.`last_time`, `a`.`md5`, `a`.`size`, `b`.`names`, `b`.`notes`\n'
|
171
|
-
'FROM `file`.`data` AS `a`\n'
|
173
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.data']}` AS `a`\n'
|
172
174
|
'LEFT JOIN (\n'
|
173
175
|
' SELECT\n'
|
174
176
|
' `md5`,\n'
|
175
177
|
" GROUP_CONCAT(DISTINCT(`name`) ORDER BY `create_time` DESC SEPARATOR ' | ') AS `names`,\n"
|
176
178
|
" GROUP_CONCAT(DISTINCT(`note`) ORDER BY `create_time` DESC SEPARATOR ' | ') AS `notes`,\n"
|
177
179
|
' MAX(`create_time`) as `last_time`\n'
|
178
|
-
' FROM `file`.`information`\n'
|
180
|
+
f' FROM `{self.db_names['file']}`.`{self.db_names['file.information']}`\n'
|
179
181
|
' GROUP BY `md5`\n'
|
180
182
|
' ORDER BY `last_time` DESC\n'
|
181
183
|
') AS `b`\n'
|
@@ -191,13 +193,13 @@ class DBFile(BaseDatabase):
|
|
191
193
|
|
192
194
|
### 'stats'.
|
193
195
|
{
|
194
|
-
'path': (self.
|
196
|
+
'path': (self.db_names['file'], self.db_names['file.stats']),
|
195
197
|
'items': [
|
196
198
|
{
|
197
199
|
'name': 'count',
|
198
200
|
'select': (
|
199
201
|
'SELECT COUNT(1)\n'
|
200
|
-
f'FROM `{self.
|
202
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.information']}`'
|
201
203
|
),
|
202
204
|
'comment': 'File information count.'
|
203
205
|
},
|
@@ -205,10 +207,21 @@ class DBFile(BaseDatabase):
|
|
205
207
|
'name': 'count_data',
|
206
208
|
'select': (
|
207
209
|
'SELECT COUNT(1)\n'
|
208
|
-
f'FROM `{self.
|
210
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`'
|
209
211
|
),
|
210
212
|
'comment': 'File data unique count.'
|
211
213
|
},
|
214
|
+
{
|
215
|
+
'name': 'size_sum',
|
216
|
+
'select': (
|
217
|
+
'SELECT CONCAT(\n'
|
218
|
+
' ROUND(SUM(`size`) / 1024),\n'
|
219
|
+
" ' KB'\n"
|
220
|
+
')\n'
|
221
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`'
|
222
|
+
),
|
223
|
+
'comment': 'File total size.'
|
224
|
+
},
|
212
225
|
{
|
213
226
|
'name': 'size_avg',
|
214
227
|
'select': (
|
@@ -216,7 +229,7 @@ class DBFile(BaseDatabase):
|
|
216
229
|
' ROUND(AVG(`size`) / 1024),\n'
|
217
230
|
" ' KB'\n"
|
218
231
|
')\n'
|
219
|
-
f'FROM `{self.
|
232
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`'
|
220
233
|
),
|
221
234
|
'comment': 'File average size.'
|
222
235
|
},
|
@@ -227,7 +240,7 @@ class DBFile(BaseDatabase):
|
|
227
240
|
' ROUND(MAX(`size`) / 1024),\n'
|
228
241
|
" ' KB'\n"
|
229
242
|
')\n'
|
230
|
-
f'FROM `{self.
|
243
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`'
|
231
244
|
),
|
232
245
|
'comment': 'File maximum size.'
|
233
246
|
},
|
@@ -235,7 +248,7 @@ class DBFile(BaseDatabase):
|
|
235
248
|
'name': 'last_time',
|
236
249
|
'select': (
|
237
250
|
'SELECT MAX(`create_time`)\n'
|
238
|
-
f'FROM `{self.
|
251
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.information']}`'
|
239
252
|
),
|
240
253
|
'comment': 'File last record create time.'
|
241
254
|
}
|
@@ -245,7 +258,7 @@ class DBFile(BaseDatabase):
|
|
245
258
|
]
|
246
259
|
|
247
260
|
# Build.
|
248
|
-
self.
|
261
|
+
self.database.build.build(databases, tables, views, views_stats)
|
249
262
|
|
250
263
|
|
251
264
|
def upload(
|
@@ -273,7 +286,7 @@ class DBFile(BaseDatabase):
|
|
273
286
|
"""
|
274
287
|
|
275
288
|
# Handle parameter.
|
276
|
-
conn = self.
|
289
|
+
conn = self.database.connect()
|
277
290
|
match source:
|
278
291
|
|
279
292
|
## File path.
|
@@ -300,7 +313,7 @@ class DBFile(BaseDatabase):
|
|
300
313
|
|
301
314
|
# Exist.
|
302
315
|
exist = conn.execute_exist(
|
303
|
-
(self.
|
316
|
+
(self.db_names['file'], self.db_names['file.data']),
|
304
317
|
'`md5` = :file_md5',
|
305
318
|
file_md5=file_md5
|
306
319
|
)
|
@@ -315,7 +328,7 @@ class DBFile(BaseDatabase):
|
|
315
328
|
'bytes': file_bytes
|
316
329
|
}
|
317
330
|
conn.execute_insert(
|
318
|
-
(self.
|
331
|
+
(self.db_names['file'], self.db_names['file.data']),
|
319
332
|
data,
|
320
333
|
'ignore'
|
321
334
|
)
|
@@ -327,7 +340,7 @@ class DBFile(BaseDatabase):
|
|
327
340
|
'note': note
|
328
341
|
}
|
329
342
|
conn.execute_insert(
|
330
|
-
(self.
|
343
|
+
(self.db_names['file'], self.db_names['file.information']),
|
331
344
|
data
|
332
345
|
)
|
333
346
|
|
@@ -380,17 +393,17 @@ class DBFile(BaseDatabase):
|
|
380
393
|
sql = (
|
381
394
|
'SELECT `name`, (\n'
|
382
395
|
' SELECT `bytes`\n'
|
383
|
-
f' FROM `{self.
|
384
|
-
f' WHERE `md5` = `{self.
|
396
|
+
f' FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`\n'
|
397
|
+
f' WHERE `md5` = `{self.db_names['file.information']}`.`md5`\n'
|
385
398
|
' LIMIT 1\n'
|
386
399
|
') AS `bytes`\n'
|
387
|
-
f'FROM `{self.
|
400
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.information']}`\n'
|
388
401
|
'WHERE `file_id` = :file_id\n'
|
389
402
|
'LIMIT 1'
|
390
403
|
)
|
391
404
|
|
392
405
|
# Execute SQL.
|
393
|
-
result = self.
|
406
|
+
result = self.database.execute(sql, file_id=file_id)
|
394
407
|
|
395
408
|
# Check.
|
396
409
|
if result.empty:
|
@@ -432,17 +445,17 @@ class DBFile(BaseDatabase):
|
|
432
445
|
sql = (
|
433
446
|
'SELECT `create_time`, `md5`, `name`, `note`, (\n'
|
434
447
|
' SELECT `size`\n'
|
435
|
-
f' FROM `{self.
|
448
|
+
f' FROM `{self.db_names['file']}`.`{self.db_names['file.data']}`\n'
|
436
449
|
' WHERE `md5` = `a`.`md5`\n'
|
437
450
|
' LIMIT 1\n'
|
438
451
|
') AS `size`\n'
|
439
|
-
f'FROM `{self.
|
452
|
+
f'FROM `{self.db_names['file']}`.`{self.db_names['file.information']}` AS `a`\n'
|
440
453
|
'WHERE `file_id` = :file_id\n'
|
441
454
|
'LIMIT 1'
|
442
455
|
)
|
443
456
|
|
444
457
|
# Execute SQL.
|
445
|
-
result = self.
|
458
|
+
result = self.database.execute(sql, file_id=file_id)
|
446
459
|
|
447
460
|
# Check.
|
448
461
|
if result.empty:
|
@@ -453,6 +466,3 @@ class DBFile(BaseDatabase):
|
|
453
466
|
info = table[0]
|
454
467
|
|
455
468
|
return info
|
456
|
-
|
457
|
-
|
458
|
-
__call__ = build
|
@@ -5,10 +5,10 @@ reydb/rbuild.py,sha256=ppsaGWTC3S-zwQDj3keL3oF5TddORTuEpfqNElj6thU,32327
|
|
5
5
|
reydb/rconn.py,sha256=ZZDssqBCb1GQT61xG1N96-wYwISTIlKO1nJkgBuwBlI,6507
|
6
6
|
reydb/rdb.py,sha256=VVytmnw07MFC-gc3JzjJC50SJTXA0H-oy_pFtYf_ras,60895
|
7
7
|
reydb/rexec.py,sha256=kc5xSfuEDFW9rcAeJj_x6JWPDSYnHZQXcfSBXFGIhL8,8893
|
8
|
-
reydb/rfile.py,sha256=
|
8
|
+
reydb/rfile.py,sha256=QQBsWB-ulumdmCcOnTOLiOKYFUpBmGWb0IZCI3aCo58,14275
|
9
9
|
reydb/rinfo.py,sha256=NhcFhzp9gQ49EpAqcFYXcG-FMUXu3qii8WGoHxN6UcQ,14250
|
10
10
|
reydb/rparam.py,sha256=EVSz_D4wyiaj5ZKxvdDcECmpbriOUNBBFCzz4bnV6dY,6838
|
11
|
-
reydb-1.1.
|
12
|
-
reydb-1.1.
|
13
|
-
reydb-1.1.
|
14
|
-
reydb-1.1.
|
11
|
+
reydb-1.1.24.dist-info/METADATA,sha256=9vreMU2KglvIkMrUXQl_ZIRdfNEpTiBZmP0is-Pkg_8,1550
|
12
|
+
reydb-1.1.24.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
13
|
+
reydb-1.1.24.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
|
14
|
+
reydb-1.1.24.dist-info/RECORD,,
|
File without changes
|
File without changes
|