reydb 1.2.13__py3-none-any.whl → 1.2.14__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/rconfig.py CHANGED
@@ -32,7 +32,7 @@ __all__ = (
32
32
 
33
33
 
34
34
  type ConfigValue = bool | str | int | float | list | tuple | dict | set | Datetime | Date | Time | Timedelta | None
35
- ConfigRow = TypedDict('ConfigRow', {'key': str, 'value': ConfigValue, 'type': str, 'note': str | None})
35
+ ConfigRow = TypedDict('ConfigRow', {'key': str, 'value': ConfigValue, 'note': str | None})
36
36
  type ConfigTable = list[ConfigRow]
37
37
  ConfigValueT = TypeVar('T', bound=ConfigValue) # Any.
38
38
  DatabaseT = TypeVar('DatabaseT', 'rdb.Database', 'rdb.DatabaseAsync')
@@ -170,25 +170,21 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
170
170
  """
171
171
 
172
172
  # Get.
173
- models = (
174
- self.db.orm.select(DatabaseTableConfig)
175
- .fields(DatabaseTableConfig.key, DatabaseTableConfig.value, DatabaseTableConfig.type, DatabaseTableConfig.note)
176
- .order_by(
177
- rorm.funcs.IFNULL(DatabaseTableConfig.update_time, DatabaseTableConfig.create_time)
178
- .desc()
179
- )
180
- .execute()
173
+ result = self.db.execute.select(
174
+ self.db_names['config'],
175
+ ['key', 'value', 'note'],
176
+ order='IFNULL(`update_time`, `create_time`) DESC'
181
177
  )
182
178
 
183
179
  # Convert.
184
180
  global_dict = {'datetime': Datetime}
185
181
  result = [
186
182
  {
187
- 'key': model.key,
188
- 'value': eval(model.value, global_dict),
189
- 'note': model.note
183
+ 'key': row['key'],
184
+ 'value': eval(row['value'], global_dict),
185
+ 'note': row['note']
190
186
  }
191
- for model in models
187
+ for row in result
192
188
  ]
193
189
 
194
190
  return result
@@ -209,10 +205,18 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
209
205
  """
210
206
 
211
207
  # Get.
212
- model = self.db.orm.get(DatabaseTableConfig, key)
208
+ where = '`key` = :key'
209
+ result = self.db.execute.select(
210
+ self.db_names['config'],
211
+ '`value`',
212
+ where,
213
+ limit=1,
214
+ key=key
215
+ )
216
+ value = result.scalar()
213
217
 
214
218
  # Default.
215
- if model.value is None:
219
+ if value is None:
216
220
  value = default
217
221
  else:
218
222
  global_dict = {'datetime': Datetime}
@@ -225,7 +229,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
225
229
  self,
226
230
  key: str,
227
231
  default: ConfigValueT | None = None,
228
- default_note: str | None = None
232
+ note: str | None = None
229
233
  ) -> ConfigValue | ConfigValueT:
230
234
  """
231
235
  Set config default value.
@@ -234,7 +238,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
234
238
  ----------
235
239
  key : Config key.
236
240
  default : Config default value.
237
- default_note : Config default note.
241
+ note : Config default note.
238
242
 
239
243
  Returns
240
244
  -------
@@ -246,13 +250,12 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
246
250
  'key': key,
247
251
  'value': repr(default),
248
252
  'type': type(default).__name__,
249
- 'note': default_note
253
+ 'note': note
250
254
  }
251
- result = (
252
- self.db.orm.insert(DatabaseTableConfig)
253
- .values(data)
254
- .ignore()
255
- .execute()
255
+ result = self.db.execute.insert(
256
+ self.db_names['config'],
257
+ data,
258
+ 'ignore'
256
259
  )
257
260
 
258
261
  # Get.
@@ -262,39 +265,30 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
262
265
  return default
263
266
 
264
267
 
265
- def update(self, data: dict[str, ConfigValue] | ConfigTable) -> None:
268
+ def update(self, data: ConfigRow | ConfigTable) -> None:
266
269
  """
267
270
  Update config values.
268
271
 
269
272
  Parameters
270
273
  ----------
271
274
  data : Config update data.
272
- - `dict[str, Any]`: Config key and value.
273
- - `ConfigTable`: Config key and value and note.
275
+ - `ConfigRow`: One config.
276
+ - `ConfigTable`: Multiple configs.
274
277
  """
275
278
 
276
279
  # Set parameter.
277
280
  if type(data) == dict:
278
- data = [
279
- {
280
- 'key': key,
281
- 'value': repr(value),
282
- 'type': type(value).__name__
283
- }
284
- for key, value in data.items()
285
- ]
286
- else:
287
- data = data.copy()
288
- for row in data:
289
- row['value'] = repr(row['value'])
290
- row['type'] = type(row['value']).__name__
281
+ data = [data]
282
+ data = data.copy()
283
+ for row in data:
284
+ row['value'] = repr(row['value'])
285
+ row['type'] = type(row['value']).__name__
291
286
 
292
287
  # Update.
293
- (
294
- self.db.orm.insert(DatabaseTableConfig)
295
- .values(data)
296
- .update()
297
- .execute()
288
+ self.db.execute.insert(
289
+ self.db_names['config'],
290
+ data,
291
+ 'update'
298
292
  )
299
293
 
300
294
 
@@ -309,16 +303,16 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
309
303
 
310
304
  # Remove.
311
305
  if type(key) == str:
312
- where = DatabaseTableConfig == key
306
+ where = '`key` = :key'
313
307
  limit = 1
314
308
  else:
315
- where = DatabaseTableConfig in key
309
+ where = '`key` in :key'
316
310
  limit = None
317
- result = (
318
- self.db.orm.delete(DatabaseTableConfig)
319
- .where(where)
320
- .limit(limit)
321
- .execute()
311
+ result = self.db.execute.delete(
312
+ self.db_names['base.config'],
313
+ where,
314
+ limit=limit,
315
+ key=key
322
316
  )
323
317
 
324
318
  # Check.
@@ -336,17 +330,17 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
336
330
  """
337
331
 
338
332
  # Get.
339
- models = (
340
- self.db.orm.select(DatabaseTableConfig)
341
- .fields('key', 'value')
342
- .execute()
333
+ result = self.db.execute.select(
334
+ self.db_names['config'],
335
+ ['key', 'value']
343
336
  )
344
337
 
345
338
  # Convert.
346
339
  global_dict = {'datetime': Datetime}
340
+ result = result.to_dict('key', 'value')
347
341
  result = {
348
- model.key: eval(model.value, global_dict)
349
- for model in models
342
+ key: eval(value, global_dict)
343
+ for key, value in result.items()
350
344
  }
351
345
 
352
346
  return result
@@ -425,35 +419,34 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
425
419
  return value
426
420
 
427
421
 
428
- def __setitem__(self, key_note: str | tuple[str, str], value: ConfigValue) -> None:
422
+ def __setitem__(
423
+ self,
424
+ key_and_note: str | tuple[str, str],
425
+ value: ConfigValue
426
+ ) -> None:
429
427
  """
430
428
  Set config value.
431
429
 
432
430
  Parameters
433
431
  ----------
434
- key_note : Config key and note.
432
+ key_and_note : Config key and note.
435
433
  value : Config value.
436
434
  """
437
435
 
438
436
  # Set parameter.
439
- if type(key_note) != str:
440
- key, note = key_note
437
+ if type(key_and_note) != str:
438
+ key, note = key_and_note
441
439
  else:
442
- key = key_note
440
+ key = key_and_note
443
441
  note = None
444
442
 
445
443
  # Set.
446
444
  data = {
447
445
  'key': key,
448
446
  'value': repr(value),
449
- 'type': type(value).__name__,
450
447
  'note': note
451
448
  }
452
- self.db.execute.insert(
453
- self.db_names['config'],
454
- data,
455
- 'update'
456
- )
449
+ self.update(data)
457
450
 
458
451
 
459
452
  class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
@@ -495,7 +488,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
495
488
  # Get.
496
489
  result = await self.db.execute.select(
497
490
  self.db_names['config'],
498
- ['key', 'value', 'type', 'note'],
491
+ ['key', 'value', 'note'],
499
492
  order='IFNULL(`update_time`, `create_time`) DESC'
500
493
  )
501
494
 
@@ -552,7 +545,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
552
545
  self,
553
546
  key: str,
554
547
  default: ConfigValueT | None = None,
555
- default_note: str | None = None
548
+ note: str | None = None
556
549
  ) -> ConfigValue | ConfigValueT:
557
550
  """
558
551
  Asynchronous set config default value.
@@ -561,7 +554,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
561
554
  ----------
562
555
  key : Config key.
563
556
  default : Config default value.
564
- default_note : Config default note.
557
+ note : Config default note.
565
558
 
566
559
  Returns
567
560
  -------
@@ -573,7 +566,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
573
566
  'key': key,
574
567
  'value': repr(default),
575
568
  'type': type(default).__name__,
576
- 'note': default_note
569
+ 'note': note
577
570
  }
578
571
  result = await self.db.execute.insert(
579
572
  self.db_names['config'],
@@ -588,32 +581,24 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
588
581
  return default
589
582
 
590
583
 
591
- async def update(self, data: dict[str, ConfigValue] | ConfigTable) -> None:
584
+ async def update(self, data: ConfigRow | ConfigTable) -> None:
592
585
  """
593
586
  Asynchronous update config values.
594
587
 
595
588
  Parameters
596
589
  ----------
597
590
  data : Config update data.
598
- - `dict[str, Any]`: Config key and value.
599
- - `ConfigTable`: Config key and value and note.
591
+ - `ConfigRow`: One config.
592
+ - `ConfigTable`: Multiple configs.
600
593
  """
601
594
 
602
595
  # Set parameter.
603
596
  if type(data) == dict:
604
- data = [
605
- {
606
- 'key': key,
607
- 'value': repr(value),
608
- 'type': type(value).__name__
609
- }
610
- for key, value in data.items()
611
- ]
612
- else:
613
- data = data.copy()
614
- for row in data:
615
- row['value'] = repr(row['value'])
616
- row['type'] = type(row['value']).__name__
597
+ data = [data]
598
+ data = data.copy()
599
+ for row in data:
600
+ row['value'] = repr(row['value'])
601
+ row['type'] = type(row['value']).__name__
617
602
 
618
603
  # Update.
619
604
  await self.db.execute.insert(
@@ -750,32 +735,31 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
750
735
  return value
751
736
 
752
737
 
753
- async def __setitem__(self, key_note: str | tuple[str, str], value: ConfigValue) -> None:
738
+ async def __setitem__(
739
+ self,
740
+ key_and_note: str | tuple[str, str],
741
+ value: ConfigValue
742
+ ) -> None:
754
743
  """
755
744
  Asynchronous set config value.
756
745
 
757
746
  Parameters
758
747
  ----------
759
- key_note : Config key and note.
748
+ key_and_note : Config key and note.
760
749
  value : Config value.
761
750
  """
762
751
 
763
752
  # Set parameter.
764
- if type(key_note) != str:
765
- key, note = key_note
753
+ if type(key_and_note) != str:
754
+ key, note = key_and_note
766
755
  else:
767
- key = key_note
756
+ key = key_and_note
768
757
  note = None
769
758
 
770
759
  # Set.
771
760
  data = {
772
761
  'key': key,
773
762
  'value': repr(value),
774
- 'type': type(value).__name__,
775
763
  'note': note
776
764
  }
777
- await self.db.execute.insert(
778
- self.db_names['config'],
779
- data,
780
- 'update'
781
- )
765
+ await self.update(data)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reydb
3
- Version: 1.2.13
3
+ Version: 1.2.14
4
4
  Summary: Database method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reydb/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -2,14 +2,14 @@ reydb/__init__.py,sha256=4mnlkfJfkBfxBpCotVUJ86f4AnT8plqlFbGiH3vZ4PM,550
2
2
  reydb/rall.py,sha256=IxSPGh77xz7ndDC7J8kZ_66Gq_xTAztGtnELUku1Ouw,364
3
3
  reydb/rbase.py,sha256=vx37yV6LlWP89nWAfYyOf0Xm3N_e9eB8z5Mxe-aTEo4,8248
4
4
  reydb/rbuild.py,sha256=0jI0MNl-BIhQtuT_-GeXBPTjG76k9EE3wwEQXGhTJyc,80938
5
- reydb/rconfig.py,sha256=xXNZf0yMkNWK_7NMpCUg0osYHLCVYsy0QV3qlSvmVSI,19229
5
+ reydb/rconfig.py,sha256=C2qBgO-qnSVSYpvOcDisfTqwXLE6VIE014sE7RxtrCg,18328
6
6
  reydb/rconn.py,sha256=guRaR8N6RuzZzujwaeq7HhKWTizF9SrUBqEAFjfjpoo,6909
7
7
  reydb/rdb.py,sha256=syyqZbEu92NbCj9O6_T6iAv7E46CyfQOC4T8qtPfHNs,14364
8
8
  reydb/rerror.py,sha256=uwVuolRp-PmXXUZIA_Qd2S6NSOm1S0vDJvehX6l__U8,14888
9
9
  reydb/rexec.py,sha256=HSu8fCgBjpKY1z6OJI6Ky_0sKMPEv_uCAEAcN7fd2i4,53028
10
10
  reydb/rinfo.py,sha256=LjrqTA7JJbWJsjXwV-zKpbE1htv-whg6239hoQj4yIU,18151
11
11
  reydb/rorm.py,sha256=NxY2qOCXDwyy_lSRWZPxQDhG8IuLLxbaqIWxOZ1DDys,50791
12
- reydb-1.2.13.dist-info/METADATA,sha256=RJBvka1FTupRVLdIDJjUtbb7xJSVEaD4J-AYwyAxig0,1622
13
- reydb-1.2.13.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- reydb-1.2.13.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
15
- reydb-1.2.13.dist-info/RECORD,,
12
+ reydb-1.2.14.dist-info/METADATA,sha256=oWzy71_0t-tUawia-612SzE0RHOEFY6vx5FuECD49zo,1622
13
+ reydb-1.2.14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
+ reydb-1.2.14.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
15
+ reydb-1.2.14.dist-info/RECORD,,
File without changes