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/rparam.py CHANGED
@@ -9,7 +9,7 @@
9
9
  """
10
10
 
11
11
 
12
- from typing import TypeVar, Generic, overload
12
+ from typing import Literal, TypeVar, Generic, Final, overload
13
13
 
14
14
  from . import rdb
15
15
  from .rbase import DatabaseBase
@@ -17,10 +17,20 @@ from .rexec import Result
17
17
 
18
18
 
19
19
  __all__ = (
20
+ 'DatabaseSchemaSuper',
20
21
  'DatabaseSchema',
22
+ 'DatabaseSchemaAsync',
23
+ 'DatabaseParametersSuper',
21
24
  'DatabaseParameters',
25
+ 'DatabaseParametersAsync',
26
+ 'DatabaseParametersVariables',
22
27
  'DatabaseParametersStatus',
23
- 'DatabaseParametersVariable'
28
+ 'DatabaseParametersVariablesGlobal',
29
+ 'DatabaseParametersStatusGlobal',
30
+ 'DatabaseParametersVariablesAsync',
31
+ 'DatabaseParametersStatusAsync',
32
+ 'DatabaseParametersVariablesGlobalAsync',
33
+ 'DatabaseParametersStatusGlobalAsync'
24
34
  )
25
35
 
26
36
 
@@ -185,16 +195,18 @@ class DatabaseSchemaAsync(DatabaseSchemaSuper['rdb.DatabaseAsync']):
185
195
  return schema_dict
186
196
 
187
197
 
188
- class DatabaseParameters(DatabaseBase):
198
+ class DatabaseParametersSuper(DatabaseBase, Generic[DatabaseT]):
189
199
  """
190
- Database parameters type.
200
+ Database parameters super type.
191
201
  """
192
202
 
203
+ mode: Literal['VARIABLES', 'STATUS']
204
+ glob: bool
205
+
193
206
 
194
207
  def __init__(
195
208
  self,
196
- db: 'rdb.Database',
197
- global_: bool
209
+ db: DatabaseT
198
210
  ) -> None:
199
211
  """
200
212
  Build instance attributes.
@@ -202,12 +214,16 @@ class DatabaseParameters(DatabaseBase):
202
214
  Parameters
203
215
  ----------
204
216
  db: Database instance.
205
- global\\_ : Whether base global.
206
217
  """
207
218
 
208
219
  # Set parameter.
209
220
  self.db = db
210
- self.global_ = global_
221
+
222
+
223
+ class DatabaseParameters(DatabaseParametersSuper['rdb.Database']):
224
+ """
225
+ Database parameters type.
226
+ """
211
227
 
212
228
 
213
229
  def __getitem__(self, key: str) -> str | None:
@@ -246,12 +262,6 @@ class DatabaseParameters(DatabaseBase):
246
262
  self.update(params)
247
263
 
248
264
 
249
- class DatabaseParametersStatus(DatabaseParameters):
250
- """
251
- Database parameters status type.
252
- """
253
-
254
-
255
265
  @overload
256
266
  def get(self) -> dict[str, str]: ...
257
267
 
@@ -274,14 +284,11 @@ class DatabaseParametersStatus(DatabaseParameters):
274
284
  """
275
285
 
276
286
  # Generate SQL.
277
-
278
- ## Global.
279
- if self.global_:
280
- sql = 'SHOW GLOBAL STATUS'
281
-
282
- ## Not global.
283
- else:
284
- sql = 'SHOW STATUS'
287
+ sql = 'SHOW ' + (
288
+ 'GLOBAL '
289
+ if self.glob
290
+ else ''
291
+ ) + self.mode
285
292
 
286
293
  # Execute SQL.
287
294
 
@@ -312,25 +319,80 @@ class DatabaseParametersStatus(DatabaseParameters):
312
319
  params : Update parameter key value pairs.
313
320
  """
314
321
 
315
- # Throw exception.
316
- raise AssertionError('database status not update')
322
+ # Generate SQL.
323
+ sql_set_list = [
324
+ '%s = %s' % (
325
+ key,
326
+ (
327
+ value
328
+ if type(value) in (int, float)
329
+ else "'%s'" % value
330
+ )
331
+ )
332
+ for key, value in params.items()
333
+ ]
334
+ sql_set = ',\n '.join(sql_set_list)
335
+ sql = 'SHOW ' + (
336
+ 'GLOBAL '
337
+ if self.glob
338
+ else ''
339
+ ) + sql_set
340
+
341
+ # Execute SQL.
342
+ self.db.execute(sql)
317
343
 
318
344
 
319
- class DatabaseParametersVariable(DatabaseParameters):
345
+ class DatabaseParametersAsync(DatabaseParametersSuper['rdb.DatabaseAsync']):
320
346
  """
321
- Database parameters variable type.
347
+ Asynchrouous database parameters type.
322
348
  """
323
349
 
324
350
 
351
+ async def __getitem__(self, key: str) -> str | None:
352
+ """
353
+ Asynchrouous get item of parameter dictionary.
354
+
355
+ Parameters
356
+ ----------
357
+ key : Parameter key.
358
+
359
+ Returns
360
+ -------
361
+ Parameter value.
362
+ """
363
+
364
+ # Get.
365
+ value = await self.get(key)
366
+
367
+ return value
368
+
369
+
370
+ async def __setitem__(self, key: str, value: str | float) -> None:
371
+ """
372
+ Asynchrouous set item of parameter dictionary.
373
+
374
+ Parameters
375
+ ----------
376
+ key : Parameter key.
377
+ value : Parameter value.
378
+ """
379
+
380
+ # Set.
381
+ params = {key: value}
382
+
383
+ # Update.
384
+ await self.update(params)
385
+
386
+
325
387
  @overload
326
- def get(self) -> dict[str, str]: ...
388
+ async def get(self) -> dict[str, str]: ...
327
389
 
328
390
  @overload
329
- def get(self, key: str) -> str | None: ...
391
+ async def get(self, key: str) -> str | None: ...
330
392
 
331
- def get(self, key: str | None = None) -> dict[str, str] | str | None:
393
+ async def get(self, key: str | None = None) -> dict[str, str] | str | None:
332
394
  """
333
- Get parameter.
395
+ Asynchrouous get parameter.
334
396
 
335
397
  Parameters
336
398
  ----------
@@ -340,48 +402,49 @@ class DatabaseParametersVariable(DatabaseParameters):
340
402
 
341
403
  Returns
342
404
  -------
343
- Variables of database.
405
+ Status of database.
344
406
  """
345
407
 
346
408
  # Generate SQL.
347
-
348
- ## Global.
349
- if self.global_:
350
- sql = 'SHOW GLOBAL VARIABLES'
351
-
352
- ## Not global.
353
- else:
354
- sql = 'SHOW VARIABLES'
409
+ sql = 'SHOW ' + (
410
+ 'GLOBAL '
411
+ if self.glob
412
+ else ''
413
+ ) + self.mode
355
414
 
356
415
  # Execute SQL.
357
416
 
358
417
  ## Dictionary.
359
418
  if key is None:
360
- result = self.db.execute(sql, key=key)
361
- variables = result.to_dict(val_field=1)
419
+ result = await self.db.execute(sql, key=key)
420
+ status = result.to_dict(val_field=1)
362
421
 
363
422
  ## Value.
364
423
  else:
365
424
  sql += ' LIKE :key'
366
- result = self.db.execute(sql, key=key)
425
+ result = await self.db.execute(sql, key=key)
367
426
  row = result.first()
368
427
  if row is None:
369
- variables = None
428
+ status = None
370
429
  else:
371
- variables = row['Value']
430
+ status = row['Value']
372
431
 
373
- return variables
432
+ return status
374
433
 
375
434
 
376
- def update(self, params: dict[str, str | float]) -> None:
435
+ async def update(self, params: dict[str, str | float]) -> None:
377
436
  """
378
- Update parameter.
437
+ Asynchrouous update parameter.
379
438
 
380
439
  Parameters
381
440
  ----------
382
441
  params : Update parameter key value pairs.
383
442
  """
384
443
 
444
+ # Check.
445
+ if self.mode == 'STATUS':
446
+ raise AssertionError('database status not update')
447
+
385
448
  # Generate SQL.
386
449
  sql_set_list = [
387
450
  '%s = %s' % (
@@ -395,14 +458,83 @@ class DatabaseParametersVariable(DatabaseParameters):
395
458
  for key, value in params.items()
396
459
  ]
397
460
  sql_set = ',\n '.join(sql_set_list)
461
+ sql = 'SHOW ' + (
462
+ 'GLOBAL '
463
+ if self.glob
464
+ else ''
465
+ ) + sql_set
398
466
 
399
- ## Global.
400
- if self.global_:
401
- sql = f'SET GLOBAL {sql_set}'
467
+ # Execute SQL.
468
+ await self.db.execute(sql)
402
469
 
403
- ## Not global.
404
- else:
405
- sql = f'SET {sql_set}'
406
470
 
407
- # Execute SQL.
408
- self.db.execute(sql)
471
+ class DatabaseParametersVariables(DatabaseParameters):
472
+ """
473
+ Database variable parameters type.
474
+ """
475
+
476
+ mode: Final = 'VARIABLES'
477
+ glob: Final = False
478
+
479
+
480
+ class DatabaseParametersStatus(DatabaseParameters):
481
+ """
482
+ Database status parameters type.
483
+ """
484
+
485
+ mode: Final = 'STATUS'
486
+ glob: Final = False
487
+
488
+
489
+ class DatabaseParametersVariablesGlobal(DatabaseParameters):
490
+ """
491
+ Database global variable parameters type.
492
+ """
493
+
494
+ mode: Final = 'VARIABLES'
495
+ glob: Final = True
496
+
497
+
498
+ class DatabaseParametersStatusGlobal(DatabaseParameters):
499
+ """
500
+ Database global status parameters type.
501
+ """
502
+
503
+ mode: Final = 'STATUS'
504
+ glob: Final = True
505
+
506
+
507
+ class DatabaseParametersVariablesAsync(DatabaseParametersAsync):
508
+ """
509
+ Asynchrouous database variable parameters type.
510
+ """
511
+
512
+ mode: Final = 'VARIABLES'
513
+ glob: Final = False
514
+
515
+
516
+ class DatabaseParametersStatusAsync(DatabaseParametersAsync):
517
+ """
518
+ Asynchrouous database status parameters type.
519
+ """
520
+
521
+ mode: Final = 'STATUS'
522
+ glob: Final = False
523
+
524
+
525
+ class DatabaseParametersVariablesGlobalAsync(DatabaseParametersAsync):
526
+ """
527
+ Asynchrouous database global variable parameters type.
528
+ """
529
+
530
+ mode: Final = 'VARIABLES'
531
+ glob: Final = True
532
+
533
+
534
+ class DatabaseParametersStatusGlobalAsync(DatabaseParametersAsync):
535
+ """
536
+ Asynchrouous database global status parameters type.
537
+ """
538
+
539
+ mode: Final = 'STATUS'
540
+ glob: Final = True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reydb
3
- Version: 1.1.60
3
+ Version: 1.1.61
4
4
  Summary: Database method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reydb/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -0,0 +1,16 @@
1
+ reydb/__init__.py,sha256=zuQ14sl7rZ6lQ1P566ALjiRi-PcIXj9Ff0U_yYNQHFE,581
2
+ reydb/rall.py,sha256=8tWDeGRLKujqPHFy4898WCIgZEA4OxOfeQ8xG6Fw69c,387
3
+ reydb/rbase.py,sha256=16fG_YWnvJFu0ElXvc3BS9PtSJFZ9M631Te0b2ewWDE,9457
4
+ reydb/rbuild.py,sha256=-C8ORqJSa6tDBMm7Y-ZcN80sgWs5rX6I0aO0DioXNm4,46599
5
+ reydb/rconfig.py,sha256=mA40xrC5O9Y3lHnuJYDRUqRsLk3s2BFxgXou2tnFAXM,21196
6
+ reydb/rconn.py,sha256=guRaR8N6RuzZzujwaeq7HhKWTizF9SrUBqEAFjfjpoo,6909
7
+ reydb/rdb.py,sha256=Dh0J26fIfRrX8EK25cH1MfFzPLmWC-VnvXjLgiS_wFM,13824
8
+ reydb/rerror.py,sha256=309PJVQG7jsL2A2R5IW4zuS4IojBgoGx3qxwIotBh_k,9896
9
+ reydb/rexec.py,sha256=sOiapQnnbMhnItgYhUZ4iz8xRolsUJz6inCH1-7hb54,52074
10
+ reydb/rfile.py,sha256=usK1W39O3Fi7FoAljhDIFgqj15c1GrQv3ASYUt1IxdA,15087
11
+ reydb/rorm.py,sha256=heJf_vVJgjlNNQHbkpS_Q2rk8CBmRdOOSO7RZBfHulE,40355
12
+ reydb/rparam.py,sha256=hXpnT4YnTgZFjyuc6bf2TCc-p1HQ7ycJjamq7I1xook,12851
13
+ reydb-1.1.61.dist-info/METADATA,sha256=U2Xa2A4pdO1OKHmYgzphmIWh0cma7fCBi31grlX8iwQ,1622
14
+ reydb-1.1.61.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
15
+ reydb-1.1.61.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
16
+ reydb-1.1.61.dist-info/RECORD,,