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/__init__.py +0 -1
- reydb/rall.py +0 -1
- reydb/rbuild.py +8 -2
- reydb/rconfig.py +411 -24
- reydb/rdb.py +68 -66
- reydb/rexec.py +27 -78
- reydb/rorm.py +13 -6
- reydb/rparam.py +187 -55
- {reydb-1.1.60.dist-info → reydb-1.1.61.dist-info}/METADATA +1 -1
- reydb-1.1.61.dist-info/RECORD +16 -0
- reydb/rinfo.py +0 -499
- reydb-1.1.60.dist-info/RECORD +0 -17
- {reydb-1.1.60.dist-info → reydb-1.1.61.dist-info}/WHEEL +0 -0
- {reydb-1.1.60.dist-info → reydb-1.1.61.dist-info}/licenses/LICENSE +0 -0
reydb/rdb.py
CHANGED
@@ -16,7 +16,7 @@ from sqlalchemy import Engine, create_engine as sqlalchemy_create_engine
|
|
16
16
|
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine as sqlalchemy_create_async_engine
|
17
17
|
from reykit.rtext import join_data_text
|
18
18
|
|
19
|
-
from . import rbase, rbuild, rconfig, rconn, rerror, rexec, rfile,
|
19
|
+
from . import rbase, rbuild, rconfig, rconn, rerror, rexec, rfile, rorm, rparam
|
20
20
|
|
21
21
|
|
22
22
|
__all__ = (
|
@@ -28,9 +28,14 @@ __all__ = (
|
|
28
28
|
|
29
29
|
DatabaseConnectionT = TypeVar('DatabaseConnectionT', 'rconn.DatabaseConnection', 'rconn.DatabaseConnectionAsync')
|
30
30
|
DatabaseExecuteT = TypeVar('DatabaseExecuteT', 'rexec.DatabaseExecute', 'rexec.DatabaseExecuteAsync')
|
31
|
-
DatabaseSchemaT = TypeVar('DatabaseSchemaT', 'rparam.DatabaseSchema', 'rparam.DatabaseSchemaAsync')
|
32
31
|
DatabaseORMT = TypeVar('DatabaseORMT', 'rorm.DatabaseORM', 'rorm.DatabaseORMAsync')
|
33
|
-
DatabaseBuildT = TypeVar('DatabaseBuildT')
|
32
|
+
DatabaseBuildT = TypeVar('DatabaseBuildT', 'rbuild.DatabaseBuild', 'rbuild.DatabaseBuildAsync')
|
33
|
+
DatabaseConfigT = TypeVar('DatabaseConfigT', 'rconfig.DatabaseConfig', 'rconfig.DatabaseConfigAsync')
|
34
|
+
DatabaseSchemaT = TypeVar('DatabaseSchemaT', 'rparam.DatabaseSchema', 'rparam.DatabaseSchemaAsync')
|
35
|
+
DatabaseParametersVariablesT = TypeVar('DatabaseParametersVariablesT', 'rparam.DatabaseParametersVariables', 'rparam.DatabaseParametersVariablesAsync')
|
36
|
+
DatabaseParametersStatusT = TypeVar('DatabaseParametersStatusT', 'rparam.DatabaseParametersStatus', 'rparam.DatabaseParametersStatusAsync')
|
37
|
+
DatabaseParametersVariablesGlobalT = TypeVar('DatabaseParametersVariablesGlobalT', 'rparam.DatabaseParametersVariablesGlobal', 'rparam.DatabaseParametersVariablesGlobalAsync')
|
38
|
+
DatabaseParametersStatusGlobalT = TypeVar('DatabaseParametersStatusGlobalT', 'rparam.DatabaseParametersStatusGlobal', 'rparam.DatabaseParametersStatusGlobalAsync')
|
34
39
|
|
35
40
|
|
36
41
|
class DatabaseSuper(
|
@@ -39,9 +44,14 @@ class DatabaseSuper(
|
|
39
44
|
rbase.EngineT,
|
40
45
|
DatabaseConnectionT,
|
41
46
|
DatabaseExecuteT,
|
42
|
-
DatabaseSchemaT,
|
43
47
|
DatabaseORMT,
|
44
|
-
DatabaseBuildT
|
48
|
+
DatabaseBuildT,
|
49
|
+
DatabaseConfigT,
|
50
|
+
DatabaseSchemaT,
|
51
|
+
DatabaseParametersVariablesT,
|
52
|
+
DatabaseParametersStatusT,
|
53
|
+
DatabaseParametersVariablesGlobalT,
|
54
|
+
DatabaseParametersStatusGlobalT
|
45
55
|
]
|
46
56
|
):
|
47
57
|
"""
|
@@ -359,7 +369,7 @@ class DatabaseSuper(
|
|
359
369
|
|
360
370
|
|
361
371
|
@property
|
362
|
-
def config(self):
|
372
|
+
def config(self) -> DatabaseConfigT:
|
363
373
|
"""
|
364
374
|
Build database config instance.
|
365
375
|
|
@@ -369,45 +379,13 @@ class DatabaseSuper(
|
|
369
379
|
"""
|
370
380
|
|
371
381
|
# Build.
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
@property
|
378
|
-
def info(self):
|
379
|
-
"""
|
380
|
-
Build database information schema instance.
|
381
|
-
|
382
|
-
Returns
|
383
|
-
-------
|
384
|
-
Instance.
|
385
|
-
|
386
|
-
Examples
|
387
|
-
--------
|
388
|
-
Get databases information of server.
|
389
|
-
>>> databases_info = DatabaseInformationSchema()
|
390
|
-
|
391
|
-
Get tables information of database.
|
392
|
-
>>> tables_info = DatabaseInformationSchema.database()
|
393
|
-
|
394
|
-
Get columns information of table.
|
395
|
-
>>> columns_info = DatabaseInformationSchema.database.table()
|
396
|
-
|
397
|
-
Get database attribute.
|
398
|
-
>>> database_attr = DatabaseInformationSchema.database['attribute']
|
399
|
-
|
400
|
-
Get table attribute.
|
401
|
-
>>> database_attr = DatabaseInformationSchema.database.table['attribute']
|
402
|
-
|
403
|
-
Get column attribute.
|
404
|
-
>>> database_attr = DatabaseInformationSchema.database.table.column['attribute']
|
405
|
-
"""
|
406
|
-
|
407
|
-
# Build.
|
408
|
-
dbischema = rinfo.DatabaseInformationSchema(self)
|
382
|
+
match self:
|
383
|
+
case Database():
|
384
|
+
config = rconfig.DatabaseConfig(self)
|
385
|
+
case DatabaseAsync():
|
386
|
+
config = rconfig.DatabaseConfigAsync(self)
|
409
387
|
|
410
|
-
return
|
388
|
+
return config
|
411
389
|
|
412
390
|
|
413
391
|
@property
|
@@ -431,9 +409,9 @@ class DatabaseSuper(
|
|
431
409
|
|
432
410
|
|
433
411
|
@property
|
434
|
-
def
|
412
|
+
def var(self) -> DatabaseParametersVariablesT:
|
435
413
|
"""
|
436
|
-
Build database parameters
|
414
|
+
Build database parameters variable instance.
|
437
415
|
|
438
416
|
Returns
|
439
417
|
-------
|
@@ -441,15 +419,19 @@ class DatabaseSuper(
|
|
441
419
|
"""
|
442
420
|
|
443
421
|
# Build.
|
444
|
-
|
422
|
+
match self:
|
423
|
+
case Database():
|
424
|
+
var = rparam.DatabaseParametersVariables(self)
|
425
|
+
case DatabaseAsync():
|
426
|
+
var = rparam.DatabaseParametersVariablesAsync(self)
|
445
427
|
|
446
|
-
return
|
428
|
+
return var
|
447
429
|
|
448
430
|
|
449
431
|
@property
|
450
|
-
def
|
432
|
+
def stat(self) -> DatabaseParametersVariablesT:
|
451
433
|
"""
|
452
|
-
Build
|
434
|
+
Build database parameters status instance.
|
453
435
|
|
454
436
|
Returns
|
455
437
|
-------
|
@@ -457,15 +439,19 @@ class DatabaseSuper(
|
|
457
439
|
"""
|
458
440
|
|
459
441
|
# Build.
|
460
|
-
|
442
|
+
match self:
|
443
|
+
case Database():
|
444
|
+
stat = rparam.DatabaseParametersStatus(self)
|
445
|
+
case DatabaseAsync():
|
446
|
+
stat = rparam.DatabaseParametersStatusAsync(self)
|
461
447
|
|
462
|
-
return
|
448
|
+
return stat
|
463
449
|
|
464
450
|
|
465
451
|
@property
|
466
|
-
def
|
452
|
+
def glob_var(self) -> DatabaseParametersVariablesGlobalT:
|
467
453
|
"""
|
468
|
-
Build database parameters variable instance.
|
454
|
+
Build global database parameters variable instance.
|
469
455
|
|
470
456
|
Returns
|
471
457
|
-------
|
@@ -473,15 +459,19 @@ class DatabaseSuper(
|
|
473
459
|
"""
|
474
460
|
|
475
461
|
# Build.
|
476
|
-
|
462
|
+
match self:
|
463
|
+
case Database():
|
464
|
+
var = rparam.DatabaseParametersVariablesGlobal(self)
|
465
|
+
case DatabaseAsync():
|
466
|
+
var = rparam.DatabaseParametersVariablesGlobalAsync(self)
|
477
467
|
|
478
|
-
return
|
468
|
+
return var
|
479
469
|
|
480
470
|
|
481
471
|
@property
|
482
|
-
def
|
472
|
+
def glob_stat(self) -> DatabaseParametersStatusGlobalT:
|
483
473
|
"""
|
484
|
-
Build global database parameters
|
474
|
+
Build global database parameters status instance.
|
485
475
|
|
486
476
|
Returns
|
487
477
|
-------
|
@@ -489,11 +479,13 @@ class DatabaseSuper(
|
|
489
479
|
"""
|
490
480
|
|
491
481
|
# Build.
|
482
|
+
match self:
|
483
|
+
case Database():
|
484
|
+
stat = rparam.DatabaseParametersStatusGlobal(self)
|
485
|
+
case DatabaseAsync():
|
486
|
+
stat = rparam.DatabaseParametersStatusGlobalAsync(self)
|
492
487
|
|
493
|
-
|
494
|
-
dbpv = rparam.DatabaseParametersVariable(self, True)
|
495
|
-
|
496
|
-
return dbpv
|
488
|
+
return stat
|
497
489
|
|
498
490
|
|
499
491
|
class Database(
|
@@ -501,9 +493,14 @@ class Database(
|
|
501
493
|
Engine,
|
502
494
|
'rconn.DatabaseConnection',
|
503
495
|
'rexec.DatabaseExecute',
|
504
|
-
'rparam.DatabaseSchema',
|
505
496
|
'rorm.DatabaseORM',
|
506
|
-
'rbuild.DatabaseBuild'
|
497
|
+
'rbuild.DatabaseBuild',
|
498
|
+
'rconfig.DatabaseConfig',
|
499
|
+
'rparam.DatabaseSchema',
|
500
|
+
'rparam.DatabaseParametersVariables',
|
501
|
+
'rparam.DatabaseParametersStatus',
|
502
|
+
'rparam.DatabaseParametersVariablesGlobal',
|
503
|
+
'rparam.DatabaseParametersStatusGlobal'
|
507
504
|
]
|
508
505
|
):
|
509
506
|
"""
|
@@ -516,9 +513,14 @@ class DatabaseAsync(
|
|
516
513
|
AsyncEngine,
|
517
514
|
'rconn.DatabaseConnectionAsync',
|
518
515
|
'rexec.DatabaseExecuteAsync',
|
519
|
-
'rparam.DatabaseSchemaAsync',
|
520
516
|
'rorm.DatabaseORMAsync',
|
521
|
-
'rbuild.DatabaseBuildAsync'
|
517
|
+
'rbuild.DatabaseBuildAsync',
|
518
|
+
'rconfig.DatabaseConfigAsync',
|
519
|
+
'rparam.DatabaseSchemaAsync',
|
520
|
+
'rparam.DatabaseParametersVariablesAsync',
|
521
|
+
'rparam.DatabaseParametersStatusAsync',
|
522
|
+
'rparam.DatabaseParametersVariablesGlobalAsync',
|
523
|
+
'rparam.DatabaseParametersStatusGlobalAsync'
|
522
524
|
]
|
523
525
|
):
|
524
526
|
"""
|
reydb/rexec.py
CHANGED
@@ -29,6 +29,7 @@ from .rbase import DatabaseBase, handle_sql, handle_data, extract_path
|
|
29
29
|
|
30
30
|
__all__ = (
|
31
31
|
'Result',
|
32
|
+
'DatabaseExecuteSuper',
|
32
33
|
'DatabaseExecute',
|
33
34
|
'DatabaseExecuteAsync'
|
34
35
|
)
|
@@ -541,9 +542,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
541
542
|
def handle_copy(
|
542
543
|
self,
|
543
544
|
table: str,
|
545
|
+
fields: str | Iterable[str] | None = None,
|
544
546
|
where: str | None = None,
|
545
|
-
limit: int | str | tuple[int, int] | None = None
|
546
|
-
**kwdata: Any
|
547
|
+
limit: int | str | tuple[int, int] | None = None
|
547
548
|
) -> Result:
|
548
549
|
"""
|
549
550
|
Execute inesrt SQL of copy records.
|
@@ -551,15 +552,14 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
551
552
|
Parameters
|
552
553
|
----------
|
553
554
|
table : Table name, can include database name.
|
555
|
+
fields : Select clause content.
|
556
|
+
- `None`: Is `SELECT *`.
|
557
|
+
- `str`: Join as `SELECT str`.
|
558
|
+
- `Iterable[str]`: Join as `SELECT str`.
|
554
559
|
where : Clause `WHERE` content, join as `WHERE str`.
|
555
560
|
limit : Clause `LIMIT` content.
|
556
561
|
- `int | str`: Join as `LIMIT int/str`.
|
557
562
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
558
|
-
kwdata : Keyword parameters for filling.
|
559
|
-
- `In 'WHERE' syntax`: Fill 'WHERE' syntax.
|
560
|
-
- `Not in 'WHERE' syntax`: Fill 'INSERT' and 'SELECT' syntax.
|
561
|
-
`str and first character is ':'`: Use this syntax.
|
562
|
-
`Any`: Use this value.
|
563
563
|
|
564
564
|
Returns
|
565
565
|
-------
|
@@ -570,72 +570,23 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
570
570
|
database = self.conn.db.database
|
571
571
|
if '.' in table:
|
572
572
|
database, table, _ = extract_path(table)
|
573
|
-
|
574
|
-
|
575
|
-
fields
|
576
|
-
|
577
|
-
for row in table_info
|
578
|
-
]
|
579
|
-
pattern = '(?<!\\\\):(\\w+)'
|
580
|
-
if type(where) == str:
|
581
|
-
where_keys = findall(pattern, where)
|
582
|
-
else:
|
583
|
-
where_keys = ()
|
573
|
+
if fields is None:
|
574
|
+
fields = '*'
|
575
|
+
elif type(fields) != str:
|
576
|
+
fields = ', '.join(fields)
|
584
577
|
|
585
578
|
# Generate SQL.
|
586
579
|
sqls = []
|
587
580
|
|
588
581
|
## Part 'INSERT' syntax.
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
if field not in kwdata
|
593
|
-
)
|
594
|
-
if kwdata != {}:
|
595
|
-
sql_fields_kwdata = ', '.join(
|
596
|
-
f'`{field}`'
|
597
|
-
for field in kwdata
|
598
|
-
if field not in where_keys
|
599
|
-
)
|
600
|
-
sql_fields_filter = filter(
|
601
|
-
lambda sql: sql != '',
|
602
|
-
(
|
603
|
-
sql_fields,
|
604
|
-
sql_fields_kwdata
|
605
|
-
)
|
606
|
-
)
|
607
|
-
sql_fields = ', '.join(sql_fields_filter)
|
608
|
-
sql_insert = f'INSERT INTO `{database}`.`{table}`({sql_fields})'
|
582
|
+
sql_insert = f'INSERT INTO `{database}`.`{table}`'
|
583
|
+
if fields != '*':
|
584
|
+
sql_insert += f'({fields})'
|
609
585
|
sqls.append(sql_insert)
|
610
586
|
|
611
587
|
## Part 'SELECT' syntax.
|
612
|
-
sql_values = ', '.join(
|
613
|
-
f'`{field}`'
|
614
|
-
for field in fields
|
615
|
-
if field not in kwdata
|
616
|
-
)
|
617
|
-
if kwdata != {}:
|
618
|
-
sql_values_kwdata = ', '.join(
|
619
|
-
value[1:]
|
620
|
-
if (
|
621
|
-
type(value) == str
|
622
|
-
and value.startswith(':')
|
623
|
-
and value != ':'
|
624
|
-
)
|
625
|
-
else f':{field}'
|
626
|
-
for field, value in kwdata.items()
|
627
|
-
if field not in where_keys
|
628
|
-
)
|
629
|
-
sql_values_filter = filter(
|
630
|
-
lambda sql: sql != '',
|
631
|
-
(
|
632
|
-
sql_values,
|
633
|
-
sql_values_kwdata
|
634
|
-
)
|
635
|
-
)
|
636
|
-
sql_values = ', '.join(sql_values_filter)
|
637
588
|
sql_select = (
|
638
|
-
f'SELECT {
|
589
|
+
f'SELECT {fields}\n'
|
639
590
|
f'FROM `{database}`.`{table}`'
|
640
591
|
)
|
641
592
|
sqls.append(sql_select)
|
@@ -954,6 +905,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
954
905
|
def copy(
|
955
906
|
self,
|
956
907
|
table: str,
|
908
|
+
fields: str | Iterable[str] | None = None,
|
957
909
|
where: str | None = None,
|
958
910
|
limit: int | str | tuple[int, int] | None = None,
|
959
911
|
report: bool | None = None,
|
@@ -965,17 +917,15 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
965
917
|
Parameters
|
966
918
|
----------
|
967
919
|
table : Table name, can include database name.
|
920
|
+
fields : Select clause content.
|
921
|
+
- `None`: Is `SELECT *`.
|
922
|
+
- `str`: Join as `SELECT str`.
|
923
|
+
- `Iterable[str]`: Join as `SELECT str`.
|
968
924
|
where : Clause `WHERE` content, join as `WHERE str`.
|
969
925
|
limit : Clause `LIMIT` content.
|
970
926
|
- `int | str`: Join as `LIMIT int/str`.
|
971
927
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
972
|
-
report : Whether report SQL execute information.
|
973
|
-
- `None`: Use attribute `Database.report`.
|
974
928
|
kwdata : Keyword parameters for filling.
|
975
|
-
- `In 'WHERE' syntax`: Fill 'WHERE' syntax.
|
976
|
-
- `Not in 'WHERE' syntax`: Fill 'INSERT' and 'SELECT' syntax.
|
977
|
-
`str and first character is ':'`: Use this syntax.
|
978
|
-
`Any`: Use this value.
|
979
929
|
|
980
930
|
Returns
|
981
931
|
-------
|
@@ -992,7 +942,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
992
942
|
"""
|
993
943
|
|
994
944
|
# Handle parameter.
|
995
|
-
sql = self.handle_copy(table, where, limit
|
945
|
+
sql = self.handle_copy(table, fields, where, limit)
|
996
946
|
|
997
947
|
# Execute SQL.
|
998
948
|
result = self.execute(sql, report=report, **kwdata)
|
@@ -1492,6 +1442,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1492
1442
|
async def copy(
|
1493
1443
|
self,
|
1494
1444
|
table: str,
|
1445
|
+
fields: str | Iterable[str] | None = None,
|
1495
1446
|
where: str | None = None,
|
1496
1447
|
limit: int | str | tuple[int, int] | None = None,
|
1497
1448
|
report: bool | None = None,
|
@@ -1503,17 +1454,15 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1503
1454
|
Parameters
|
1504
1455
|
----------
|
1505
1456
|
table : Table name, can include database name.
|
1457
|
+
fields : Select clause content.
|
1458
|
+
- `None`: Is `SELECT *`.
|
1459
|
+
- `str`: Join as `SELECT str`.
|
1460
|
+
- `Iterable[str]`: Join as `SELECT str`.
|
1506
1461
|
where : Clause `WHERE` content, join as `WHERE str`.
|
1507
1462
|
limit : Clause `LIMIT` content.
|
1508
1463
|
- `int | str`: Join as `LIMIT int/str`.
|
1509
1464
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
1510
|
-
report : Whether report SQL execute information.
|
1511
|
-
- `None`: Use attribute `Database.report`.
|
1512
1465
|
kwdata : Keyword parameters for filling.
|
1513
|
-
- `In 'WHERE' syntax`: Fill 'WHERE' syntax.
|
1514
|
-
- `Not in 'WHERE' syntax`: Fill 'INSERT' and 'SELECT' syntax.
|
1515
|
-
`str and first character is ':'`: Use this syntax.
|
1516
|
-
`Any`: Use this value.
|
1517
1466
|
|
1518
1467
|
Returns
|
1519
1468
|
-------
|
@@ -1530,7 +1479,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1530
1479
|
"""
|
1531
1480
|
|
1532
1481
|
# Handle parameter.
|
1533
|
-
sql = self.handle_copy(table, where, limit
|
1482
|
+
sql = self.handle_copy(table, fields, where, limit)
|
1534
1483
|
|
1535
1484
|
# Execute SQL.
|
1536
1485
|
result = await self.execute(sql, report=report, **kwdata)
|
reydb/rorm.py
CHANGED
@@ -9,11 +9,12 @@
|
|
9
9
|
"""
|
10
10
|
|
11
11
|
|
12
|
-
from typing import Self, Any, Type, TypeVar, Generic, Final, overload
|
12
|
+
from typing import Self, Any, Type, Literal, TypeVar, Generic, Final, overload
|
13
13
|
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 text as sqlalchemy_text
|
17
18
|
from sqlalchemy.orm import SessionTransaction
|
18
19
|
from sqlalchemy.ext.asyncio import AsyncSessionTransaction
|
19
20
|
from sqlalchemy.sql import sqltypes
|
@@ -100,7 +101,7 @@ class DatabaseORMModelMeta(DatabaseORMBase, SQLModelMetaclass):
|
|
100
101
|
"""
|
101
102
|
|
102
103
|
# Handle parameter.
|
103
|
-
if
|
104
|
+
if '__annotations__' in attrs:
|
104
105
|
table_args = attrs.setdefault('__table_args__', {})
|
105
106
|
table_args['quote'] = True
|
106
107
|
|
@@ -110,7 +111,7 @@ class DatabaseORMModelMeta(DatabaseORMBase, SQLModelMetaclass):
|
|
110
111
|
|
111
112
|
## Name.
|
112
113
|
if '__name__' in attrs:
|
113
|
-
|
114
|
+
name = attrs.pop('__name__')
|
114
115
|
|
115
116
|
## Comment.
|
116
117
|
if '__comment__' in attrs:
|
@@ -232,7 +233,7 @@ class DatabaseORMModel(DatabaseORMBase, SQLModel, metaclass=model_metaclass):
|
|
232
233
|
table.comment = comment
|
233
234
|
|
234
235
|
|
235
|
-
class DatabaseORMModelField(
|
236
|
+
class DatabaseORMModelField(DatabaseORMBase, FieldInfo):
|
236
237
|
"""
|
237
238
|
Database ORM model filed type.
|
238
239
|
|
@@ -249,7 +250,7 @@ class DatabaseORMModelField(DatabaseBase, FieldInfo):
|
|
249
250
|
arg_default: Any | Callable[[], Any] | Null = Null,
|
250
251
|
*,
|
251
252
|
arg_name: str | None = None,
|
252
|
-
field_default: str | None = None,
|
253
|
+
field_default: str | Literal['CURRENT_TIMESTAMP'] | Literal['ON UPDATE CURRENT_TIMESTAMP'] | None = None,
|
253
254
|
filed_name: str | None = None,
|
254
255
|
field_type: TypeEngine | None = None,
|
255
256
|
key: bool = False,
|
@@ -286,6 +287,8 @@ class DatabaseORMModelField(DatabaseBase, FieldInfo):
|
|
286
287
|
arg_name : Call argument name.
|
287
288
|
- `None`: Same as attribute name.
|
288
289
|
field_default : Database field defualt value.
|
290
|
+
- `Literal['current_timestamp']`: Set SQL syntax 'current_timestamp', case insensitive.
|
291
|
+
- `Literal['on update current_timestamp']`: Set SQL syntax 'on update current_timestamp', case insensitive.
|
289
292
|
filed_name : Database field name.
|
290
293
|
- `None`: Same as attribute name.
|
291
294
|
field_type : Database field type.
|
@@ -356,7 +359,11 @@ class DatabaseORMModelField(DatabaseBase, FieldInfo):
|
|
356
359
|
|
357
360
|
## Field default.
|
358
361
|
if 'field_default' in kwargs:
|
359
|
-
|
362
|
+
field_default: str = kwargs.pop('field_default')
|
363
|
+
field_default_upper = field_default.upper()
|
364
|
+
if field_default_upper in ('CURRENT_TIMESTAMP', 'ON UPDATE CURRENT_TIMESTAMP'):
|
365
|
+
field_default = sqlalchemy_text(field_default_upper)
|
366
|
+
kwargs['sa_column_kwargs']['server_default'] = field_default
|
360
367
|
|
361
368
|
## Field name.
|
362
369
|
if 'filed_name' in kwargs:
|