reydb 1.1.60__py3-none-any.whl → 1.1.61__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/rinfo.py DELETED
@@ -1,499 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2022-12-05 14:10:02
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Database information methods.
9
- """
10
-
11
-
12
- from typing import Any, Literal, overload
13
-
14
- from . import rdb
15
- from .rbase import DatabaseBase
16
-
17
-
18
- __all__ = (
19
- 'DatabaseInformation',
20
- 'DatabaseInformationSchema',
21
- 'DatabaseInformationDatabase',
22
- 'DatabaseInformationTable',
23
- 'DatabaseInformationColumn'
24
- )
25
-
26
-
27
- class DatabaseInformation(DatabaseBase):
28
- """
29
- Database base information type.
30
- """
31
-
32
-
33
- @overload
34
- def __call__(self: 'DatabaseInformationSchema | DatabaseInformationSchema | DatabaseInformationDatabase | DatabaseInformationTable') -> list[dict]: ...
35
-
36
- @overload
37
- def __call__(self: 'DatabaseInformationSchema', name: str) -> 'DatabaseInformationDatabase': ...
38
-
39
- @overload
40
- def __call__(self: 'DatabaseInformationDatabase', name: str) -> 'DatabaseInformationTable': ...
41
-
42
- @overload
43
- def __call__(self: 'DatabaseInformationTable', name: str) -> 'DatabaseInformationColumn': ...
44
-
45
- @overload
46
- def __call__(self: 'DatabaseInformationColumn') -> dict: ...
47
-
48
- def __call__(self, name: str | None = None) -> 'DatabaseInformationDatabase | DatabaseInformationTable | DatabaseInformationColumn | list[dict] | dict':
49
- """
50
- Get information table or subclass instance.
51
-
52
- Parameters
53
- ----------
54
- name : Subclass index name.
55
-
56
- Returns
57
- -------
58
- Information table or subclass instance.
59
- """
60
-
61
- # Information table.
62
- if name is None:
63
-
64
- ## Break.
65
- if not hasattr(self, '_get_info_table'):
66
- raise AssertionError("class '%s' does not have this method" % type(self).__name__)
67
-
68
- ## Get.
69
- result: list[dict] = self._get_info_table()
70
-
71
- # Subobject.
72
- else:
73
-
74
- ## Break.
75
- if not hasattr(self, '__getattr__'):
76
- raise AssertionError("class '%s' does not have this method" % type(self).__name__)
77
-
78
- ## Get.
79
- result = self.__getattr__(name)
80
-
81
- return result
82
-
83
-
84
- @overload
85
- def __getitem__(self, key: Literal['*', 'all', 'ALL']) -> dict: ...
86
-
87
- @overload
88
- def __getitem__(self, key: str) -> Any: ...
89
-
90
- def __getitem__(self, key: str) -> Any:
91
- """
92
- Get information attribute value or dictionary.
93
-
94
- Parameters
95
- ----------
96
- key : Attribute key. When key not exist, then try all caps key.
97
- - `Literal['*', 'all', 'ALL']`: Get attribute dictionary.
98
- - `str`: Get attribute value.
99
-
100
- Returns
101
- -------
102
- Information attribute value or dictionary.
103
- """
104
-
105
- # Break.
106
- if not hasattr(self, '_get_info_attrs'):
107
- raise AssertionError("class '%s' does not have this method" % type(self).__name__)
108
-
109
- # Get.
110
- info_attrs: dict = self._get_info_attrs()
111
-
112
- # Return.
113
-
114
- ## Dictionary.
115
- if key in ('*', 'all', 'ALL'):
116
- return info_attrs
117
-
118
- ## Value.
119
- info_attr = info_attrs.get(key)
120
- if info_attr is None:
121
- key_upper = key.upper()
122
- info_attr = info_attrs[key_upper]
123
- return info_attr
124
-
125
-
126
- @overload
127
- def __getattr__(self: 'DatabaseInformationSchema', name: str) -> 'DatabaseInformationDatabase': ...
128
-
129
- @overload
130
- def __getattr__(self: 'DatabaseInformationDatabase', name: str) -> 'DatabaseInformationTable': ...
131
-
132
- @overload
133
- def __getattr__(self: 'DatabaseInformationTable', name: str) -> 'DatabaseInformationColumn': ...
134
-
135
- def __getattr__(self, name: str) -> 'DatabaseInformationDatabase | DatabaseInformationTable | DatabaseInformationColumn':
136
- """
137
- Build subclass instance.
138
-
139
- Parameters
140
- ----------
141
- key : Table name.
142
-
143
- Returns
144
- -------
145
- Subclass instance.
146
- """
147
-
148
- # Build.
149
- match self:
150
- case DatabaseInformationSchema():
151
- table = DatabaseInformationDatabase(self.db, name)
152
- case DatabaseInformationDatabase():
153
- table = DatabaseInformationTable(self.db, self.database, name)
154
- case DatabaseInformationTable():
155
- table = DatabaseInformationColumn(self.db, self.database, self.table, name)
156
- case _:
157
- raise AssertionError("class '%s' does not have this method" % type(self).__name__)
158
-
159
- return table
160
-
161
-
162
- class DatabaseInformationSchema(DatabaseInformation):
163
- """
164
- Database information schema type.
165
-
166
- Examples
167
- --------
168
- Get databases information of server.
169
- >>> databases_info = DatabaseInformationSchema()
170
-
171
- Get tables information of database.
172
- >>> tables_info = DatabaseInformationSchema.database()
173
-
174
- Get columns information of table.
175
- >>> columns_info = DatabaseInformationSchema.database.table()
176
-
177
- Get column information.
178
- >>> column_info = DatabaseInformationSchema.database.table.column()
179
-
180
- Get database attribute.
181
- >>> database_attr = DatabaseInformationSchema.database['attribute']
182
-
183
- Get table attribute.
184
- >>> database_attr = DatabaseInformationSchema.database.table['attribute']
185
-
186
- Get column attribute.
187
- >>> database_attr = DatabaseInformationSchema.database.table.column['attribute']
188
- """
189
-
190
-
191
- def __init__(
192
- self,
193
- db: 'rdb.Database'
194
- ) -> None:
195
- """
196
- Build instance attributes.
197
-
198
- Parameters
199
- ----------
200
- db: Database instance.
201
- """
202
-
203
- # Set parameter.
204
- self.db = db
205
-
206
-
207
- def _get_info_table(self) -> list[dict]:
208
- """
209
- Get information table.
210
-
211
- Returns
212
- -------
213
- Information table.
214
- """
215
-
216
- # Select.
217
- result = self.db.execute.select(
218
- 'information_schema.SCHEMATA',
219
- order='`schema_name`'
220
- )
221
-
222
- # Convert.
223
- info_table = result.to_table()
224
-
225
- return info_table
226
-
227
-
228
- class DatabaseInformationDatabase(DatabaseInformation):
229
- """
230
- Database information database type.
231
-
232
- Examples
233
- --------
234
- Get tables information of database.
235
- >>> tables_info = DatabaseInformationDatabase()
236
-
237
- Get columns information of table.
238
- >>> columns_info = DatabaseInformationDatabase.table()
239
-
240
- Get column information.
241
- >>> column_info = DatabaseInformationDatabase.table.column()
242
-
243
- Get database attribute.
244
- >>> database_attr = DatabaseInformationDatabase['attribute']
245
-
246
- Get table attribute.
247
- >>> database_attr = DatabaseInformationDatabase.table['attribute']
248
-
249
- Get column attribute.
250
- >>> database_attr = DatabaseInformationDatabase.table.column['attribute']
251
- """
252
-
253
-
254
- def __init__(
255
- self,
256
- db: 'rdb.Database',
257
- database: str
258
- ) -> None:
259
- """
260
- Build instance attributes.
261
-
262
- Parameters
263
- ----------
264
- db: Database instance.
265
- database : Database name.
266
- """
267
-
268
- # Set parameter.
269
- self.db = db
270
- self.database = database
271
-
272
-
273
- def _get_info_attrs(self) -> dict:
274
- """
275
- Get information attribute dictionary.
276
-
277
- Returns
278
- -------
279
- Information attribute dictionary.
280
- """
281
-
282
- # Select.
283
- where = '`SCHEMA_NAME` = :database'
284
- result = self.db.execute.select(
285
- 'information_schema.SCHEMATA',
286
- where=where,
287
- limit=1,
288
- database=self.database
289
- )
290
-
291
- # Convert.
292
- info_table = result.to_table()
293
-
294
- ## Check.
295
- assert len(info_table) != 0, "database '%s' not exist" % self.database
296
-
297
- info_attrs = info_table[0]
298
-
299
- return info_attrs
300
-
301
-
302
- def _get_info_table(self) -> list[dict]:
303
- """
304
- Get information table.
305
-
306
- Returns
307
- -------
308
- Information table.
309
- """
310
-
311
- # Select.
312
- where = '`TABLE_SCHEMA` = :database'
313
- result = self.db.execute.select(
314
- 'information_schema.TABLES',
315
- where=where,
316
- order='`TABLE_NAME`',
317
- database=self.database
318
- )
319
-
320
- # Convert.
321
- info_table = result.to_table()
322
-
323
- ## Check.
324
- assert len(info_table) != 0, "database '%s' not exist" % self.database
325
-
326
- return info_table
327
-
328
-
329
- class DatabaseInformationTable(DatabaseInformation):
330
- """
331
- Database information table type.
332
-
333
- Examples
334
- --------
335
- Get columns information of table.
336
- >>> columns_info = DatabaseInformationTable()
337
-
338
- Get column information.
339
- >>> column_info = DatabaseInformationTable.column()
340
-
341
- Get table attribute.
342
- >>> database_attr = DatabaseInformationTable['attribute']
343
-
344
- Get column attribute.
345
- >>> database_attr = DatabaseInformationTable.column['attribute']
346
- """
347
-
348
-
349
- def __init__(
350
- self,
351
- db: 'rdb.Database',
352
- database: str,
353
- table: str
354
- ) -> None:
355
- """
356
- Build instance attributes.
357
-
358
- Parameters
359
- ----------
360
- db: Database instance.
361
- database : Database name.
362
- table : Table name.
363
- """
364
-
365
- # Set parameter.
366
- self.db = db
367
- self.database = database
368
- self.table = table
369
-
370
-
371
- def _get_info_attrs(self) -> dict:
372
- """
373
- Get information attribute dictionary.
374
-
375
- Returns
376
- -------
377
- Information attribute dictionary.
378
- """
379
-
380
- # Select.
381
- where = '`TABLE_SCHEMA` = :database AND `TABLE_NAME` = :table_'
382
- result = self.db.execute.select(
383
- 'information_schema.TABLES',
384
- where=where,
385
- limit=1,
386
- database=self.database,
387
- table_=self.table
388
- )
389
-
390
- # Convert.
391
- info_table = result.to_table()
392
-
393
- ## Check.
394
- assert len(info_table) != 0, "database '%s' or table '%s' not exist" % (self.database, self.table)
395
-
396
- info_attrs = info_table[0]
397
-
398
- return info_attrs
399
-
400
-
401
- def _get_info_table(self) -> list[dict]:
402
- """
403
- Get information table.
404
-
405
- Returns
406
- -------
407
- Information table.
408
- """
409
-
410
- # Select.
411
- where = '`TABLE_SCHEMA` = :database AND `TABLE_NAME` = :table_'
412
- result = self.db.execute.select(
413
- 'information_schema.COLUMNS',
414
- where=where,
415
- order='`ORDINAL_POSITION`',
416
- database=self.database,
417
- table_=self.table
418
- )
419
-
420
- # Convert.
421
- info_table = result.to_table()
422
-
423
- ## Check.
424
- assert len(info_table) != 0, "database '%s' or table '%s' not exist" % (self.database, self.table)
425
-
426
- return info_table
427
-
428
-
429
- class DatabaseInformationColumn(DatabaseInformation):
430
- """
431
- Database information column type.
432
-
433
- Examples
434
- --------
435
- Get column information.
436
- >>> column_info = DatabaseInformationColumn()
437
-
438
- Get column attribute.
439
- >>> database_attr = DatabaseInformationColumn['attribute']
440
- """
441
-
442
-
443
- def __init__(
444
- self,
445
- db: 'rdb.Database',
446
- database: str,
447
- table: str,
448
- column: str
449
- ) -> None:
450
- """
451
- Build instance attributes.
452
-
453
- Parameters
454
- ----------
455
- db: Database instance.
456
- database : Database name.
457
- table : Table name.
458
- column : Column name.
459
- """
460
-
461
- # Set parameter.
462
- self.db = db
463
- self.database = database
464
- self.table = table
465
- self.column = column
466
-
467
-
468
- def _get_info_attrs(self) -> dict:
469
- """
470
- Get information attribute dictionary.
471
-
472
- Returns
473
- -------
474
- Information attribute dictionary.
475
- """
476
-
477
- # Select.
478
- where = '`TABLE_SCHEMA` = :database AND `TABLE_NAME` = :table_ AND `COLUMN_NAME` = :column'
479
- result = self.db.execute.select(
480
- 'information_schema.COLUMNS',
481
- where=where,
482
- limit=1,
483
- database=self.database,
484
- table_=self.table,
485
- column=self.column
486
- )
487
-
488
- # Convert.
489
- info_table = result.to_table()
490
-
491
- ## Check.
492
- assert len(info_table) != 0, "database '%s' or table '%s' or column '%s' not exist" % (self.database, self.table, self.column)
493
-
494
- info_attrs = info_table[0]
495
-
496
- return info_attrs
497
-
498
-
499
- _get_info_table = _get_info_attrs
@@ -1,17 +0,0 @@
1
- reydb/__init__.py,sha256=h6duExQWsPCz3qKnTIHTslmqcBC63HCQvwiumg8oCVc,620
2
- reydb/rall.py,sha256=GsXHqvT1k--U53HpDY4SALjIHN8rwgSxeXpJjH5gq2E,409
3
- reydb/rbase.py,sha256=16fG_YWnvJFu0ElXvc3BS9PtSJFZ9M631Te0b2ewWDE,9457
4
- reydb/rbuild.py,sha256=72faSm2mrtjeWqLSxiXkeG5fg0XB25mNo2MBFotE9m8,46413
5
- reydb/rconfig.py,sha256=LWm3aTypt1u7zMmdq0p4K8d6JgT3hfWd_3RAlj3jS0I,10921
6
- reydb/rconn.py,sha256=guRaR8N6RuzZzujwaeq7HhKWTizF9SrUBqEAFjfjpoo,6909
7
- reydb/rdb.py,sha256=VM7nY-oynRWh4tFa2ZhXyJQ2Dm_cZbU2UVyW9e5NtFA,12460
8
- reydb/rerror.py,sha256=309PJVQG7jsL2A2R5IW4zuS4IojBgoGx3qxwIotBh_k,9896
9
- reydb/rexec.py,sha256=0w9BpgKm9uF7kwHtYM2vE9NK_s4ZbbLTQ4IBMYZqjn8,53973
10
- reydb/rfile.py,sha256=usK1W39O3Fi7FoAljhDIFgqj15c1GrQv3ASYUt1IxdA,15087
11
- reydb/rinfo.py,sha256=qW9QoGuMaMO2Fr76FCETE0TES_4CscagAceZtXc2qsU,12749
12
- reydb/rorm.py,sha256=4Xq6Dfc3525FmZWFw_pkbNSn60nN0FKr5RlpBEIEDpo,39754
13
- reydb/rparam.py,sha256=-uACeJvzMBQuQqa_F_AnGD9GoEoQEjjTnJ0dVZhA2to,9702
14
- reydb-1.1.60.dist-info/METADATA,sha256=jIL2Go1IxL7mK8OT05Q4rfiE1z9Q0Z6e6qsjsO1L2EE,1622
15
- reydb-1.1.60.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
16
- reydb-1.1.60.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
17
- reydb-1.1.60.dist-info/RECORD,,
File without changes