reydb 1.2.12__py3-none-any.whl → 1.2.13__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 +39 -43
- reydb/rexec.py +3 -2
- reydb/rorm.py +318 -60
- {reydb-1.2.12.dist-info → reydb-1.2.13.dist-info}/METADATA +1 -1
- {reydb-1.2.12.dist-info → reydb-1.2.13.dist-info}/RECORD +7 -7
- {reydb-1.2.12.dist-info → reydb-1.2.13.dist-info}/WHEEL +0 -0
- {reydb-1.2.12.dist-info → reydb-1.2.13.dist-info}/licenses/LICENSE +0 -0
reydb/rconfig.py
CHANGED
@@ -170,23 +170,25 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
170
170
|
"""
|
171
171
|
|
172
172
|
# Get.
|
173
|
-
|
174
|
-
DatabaseTableConfig
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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()
|
181
|
+
)
|
180
182
|
|
181
183
|
# Convert.
|
182
184
|
global_dict = {'datetime': Datetime}
|
183
185
|
result = [
|
184
186
|
{
|
185
|
-
'key':
|
186
|
-
'value': eval(
|
187
|
-
'note':
|
187
|
+
'key': model.key,
|
188
|
+
'value': eval(model.value, global_dict),
|
189
|
+
'note': model.note
|
188
190
|
}
|
189
|
-
for
|
191
|
+
for model in models
|
190
192
|
]
|
191
193
|
|
192
194
|
return result
|
@@ -207,18 +209,10 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
207
209
|
"""
|
208
210
|
|
209
211
|
# Get.
|
210
|
-
|
211
|
-
result = self.db.execute.select(
|
212
|
-
self.db_names['config'],
|
213
|
-
'`value`',
|
214
|
-
where,
|
215
|
-
limit=1,
|
216
|
-
key=key
|
217
|
-
)
|
218
|
-
value = result.scalar()
|
212
|
+
model = self.db.orm.get(DatabaseTableConfig, key)
|
219
213
|
|
220
214
|
# Default.
|
221
|
-
if value is None:
|
215
|
+
if model.value is None:
|
222
216
|
value = default
|
223
217
|
else:
|
224
218
|
global_dict = {'datetime': Datetime}
|
@@ -254,10 +248,11 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
254
248
|
'type': type(default).__name__,
|
255
249
|
'note': default_note
|
256
250
|
}
|
257
|
-
result =
|
258
|
-
self.
|
259
|
-
data
|
260
|
-
|
251
|
+
result = (
|
252
|
+
self.db.orm.insert(DatabaseTableConfig)
|
253
|
+
.values(data)
|
254
|
+
.ignore()
|
255
|
+
.execute()
|
261
256
|
)
|
262
257
|
|
263
258
|
# Get.
|
@@ -295,10 +290,11 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
295
290
|
row['type'] = type(row['value']).__name__
|
296
291
|
|
297
292
|
# Update.
|
298
|
-
|
299
|
-
self.
|
300
|
-
data
|
301
|
-
|
293
|
+
(
|
294
|
+
self.db.orm.insert(DatabaseTableConfig)
|
295
|
+
.values(data)
|
296
|
+
.update()
|
297
|
+
.execute()
|
302
298
|
)
|
303
299
|
|
304
300
|
|
@@ -313,16 +309,16 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
313
309
|
|
314
310
|
# Remove.
|
315
311
|
if type(key) == str:
|
316
|
-
where =
|
312
|
+
where = DatabaseTableConfig == key
|
317
313
|
limit = 1
|
318
314
|
else:
|
319
|
-
where =
|
315
|
+
where = DatabaseTableConfig in key
|
320
316
|
limit = None
|
321
|
-
result =
|
322
|
-
self.
|
323
|
-
where
|
324
|
-
limit
|
325
|
-
|
317
|
+
result = (
|
318
|
+
self.db.orm.delete(DatabaseTableConfig)
|
319
|
+
.where(where)
|
320
|
+
.limit(limit)
|
321
|
+
.execute()
|
326
322
|
)
|
327
323
|
|
328
324
|
# Check.
|
@@ -340,17 +336,17 @@ class DatabaseConfig(DatabaseConfigSuper['rdb.Database']):
|
|
340
336
|
"""
|
341
337
|
|
342
338
|
# Get.
|
343
|
-
|
344
|
-
self.
|
345
|
-
|
339
|
+
models = (
|
340
|
+
self.db.orm.select(DatabaseTableConfig)
|
341
|
+
.fields('key', 'value')
|
342
|
+
.execute()
|
346
343
|
)
|
347
344
|
|
348
345
|
# Convert.
|
349
346
|
global_dict = {'datetime': Datetime}
|
350
|
-
result = result.to_dict('key', 'value')
|
351
347
|
result = {
|
352
|
-
key: eval(value, global_dict)
|
353
|
-
for
|
348
|
+
model.key: eval(model.value, global_dict)
|
349
|
+
for model in models
|
354
350
|
}
|
355
351
|
|
356
352
|
return result
|
@@ -644,7 +640,7 @@ class DatabaseConfigAsync(DatabaseConfigSuper['rdb.DatabaseAsync']):
|
|
644
640
|
where = '`key` in :key'
|
645
641
|
limit = None
|
646
642
|
result = await self.db.execute.delete(
|
647
|
-
self.db_names['
|
643
|
+
self.db_names['config'],
|
648
644
|
where,
|
649
645
|
limit=limit,
|
650
646
|
key=key
|
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
|
-
|
39
|
-
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
|
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
|
-
|
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[
|
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[
|
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]
|
1515
|
+
class DatabaseORMStatement(DatabaseORMStatementSuper[DatabaseORMSession]):
|
1511
1516
|
"""
|
1512
1517
|
Database ORM statement type.
|
1513
1518
|
"""
|
1514
1519
|
|
1515
1520
|
|
1516
|
-
def execute(self) ->
|
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
|
-
|
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]
|
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) ->
|
1566
|
+
async def execute(self) -> Result:
|
1555
1567
|
"""
|
1556
|
-
|
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
|
-
|
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
|
1612
|
+
inherit_cache : Compatible type.
|
1594
1613
|
"""
|
1595
1614
|
|
1596
1615
|
inherit_cache: Final = True
|
1597
1616
|
|
1598
1617
|
|
1599
|
-
def fields(self, *
|
1618
|
+
def fields(self, *names: str) -> Self:
|
1600
1619
|
"""
|
1601
1620
|
Replace select fiedls.
|
1602
1621
|
|
1603
1622
|
Parameters
|
1604
1623
|
----------
|
1605
|
-
|
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
|
-
|
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
|
-
|
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
|
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) ->
|
1684
|
+
def execute(self) -> list[DatabaseORMModelT]: ...
|
1633
1685
|
|
1634
1686
|
execute = DatabaseORMStatement.execute
|
1635
1687
|
|
1636
1688
|
|
1637
|
-
class
|
1689
|
+
class DatabaseORMStatementSelectAsync(DatabaseORMStatementAsync, DatabaseORMStatementSelectSuper, Generic[DatabaseORMModelT]):
|
1638
1690
|
"""
|
1639
|
-
|
1691
|
+
Asynchronous database ORM `select` statement type.
|
1640
1692
|
|
1641
1693
|
Attributes
|
1642
1694
|
----------
|
1643
|
-
inherit_cache : Compatible
|
1695
|
+
inherit_cache : Compatible type.
|
1644
1696
|
"""
|
1645
1697
|
|
1646
1698
|
inherit_cache: Final = True
|
1647
1699
|
|
1648
1700
|
|
1649
|
-
|
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 `
|
1709
|
+
Database ORM `select` statement super type.
|
1652
1710
|
|
1653
1711
|
Attributes
|
1654
1712
|
----------
|
1655
|
-
inherit_cache : Compatible
|
1713
|
+
inherit_cache : Compatible type.
|
1656
1714
|
"""
|
1657
1715
|
|
1658
1716
|
inherit_cache: Final = True
|
1659
1717
|
|
1660
1718
|
|
1661
|
-
|
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 `
|
1795
|
+
Database ORM `insert` statement type.
|
1664
1796
|
|
1665
1797
|
Attributes
|
1666
1798
|
----------
|
1667
|
-
inherit_cache : Compatible
|
1799
|
+
inherit_cache : Compatible type.
|
1668
1800
|
"""
|
1669
1801
|
|
1670
1802
|
inherit_cache: Final = True
|
1671
1803
|
|
1672
1804
|
|
1673
|
-
class
|
1805
|
+
class DatabaseORMStatementInsertAsync(DatabaseORMStatementAsync, DatabaseORMStatementInsertSuper):
|
1674
1806
|
"""
|
1675
|
-
Asynchronous database ORM `
|
1807
|
+
Asynchronous database ORM `insert` statement type.
|
1676
1808
|
|
1677
1809
|
Attributes
|
1678
1810
|
----------
|
1679
|
-
inherit_cache : Compatible
|
1811
|
+
inherit_cache : Compatible type.
|
1680
1812
|
"""
|
1681
1813
|
|
1682
1814
|
inherit_cache: Final = True
|
1683
1815
|
|
1684
1816
|
|
1685
|
-
|
1686
|
-
|
1817
|
+
class DatabaseORMStatementUpdateSuper(DatabaseORMStatementSuper, Update):
|
1818
|
+
"""
|
1819
|
+
Database ORM `update` statement super type.
|
1687
1820
|
|
1688
|
-
|
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
|
-
|
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
|
-
|
1879
|
+
Database ORM `update` statement type.
|
1694
1880
|
|
1695
1881
|
Attributes
|
1696
1882
|
----------
|
1697
|
-
inherit_cache : Compatible
|
1883
|
+
inherit_cache : Compatible type.
|
1698
1884
|
"""
|
1699
1885
|
|
1700
1886
|
inherit_cache: Final = True
|
1701
1887
|
|
1702
1888
|
|
1703
|
-
class DatabaseORMStatementUpdateAsync(DatabaseORMStatementAsync
|
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
|
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
|
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
|
1979
|
+
inherit_cache : Compatible type.
|
1722
1980
|
"""
|
1723
1981
|
|
1724
1982
|
inherit_cache: Final = True
|
@@ -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=
|
5
|
+
reydb/rconfig.py,sha256=xXNZf0yMkNWK_7NMpCUg0osYHLCVYsy0QV3qlSvmVSI,19229
|
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=
|
9
|
+
reydb/rexec.py,sha256=HSu8fCgBjpKY1z6OJI6Ky_0sKMPEv_uCAEAcN7fd2i4,53028
|
10
10
|
reydb/rinfo.py,sha256=LjrqTA7JJbWJsjXwV-zKpbE1htv-whg6239hoQj4yIU,18151
|
11
|
-
reydb/rorm.py,sha256=
|
12
|
-
reydb-1.2.
|
13
|
-
reydb-1.2.
|
14
|
-
reydb-1.2.
|
15
|
-
reydb-1.2.
|
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,,
|
File without changes
|
File without changes
|