reydb 1.2.12__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,13 +170,11 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
170
170
  """
171
171
 
172
172
  # Get.
173
- result = self.db.orm.select(
174
- DatabaseTableConfig
175
- ).fields(
176
- DatabaseTableConfig.key, DatabaseTableConfig.value, DatabaseTableConfig.type, DatabaseTableConfig.note
177
- ).order_by(
178
- rorm.funcs.IFNULL(DatabaseTableConfig.update_time, DatabaseTableConfig.create_time).desc()
179
- ).execute()
173
+ result = self.db.execute.select(
174
+ self.db_names['config'],
175
+ ['key', 'value', 'note'],
176
+ order='IFNULL(`update_time`, `create_time`) DESC'
177
+ )
180
178
 
181
179
  # Convert.
182
180
  global_dict = {'datetime': Datetime}
@@ -231,7 +229,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
231
229
  self,
232
230
  key: str,
233
231
  default: ConfigValueT | None = None,
234
- default_note: str | None = None
232
+ note: str | None = None
235
233
  ) -> ConfigValue | ConfigValueT:
236
234
  """
237
235
  Set config default value.
@@ -240,7 +238,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
240
238
  ----------
241
239
  key : Config key.
242
240
  default : Config default value.
243
- default_note : Config default note.
241
+ note : Config default note.
244
242
 
245
243
  Returns
246
244
  -------
@@ -252,7 +250,7 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
252
250
  'key': key,
253
251
  'value': repr(default),
254
252
  'type': type(default).__name__,
255
- 'note': default_note
253
+ 'note': note
256
254
  }
257
255
  result = self.db.execute.insert(
258
256
  self.db_names['config'],
@@ -267,32 +265,24 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
267
265
  return default
268
266
 
269
267
 
270
- def update(self, data: dict[str, ConfigValue] | ConfigTable) -> None:
268
+ def update(self, data: ConfigRow | ConfigTable) -> None:
271
269
  """
272
270
  Update config values.
273
271
 
274
272
  Parameters
275
273
  ----------
276
274
  data : Config update data.
277
- - `dict[str, Any]`: Config key and value.
278
- - `ConfigTable`: Config key and value and note.
275
+ - `ConfigRow`: One config.
276
+ - `ConfigTable`: Multiple configs.
279
277
  """
280
278
 
281
279
  # Set parameter.
282
280
  if type(data) == dict:
283
- data = [
284
- {
285
- 'key': key,
286
- 'value': repr(value),
287
- 'type': type(value).__name__
288
- }
289
- for key, value in data.items()
290
- ]
291
- else:
292
- data = data.copy()
293
- for row in data:
294
- row['value'] = repr(row['value'])
295
- 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__
296
286
 
297
287
  # Update.
298
288
  self.db.execute.insert(
@@ -429,35 +419,34 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
429
419
  return value
430
420
 
431
421
 
432
- 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:
433
427
  """
434
428
  Set config value.
435
429
 
436
430
  Parameters
437
431
  ----------
438
- key_note : Config key and note.
432
+ key_and_note : Config key and note.
439
433
  value : Config value.
440
434
  """
441
435
 
442
436
  # Set parameter.
443
- if type(key_note) != str:
444
- key, note = key_note
437
+ if type(key_and_note) != str:
438
+ key, note = key_and_note
445
439
  else:
446
- key = key_note
440
+ key = key_and_note
447
441
  note = None
448
442
 
449
443
  # Set.
450
444
  data = {
451
445
  'key': key,
452
446
  'value': repr(value),
453
- 'type': type(value).__name__,
454
447
  'note': note
455
448
  }
456
- self.db.execute.insert(
457
- self.db_names['config'],
458
- data,
459
- 'update'
460
- )
449
+ self.update(data)
461
450
 
462
451
 
463
452
  class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
@@ -499,7 +488,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
499
488
  # Get.
500
489
  result = await self.db.execute.select(
501
490
  self.db_names['config'],
502
- ['key', 'value', 'type', 'note'],
491
+ ['key', 'value', 'note'],
503
492
  order='IFNULL(`update_time`, `create_time`) DESC'
504
493
  )
505
494
 
@@ -556,7 +545,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
556
545
  self,
557
546
  key: str,
558
547
  default: ConfigValueT | None = None,
559
- default_note: str | None = None
548
+ note: str | None = None
560
549
  ) -> ConfigValue | ConfigValueT:
561
550
  """
562
551
  Asynchronous set config default value.
@@ -565,7 +554,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
565
554
  ----------
566
555
  key : Config key.
567
556
  default : Config default value.
568
- default_note : Config default note.
557
+ note : Config default note.
569
558
 
570
559
  Returns
571
560
  -------
@@ -577,7 +566,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
577
566
  'key': key,
578
567
  'value': repr(default),
579
568
  'type': type(default).__name__,
580
- 'note': default_note
569
+ 'note': note
581
570
  }
582
571
  result = await self.db.execute.insert(
583
572
  self.db_names['config'],
@@ -592,32 +581,24 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
592
581
  return default
593
582
 
594
583
 
595
- async def update(self, data: dict[str, ConfigValue] | ConfigTable) -> None:
584
+ async def update(self, data: ConfigRow | ConfigTable) -> None:
596
585
  """
597
586
  Asynchronous update config values.
598
587
 
599
588
  Parameters
600
589
  ----------
601
590
  data : Config update data.
602
- - `dict[str, Any]`: Config key and value.
603
- - `ConfigTable`: Config key and value and note.
591
+ - `ConfigRow`: One config.
592
+ - `ConfigTable`: Multiple configs.
604
593
  """
605
594
 
606
595
  # Set parameter.
607
596
  if type(data) == dict:
608
- data = [
609
- {
610
- 'key': key,
611
- 'value': repr(value),
612
- 'type': type(value).__name__
613
- }
614
- for key, value in data.items()
615
- ]
616
- else:
617
- data = data.copy()
618
- for row in data:
619
- row['value'] = repr(row['value'])
620
- 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__
621
602
 
622
603
  # Update.
623
604
  await self.db.execute.insert(
@@ -644,7 +625,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
644
625
  where = '`key` in :key'
645
626
  limit = None
646
627
  result = await self.db.execute.delete(
647
- self.db_names['base.config'],
628
+ self.db_names['config'],
648
629
  where,
649
630
  limit=limit,
650
631
  key=key
@@ -754,32 +735,31 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
754
735
  return value
755
736
 
756
737
 
757
- 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:
758
743
  """
759
744
  Asynchronous set config value.
760
745
 
761
746
  Parameters
762
747
  ----------
763
- key_note : Config key and note.
748
+ key_and_note : Config key and note.
764
749
  value : Config value.
765
750
  """
766
751
 
767
752
  # Set parameter.
768
- if type(key_note) != str:
769
- key, note = key_note
753
+ if type(key_and_note) != str:
754
+ key, note = key_and_note
770
755
  else:
771
- key = key_note
756
+ key = key_and_note
772
757
  note = None
773
758
 
774
759
  # Set.
775
760
  data = {
776
761
  'key': key,
777
762
  'value': repr(value),
778
- 'type': type(value).__name__,
779
763
  'note': note
780
764
  }
781
- await self.db.execute.insert(
782
- self.db_names['config'],
783
- data,
784
- 'update'
785
- )
765
+ await self.update(data)
reydb/rexec.py CHANGED
@@ -28,6 +28,7 @@ from .rbase import DatabaseBase, handle_sql, handle_data
28
28
 
29
29
  __all__ = (
30
30
  'Result',
31
+ 'ResultORM',
31
32
  'DatabaseExecuteSuper',
32
33
  'DatabaseExecute',
33
34
  'DatabaseExecuteAsync'
@@ -35,8 +36,8 @@ __all__ = (
35
36
 
36
37
 
37
38
  # Monkey path.
38
- Result_ = monkey_sqlalchemy_result_more_fetch()
39
- Result = Result_
39
+ _Result = monkey_sqlalchemy_result_more_fetch()
40
+ Result = _Result
40
41
  monkey_sqlalchemy_row_index_field()
41
42
 
42
43
 
reydb/rorm.py CHANGED
@@ -14,19 +14,22 @@ from collections.abc import Callable
14
14
  from functools import wraps as functools_wraps
15
15
  from inspect import iscoroutinefunction as inspect_iscoroutinefunction
16
16
  from pydantic import ConfigDict, field_validator as pydantic_field_validator, model_validator as pydantic_model_validator
17
- from sqlalchemy import types, text as sqlalchemy_text
17
+ from sqlalchemy import Column, types, text as sqlalchemy_text
18
18
  from sqlalchemy.orm import SessionTransaction, load_only
19
19
  from sqlalchemy.orm.strategy_options import _AttrType
20
20
  from sqlalchemy.sql import func as sqlalchemy_func
21
- from sqlalchemy.sql.dml import Insert, Update, Delete
21
+ from sqlalchemy.sql.dml import Update, Delete
22
22
  from sqlalchemy.sql.sqltypes import TypeEngine
23
+ from sqlalchemy.sql._typing import _ColumnExpressionArgument
23
24
  from sqlalchemy.ext.asyncio import AsyncSessionTransaction
24
- from sqlalchemy.dialects.mysql import types as types_mysql
25
+ from sqlalchemy.dialects.mysql import Insert, types as types_mysql
26
+ from sqlalchemy.exc import SAWarning
25
27
  from sqlmodel import SQLModel, Session, Table
26
28
  from sqlmodel.main import SQLModelMetaclass, FieldInfo, default_registry
27
29
  from sqlmodel.ext.asyncio.session import AsyncSession
28
30
  from sqlmodel.sql._expression_select_cls import SelectOfScalar as Select
29
31
  from datetime import datetime, date, time, timedelta
32
+ from warnings import filterwarnings
30
33
  from reykit.rbase import CallableT, Null, throw, is_instance
31
34
 
32
35
  from . import rdb
@@ -35,6 +38,7 @@ from .rbase import (
35
38
  SessionTransactionT,
36
39
  DatabaseBase
37
40
  )
41
+ from .rexec import Result
38
42
 
39
43
 
40
44
  __all__ = (
@@ -52,13 +56,15 @@ __all__ = (
52
56
  'DatabaseORMStatementSuper',
53
57
  'DatabaseORMStatement',
54
58
  'DatabaseORMStatementAsync',
59
+ 'DatabaseORMStatementSelectSuper',
55
60
  'DatabaseORMStatementSelect',
56
- 'DatabaseORMStatementInsert',
57
- 'DatabaseORMStatementUpdate',
58
- 'DatabaseORMStatementDelete',
59
61
  'DatabaseORMStatementSelectAsync',
62
+ 'DatabaseORMStatementInsertSuper',
63
+ 'DatabaseORMStatementInsert',
60
64
  'DatabaseORMStatementInsertAsync',
65
+ 'DatabaseORMStatementUpdate',
61
66
  'DatabaseORMStatementUpdateAsync',
67
+ 'DatabaseORMStatementDelete',
62
68
  'DatabaseORMStatementDeleteAsync'
63
69
  )
64
70
 
@@ -67,7 +73,6 @@ DatabaseT = TypeVar('DatabaseT', 'rdb.Database', 'rdb.DatabaseAsync')
67
73
  DatabaseORMModelT = TypeVar('DatabaseORMModelT', bound='DatabaseORMModel')
68
74
  DatabaseORMT = TypeVar('DatabaseORMT', 'DatabaseORM', 'DatabaseORMAsync')
69
75
  DatabaseORMSessionT = TypeVar('DatabaseORMSessionT', 'DatabaseORMSession', 'DatabaseORMSessionAsync')
70
- DatabaseORMStatementReturn = TypeVar('DatabaseORMStatementReturn')
71
76
  DatabaseORMStatementSelectT = TypeVar('DatabaseORMStatementSelectT', 'DatabaseORMStatementSelect', 'DatabaseORMStatementSelectAsync')
72
77
  DatabaseORMStatementInsertT = TypeVar('DatabaseORMStatementInsertT', 'DatabaseORMStatementInsert', 'DatabaseORMStatementInsertAsync')
73
78
  DatabaseORMStatementUpdateT = TypeVar('DatabaseORMStatementUpdateT', 'DatabaseORMStatementUpdate', 'DatabaseORMStatementUpdateAsync')
@@ -660,7 +665,7 @@ class DatabaseORMSessionSuper(
660
665
  -------
661
666
  Instance.
662
667
  """
663
- print(model)
668
+
664
669
  # Set parameter.
665
670
  if is_instance(model):
666
671
  model = type(model)
@@ -1096,7 +1101,7 @@ class DatabaseORMSession(
1096
1101
 
1097
1102
 
1098
1103
  @overload
1099
- def select(self, model: Type[DatabaseORMModelT] | DatabaseORMModelT) -> 'DatabaseORMStatementSelect[list[DatabaseORMModelT]]': ...
1104
+ def select(self, model: Type[DatabaseORMModelT] | DatabaseORMModelT) -> 'DatabaseORMStatementSelect[DatabaseORMModelT]': ...
1100
1105
 
1101
1106
  select = DatabaseORMSessionSuper.select
1102
1107
 
@@ -1470,7 +1475,7 @@ class DatabaseORMSessionAsync(
1470
1475
 
1471
1476
 
1472
1477
  @overload
1473
- def select(self, model: Type[DatabaseORMModelT] | DatabaseORMModelT) -> 'DatabaseORMStatementSelectAsync[list[DatabaseORMModelT]]': ...
1478
+ def select(self, model: Type[DatabaseORMModelT] | DatabaseORMModelT) -> 'DatabaseORMStatementSelectAsync[DatabaseORMModelT]': ...
1474
1479
 
1475
1480
  select = DatabaseORMSessionSuper.select
1476
1481
 
@@ -1507,37 +1512,44 @@ class DatabaseORMStatementSuper(DatabaseORMBase, Generic[DatabaseORMSessionT]):
1507
1512
  def with_only_columns(self) -> NoReturn: ...
1508
1513
 
1509
1514
 
1510
- class DatabaseORMStatement(DatabaseORMStatementSuper[DatabaseORMSession], Generic[DatabaseORMStatementReturn]):
1515
+ class DatabaseORMStatement(DatabaseORMStatementSuper[DatabaseORMSession]):
1511
1516
  """
1512
1517
  Database ORM statement type.
1513
1518
  """
1514
1519
 
1515
1520
 
1516
- def execute(self) -> DatabaseORMStatementReturn:
1521
+ def execute(self) -> Result:
1517
1522
  """
1518
1523
  Execute statement.
1524
+
1525
+ Returns
1526
+ -------
1527
+ Result.
1519
1528
  """
1520
1529
 
1530
+ # Filter warning.
1531
+ filterwarnings(
1532
+ 'ignore',
1533
+ category=SAWarning,
1534
+ message=".*'inherit_cache' attribute to ``True``.*"
1535
+ )
1536
+
1521
1537
  # Transaction.
1522
1538
  self.sess.get_begin()
1523
1539
 
1524
1540
  # Execute.
1525
- result = self.sess.sess.exec(self)
1541
+ result: Result = self.sess.sess.exec(self)
1526
1542
 
1527
- ## Select.
1543
+ ## Select.)
1528
1544
  if isinstance(self, Select):
1529
- result = list(result)
1530
- else:
1531
- result = None
1545
+ result: list[DatabaseORMModel] = list(result)
1532
1546
 
1533
1547
  # Automatic commit.
1534
1548
  if self.sess.autocommit:
1535
1549
 
1536
1550
  ## Select.
1537
1551
  if isinstance(self, Select):
1538
- for model in result:
1539
- if isinstance(model, DatabaseORMModel):
1540
- self.sess.sess.expunge(model)
1552
+ self.sess.sess.expunge_all()
1541
1553
 
1542
1554
  self.sess.commit()
1543
1555
  self.sess.close()
@@ -1545,37 +1557,44 @@ class DatabaseORMStatement(DatabaseORMStatementSuper[DatabaseORMSession], Generi
1545
1557
  return result
1546
1558
 
1547
1559
 
1548
- class DatabaseORMStatementAsync(DatabaseORMStatementSuper[DatabaseORMSessionAsync], Generic[DatabaseORMStatementReturn]):
1560
+ class DatabaseORMStatementAsync(DatabaseORMStatementSuper[DatabaseORMSessionAsync]):
1549
1561
  """
1550
1562
  Asynchronous dtabase ORM statement type.
1551
1563
  """
1552
1564
 
1553
1565
 
1554
- async def execute(self) -> DatabaseORMStatementReturn:
1566
+ async def execute(self) -> Result:
1555
1567
  """
1556
- Asynchronous execute statement.
1568
+ Asynchrouous execute statement.
1569
+
1570
+ Returns
1571
+ -------
1572
+ Result.
1557
1573
  """
1558
1574
 
1575
+ # Filter warning.
1576
+ filterwarnings(
1577
+ 'ignore',
1578
+ category=SAWarning,
1579
+ message=".*'inherit_cache' attribute to ``True``.*"
1580
+ )
1581
+
1559
1582
  # Transaction.
1560
1583
  await self.sess.get_begin()
1561
1584
 
1562
1585
  # Execute.
1563
- result = await self.sess.sess.exec(self)
1586
+ result: Result = await self.sess.sess.exec(self)
1564
1587
 
1565
1588
  ## Select.
1566
1589
  if isinstance(self, Select):
1567
- result = list(result)
1568
- else:
1569
- result = None
1590
+ result: list[DatabaseORMModel] = list(result)
1570
1591
 
1571
1592
  # Automatic commit.
1572
1593
  if self.sess.autocommit:
1573
1594
 
1574
1595
  ## Select.
1575
1596
  if isinstance(self, Select):
1576
- for model in result:
1577
- if isinstance(model, DatabaseORMModel):
1578
- self.sess.sess.expunge(model)
1597
+ self.sess.sess.expunge_all()
1579
1598
 
1580
1599
  await self.sess.commit()
1581
1600
  await self.sess.close()
@@ -1586,23 +1605,23 @@ class DatabaseORMStatementAsync(DatabaseORMStatementSuper[DatabaseORMSessionAsyn
1586
1605
 
1587
1606
  class DatabaseORMStatementSelectSuper(DatabaseORMStatementSuper, Select):
1588
1607
  """
1589
- Database ORM `select` statement type.
1608
+ Database ORM `select` statement super type.
1590
1609
 
1591
1610
  Attributes
1592
1611
  ----------
1593
- inherit_cache : Compatible `Select` type.
1612
+ inherit_cache : Compatible type.
1594
1613
  """
1595
1614
 
1596
1615
  inherit_cache: Final = True
1597
1616
 
1598
1617
 
1599
- def fields(self, *field: _AttrType) -> Self:
1618
+ def fields(self, *names: str) -> Self:
1600
1619
  """
1601
1620
  Replace select fiedls.
1602
1621
 
1603
1622
  Parameters
1604
1623
  ----------
1605
- field : Field set.
1624
+ names : Field name. (Note: primary key automatic add)
1606
1625
 
1607
1626
  Returns
1608
1627
  -------
@@ -1610,115 +1629,354 @@ class DatabaseORMStatementSelectSuper(DatabaseORMStatementSuper, Select):
1610
1629
  """
1611
1630
 
1612
1631
  # Set.
1613
- set = load_only(*field)
1632
+ attrs = [
1633
+ self.model[name]
1634
+ for name in names
1635
+ ]
1636
+ set = load_only(*attrs)
1614
1637
  select = self.options(set)
1615
1638
 
1616
1639
  return select
1617
1640
 
1618
1641
 
1619
- class DatabaseORMStatementSelect(DatabaseORMStatement, DatabaseORMStatementSelectSuper, Generic[DatabaseORMStatementReturn]):
1642
+ def where(self, *clauses: str | _ColumnExpressionArgument[bool]) -> Self:
1643
+ """
1644
+ Set `WHERE` syntax.
1645
+
1646
+ Parameters
1647
+ ----------
1648
+ clauses : Judgement clauses.
1649
+ - `str`: SQL string.
1650
+ - `_ColumnExpressionArgument[bool]`: Clause.
1651
+
1652
+ Returns
1653
+ -------
1654
+ Set self.
1655
+ """
1656
+
1657
+ # Set parameter.
1658
+ clauses = [
1659
+ sqlalchemy_text(clause)
1660
+ if type(clause) == str
1661
+ else clause
1662
+ for clause in clauses
1663
+ ]
1664
+
1665
+ # Super.
1666
+ stmt = super().where(*clauses)
1667
+
1668
+ return stmt
1669
+
1670
+
1671
+ class DatabaseORMStatementSelect(DatabaseORMStatement, DatabaseORMStatementSelectSuper, Generic[DatabaseORMModelT]):
1620
1672
  """
1621
1673
  Database ORM `select` statement type.
1622
1674
 
1623
1675
  Attributes
1624
1676
  ----------
1625
- inherit_cache : Compatible `Select` type.
1677
+ inherit_cache : Compatible type.
1626
1678
  """
1627
1679
 
1628
1680
  inherit_cache: Final = True
1629
1681
 
1630
1682
 
1631
1683
  @overload
1632
- def execute(self) -> DatabaseORMStatementReturn: ...
1684
+ def execute(self) -> list[DatabaseORMModelT]: ...
1633
1685
 
1634
1686
  execute = DatabaseORMStatement.execute
1635
1687
 
1636
1688
 
1637
- class DatabaseORMStatementInsert(DatabaseORMStatement[None], Insert):
1689
+ class DatabaseORMStatementSelectAsync(DatabaseORMStatementAsync, DatabaseORMStatementSelectSuper, Generic[DatabaseORMModelT]):
1638
1690
  """
1639
- Database ORM `insert` statement type.
1691
+ Asynchronous database ORM `select` statement type.
1640
1692
 
1641
1693
  Attributes
1642
1694
  ----------
1643
- inherit_cache : Compatible `Select` type.
1695
+ inherit_cache : Compatible type.
1644
1696
  """
1645
1697
 
1646
1698
  inherit_cache: Final = True
1647
1699
 
1648
1700
 
1649
- class DatabaseORMStatementUpdate(DatabaseORMStatement[None], Update):
1701
+ @overload
1702
+ async def execute(self) -> list[DatabaseORMModelT]: ...
1703
+
1704
+ execute = DatabaseORMStatementAsync.execute
1705
+
1706
+
1707
+ class DatabaseORMStatementInsertSuper(DatabaseORMStatementSuper, Insert):
1650
1708
  """
1651
- Database ORM `update` statement type.
1709
+ Database ORM `select` statement super type.
1652
1710
 
1653
1711
  Attributes
1654
1712
  ----------
1655
- inherit_cache : Compatible `Update` type.
1713
+ inherit_cache : Compatible type.
1656
1714
  """
1657
1715
 
1658
1716
  inherit_cache: Final = True
1659
1717
 
1660
1718
 
1661
- class DatabaseORMStatementDelete(DatabaseORMStatement[None], Delete):
1719
+ def ignore(self) -> Self:
1720
+ """
1721
+ Add `IGNORE` syntax.
1722
+
1723
+ Returns
1724
+ -------
1725
+ Set self.
1726
+ """
1727
+
1728
+ # Set.
1729
+ insert = self.prefix_with('IGNORE')
1730
+
1731
+ return insert
1732
+
1733
+
1734
+ @overload
1735
+ def update(self, *names: str) -> Self: ...
1736
+
1737
+ @overload
1738
+ def update(self, **values: Any) -> Self: ...
1739
+
1740
+ @overload
1741
+ def update(self) -> Self: ...
1742
+
1743
+ def update(self, *names: str, **values: Any) -> Self:
1744
+ """
1745
+ Add `ON DUPLICATE KEY UPDATE`.
1746
+
1747
+ Parameters
1748
+ ----------
1749
+ names : Field name. One to one update to this field value. (i.e. `field = VALUE(field)`)
1750
+ values : Scalar value. One to many update to this value. (i.e. `field = :value`)
1751
+ - `Empty`: All parameters omit. One to one update to all fields value. (i.e. `field = VALUE(field), ...`)
1752
+
1753
+ Returns
1754
+ -------
1755
+ Set self.
1756
+
1757
+ Examples
1758
+ --------
1759
+ >>> data = [{'score': 1}, {'score': 2}]
1760
+
1761
+ Name.
1762
+ >>> orm.insert(model).values(data).update('score')
1763
+
1764
+ Value.
1765
+ >>> orm.insert(model).values(data).update(score=0)
1766
+
1767
+ Empty.
1768
+ >>> orm.insert(model).values(data).update()
1769
+ """
1770
+
1771
+ # Set.
1772
+
1773
+ ## Name.
1774
+ if names != ():
1775
+ columns: dict[str, Column] = {
1776
+ name: self.inserted[name]
1777
+ for name in names
1778
+ }
1779
+ insert = self.on_duplicate_key_update(**columns)
1780
+
1781
+ ## Value.
1782
+ elif values != {}:
1783
+ insert = self.on_duplicate_key_update(**values)
1784
+
1785
+ ## Empty.
1786
+ else:
1787
+ columns: dict[str, Column] = dict(self.inserted.items())
1788
+ insert = self.on_duplicate_key_update(**columns)
1789
+
1790
+ return insert
1791
+
1792
+
1793
+ class DatabaseORMStatementInsert(DatabaseORMStatement, DatabaseORMStatementInsertSuper):
1662
1794
  """
1663
- Database ORM `delete` statement type.
1795
+ Database ORM `insert` statement type.
1664
1796
 
1665
1797
  Attributes
1666
1798
  ----------
1667
- inherit_cache : Compatible `Delete` type.
1799
+ inherit_cache : Compatible type.
1668
1800
  """
1669
1801
 
1670
1802
  inherit_cache: Final = True
1671
1803
 
1672
1804
 
1673
- class DatabaseORMStatementSelectAsync(DatabaseORMStatementAsync, DatabaseORMStatementSelectSuper, Generic[DatabaseORMStatementReturn]):
1805
+ class DatabaseORMStatementInsertAsync(DatabaseORMStatementAsync, DatabaseORMStatementInsertSuper):
1674
1806
  """
1675
- Asynchronous database ORM `select` statement type.
1807
+ Asynchronous database ORM `insert` statement type.
1676
1808
 
1677
1809
  Attributes
1678
1810
  ----------
1679
- inherit_cache : Compatible `Select` type.
1811
+ inherit_cache : Compatible type.
1680
1812
  """
1681
1813
 
1682
1814
  inherit_cache: Final = True
1683
1815
 
1684
1816
 
1685
- @overload
1686
- async def execute(self) -> DatabaseORMStatementReturn: ...
1817
+ class DatabaseORMStatementUpdateSuper(DatabaseORMStatementSuper, Update):
1818
+ """
1819
+ Database ORM `update` statement super type.
1687
1820
 
1688
- execute = DatabaseORMStatementAsync.execute
1821
+ Attributes
1822
+ ----------
1823
+ inherit_cache : Compatible type.
1824
+ """
1825
+
1826
+ inherit_cache: Final = True
1827
+
1828
+
1829
+ def where(self, *clauses: str | _ColumnExpressionArgument[bool]) -> Self:
1830
+ """
1831
+ Set `WHERE` syntax.
1832
+
1833
+ Parameters
1834
+ ----------
1835
+ clauses : Judgement clauses.
1836
+ - `str`: SQL string.
1837
+ - `_ColumnExpressionArgument[bool]`: Clause.
1838
+
1839
+ Returns
1840
+ -------
1841
+ Set self.
1842
+ """
1843
+
1844
+ # Set parameter.
1845
+ clauses = [
1846
+ sqlalchemy_text(clause)
1847
+ if type(clause) == str
1848
+ else clause
1849
+ for clause in clauses
1850
+ ]
1851
+
1852
+ # Super.
1853
+ stmt = super().where(*clauses)
1854
+
1855
+ return stmt
1689
1856
 
1690
1857
 
1691
- class DatabaseORMStatementInsertAsync(DatabaseORMStatementAsync[None], Insert):
1858
+ def limit(self, number: int) -> Self:
1859
+ """
1860
+ Set `limit` syntax.
1861
+
1862
+ Parameters
1863
+ ----------
1864
+ number : Limit number.
1865
+
1866
+ Returns
1867
+ -------
1868
+ Set self.
1869
+ """
1870
+
1871
+ # Set.
1872
+ update = self.with_dialect_options(mysql_limit=number)
1873
+
1874
+ return update
1875
+
1876
+
1877
+ class DatabaseORMStatementUpdate(DatabaseORMStatement, DatabaseORMStatementUpdateSuper):
1692
1878
  """
1693
- Asynchronous database ORM `insert` statement type.
1879
+ Database ORM `update` statement type.
1694
1880
 
1695
1881
  Attributes
1696
1882
  ----------
1697
- inherit_cache : Compatible `Select` type.
1883
+ inherit_cache : Compatible type.
1698
1884
  """
1699
1885
 
1700
1886
  inherit_cache: Final = True
1701
1887
 
1702
1888
 
1703
- class DatabaseORMStatementUpdateAsync(DatabaseORMStatementAsync[None], Update):
1889
+ class DatabaseORMStatementUpdateAsync(DatabaseORMStatementAsync, DatabaseORMStatementUpdateSuper):
1704
1890
  """
1705
1891
  Asynchronous database ORM `update` statement type.
1706
1892
 
1707
1893
  Attributes
1708
1894
  ----------
1709
- inherit_cache : Compatible `Update` type.
1895
+ inherit_cache : Compatible type.
1896
+ """
1897
+
1898
+ inherit_cache: Final = True
1899
+
1900
+
1901
+ class DatabaseORMStatementDeleteSuper(DatabaseORMStatementSuper, Delete):
1902
+ """
1903
+ Database ORM `delete` statement super type.
1904
+
1905
+ Attributes
1906
+ ----------
1907
+ inherit_cache : Compatible type.
1908
+ """
1909
+
1910
+ inherit_cache: Final = True
1911
+
1912
+
1913
+ def where(self, *clauses: str | _ColumnExpressionArgument[bool]) -> Self:
1914
+ """
1915
+ Set `WHERE` syntax.
1916
+
1917
+ Parameters
1918
+ ----------
1919
+ clauses : Judgement clauses.
1920
+ - `str`: SQL string.
1921
+ - `_ColumnExpressionArgument[bool]`: Clause.
1922
+
1923
+ Returns
1924
+ -------
1925
+ Set self.
1926
+ """
1927
+
1928
+ # Set parameter.
1929
+ clauses = [
1930
+ sqlalchemy_text(clause)
1931
+ if type(clause) == str
1932
+ else clause
1933
+ for clause in clauses
1934
+ ]
1935
+
1936
+ # Super.
1937
+ stmt = super().where(*clauses)
1938
+
1939
+ return stmt
1940
+
1941
+
1942
+ def limit(self, number: int) -> Self:
1943
+ """
1944
+ Set `limit` syntax.
1945
+
1946
+ Parameters
1947
+ ----------
1948
+ number : Limit number.
1949
+
1950
+ Returns
1951
+ -------
1952
+ Set self.
1953
+ """
1954
+
1955
+ # Set.
1956
+ update = self.with_dialect_options(mysql_limit=number)
1957
+
1958
+ return update
1959
+
1960
+
1961
+ class DatabaseORMStatementDelete(DatabaseORMStatement, DatabaseORMStatementDeleteSuper):
1962
+ """
1963
+ Database ORM `delete` statement type.
1964
+
1965
+ Attributes
1966
+ ----------
1967
+ inherit_cache : Compatible type.
1710
1968
  """
1711
1969
 
1712
1970
  inherit_cache: Final = True
1713
1971
 
1714
1972
 
1715
- class DatabaseORMStatementDeleteAsync(DatabaseORMStatementAsync[None], Delete):
1973
+ class DatabaseORMStatementDeleteAsync(DatabaseORMStatementAsync, DatabaseORMStatementDeleteSuper):
1716
1974
  """
1717
1975
  Asynchronous database ORM `delete` statement type.
1718
1976
 
1719
1977
  Attributes
1720
1978
  ----------
1721
- inherit_cache : Compatible `Delete` type.
1979
+ inherit_cache : Compatible type.
1722
1980
  """
1723
1981
 
1724
1982
  inherit_cache: Final = True
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reydb
3
- Version: 1.2.12
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=9tMDKivwju08kIAl7CahOMdvmuuO1Q_4I_JhMPWUbvg,19319
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
- reydb/rexec.py,sha256=u6ZU5dljUktICvJFhUIzg3U7ME9fhICL3NyqZugz5H4,53010
9
+ reydb/rexec.py,sha256=HSu8fCgBjpKY1z6OJI6Ky_0sKMPEv_uCAEAcN7fd2i4,53028
10
10
  reydb/rinfo.py,sha256=LjrqTA7JJbWJsjXwV-zKpbE1htv-whg6239hoQj4yIU,18151
11
- reydb/rorm.py,sha256=VkldNaXpTz-lGhrz-8CDuBWxnDY9uBbZphsP1Jpe84E,45188
12
- reydb-1.2.12.dist-info/METADATA,sha256=hE9zm7viJ_8CcZPI4NTZfGWqMn9AHQvvFtpmHEzCAbA,1622
13
- reydb-1.2.12.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
14
- reydb-1.2.12.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
15
- reydb-1.2.12.dist-info/RECORD,,
11
+ reydb/rorm.py,sha256=NxY2qOCXDwyy_lSRWZPxQDhG8IuLLxbaqIWxOZ1DDys,50791
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