reydb 1.1.61__py3-none-any.whl → 1.2.1__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 +1 -2
- reydb/rall.py +1 -2
- reydb/rbase.py +0 -48
- reydb/rbuild.py +121 -313
- reydb/rconfig.py +53 -98
- reydb/rdb.py +68 -57
- reydb/rerror.py +305 -111
- reydb/rexec.py +224 -192
- reydb/{rparam.py → rinfo.py} +271 -56
- reydb/rorm.py +139 -115
- {reydb-1.1.61.dist-info → reydb-1.2.1.dist-info}/METADATA +1 -1
- reydb-1.2.1.dist-info/RECORD +15 -0
- reydb/rfile.py +0 -482
- reydb-1.1.61.dist-info/RECORD +0 -16
- {reydb-1.1.61.dist-info → reydb-1.2.1.dist-info}/WHEEL +0 -0
- {reydb-1.1.61.dist-info → reydb-1.2.1.dist-info}/licenses/LICENSE +0 -0
reydb/rexec.py
CHANGED
@@ -18,13 +18,13 @@ from reykit.rdata import FunctionGenerator
|
|
18
18
|
from reykit.rmonkey import monkey_sqlalchemy_result_more_fetch, monkey_sqlalchemy_row_index_field
|
19
19
|
from reykit.rrand import randn
|
20
20
|
from reykit.rre import findall
|
21
|
-
from reykit.rstdout import echo
|
21
|
+
from reykit.rstdout import echo as recho
|
22
22
|
from reykit.rtable import TableData, Table
|
23
23
|
from reykit.rtime import TimeMark, time_to
|
24
24
|
from reykit.rwrap import wrap_runtime
|
25
25
|
|
26
26
|
from . import rconn
|
27
|
-
from .rbase import DatabaseBase, handle_sql, handle_data
|
27
|
+
from .rbase import DatabaseBase, handle_sql, handle_data
|
28
28
|
|
29
29
|
|
30
30
|
__all__ = (
|
@@ -67,18 +67,18 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
67
67
|
self,
|
68
68
|
sql: str | TextClause,
|
69
69
|
data: TableData | None = None,
|
70
|
-
|
70
|
+
echo: bool | None = None,
|
71
71
|
**kwdata: Any
|
72
72
|
) -> tuple[TextClause, list[dict], bool]:
|
73
73
|
"""
|
74
|
-
Handle
|
74
|
+
Handle method of execute SQL.
|
75
75
|
|
76
76
|
Parameters
|
77
77
|
----------
|
78
78
|
sql : SQL in method `sqlalchemy.text` format, or `TextClause` object.
|
79
79
|
data : Data set for filling.
|
80
|
-
|
81
|
-
- `None`: Use attribute `Database.
|
80
|
+
echo : Whether report SQL execute information.
|
81
|
+
- `None`: Use attribute `Database.echo`.
|
82
82
|
- `bool`: Use this value.
|
83
83
|
kwdata : Keyword parameters for filling.
|
84
84
|
|
@@ -88,7 +88,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
88
88
|
"""
|
89
89
|
|
90
90
|
# Handle parameter.
|
91
|
-
|
91
|
+
echo = get_first_notnone(echo, self.conn.db.echo)
|
92
92
|
sql = handle_sql(sql)
|
93
93
|
if data is None:
|
94
94
|
if kwdata == {}:
|
@@ -102,12 +102,12 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
102
102
|
row.update(kwdata)
|
103
103
|
data = handle_data(data, sql)
|
104
104
|
|
105
|
-
return sql, data,
|
105
|
+
return sql, data, echo
|
106
106
|
|
107
107
|
|
108
108
|
def handle_select(
|
109
109
|
self,
|
110
|
-
|
110
|
+
path: str | tuple[str, str],
|
111
111
|
fields: str | Iterable[str] | None = None,
|
112
112
|
where: str | None = None,
|
113
113
|
group: str | None = None,
|
@@ -116,11 +116,13 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
116
116
|
limit: int | str | tuple[int, int] | None = None
|
117
117
|
) -> str:
|
118
118
|
"""
|
119
|
-
Handle
|
119
|
+
Handle method of execute select SQL.
|
120
120
|
|
121
121
|
Parameters
|
122
122
|
----------
|
123
|
-
|
123
|
+
path : Path.
|
124
|
+
- `str`: Table name.
|
125
|
+
- `tuple[str, str]`: Database name and table name.
|
124
126
|
fields : Select clause content.
|
125
127
|
- `None`: Is `SELECT *`.
|
126
128
|
- `str`: Join as `SELECT str`.
|
@@ -141,9 +143,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
141
143
|
"""
|
142
144
|
|
143
145
|
# Handle parameter.
|
144
|
-
|
145
|
-
|
146
|
-
|
146
|
+
if type(path) == str:
|
147
|
+
database, table = self.conn.db.database, path
|
148
|
+
else:
|
149
|
+
database, table = path
|
147
150
|
|
148
151
|
# Generate SQL.
|
149
152
|
sql_list = []
|
@@ -209,17 +212,19 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
209
212
|
|
210
213
|
def handle_insert(
|
211
214
|
self,
|
212
|
-
|
215
|
+
path: str | tuple[str, str],
|
213
216
|
data: TableData,
|
214
217
|
duplicate: Literal['ignore', 'update'] | Container[str] | None = None,
|
215
218
|
**kwdata: Any
|
216
219
|
) -> Result:
|
217
220
|
"""
|
218
|
-
Handle
|
221
|
+
Handle method of execute insert SQL.
|
219
222
|
|
220
223
|
Parameters
|
221
224
|
----------
|
222
|
-
|
225
|
+
path : Path.
|
226
|
+
- `str`: Table name.
|
227
|
+
- `tuple[str, str]`: Database name and table name.
|
223
228
|
data : Insert data.
|
224
229
|
duplicate : Handle method when constraint error.
|
225
230
|
- `None`: Not handled.
|
@@ -236,9 +241,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
236
241
|
"""
|
237
242
|
|
238
243
|
# Handle parameter.
|
239
|
-
|
240
|
-
|
241
|
-
|
244
|
+
if type(path) == str:
|
245
|
+
database, table = self.conn.db.database, path
|
246
|
+
else:
|
247
|
+
database, table = path
|
242
248
|
|
243
249
|
## Data.
|
244
250
|
data_table = Table(data)
|
@@ -343,7 +349,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
343
349
|
|
344
350
|
def handle_update(
|
345
351
|
self,
|
346
|
-
|
352
|
+
path: str | tuple[str, str],
|
347
353
|
data: TableData,
|
348
354
|
where_fields: str | Iterable[str] | None = None,
|
349
355
|
**kwdata: Any
|
@@ -353,7 +359,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
353
359
|
|
354
360
|
Parameters
|
355
361
|
----------
|
356
|
-
|
362
|
+
path : Path.
|
363
|
+
- `str`: Table name.
|
364
|
+
- `tuple[str, str]`: Database name and table name.
|
357
365
|
data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
|
358
366
|
- `Key`: Table field.
|
359
367
|
`literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
|
@@ -376,9 +384,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
376
384
|
"""
|
377
385
|
|
378
386
|
# Handle parameter.
|
379
|
-
|
380
|
-
|
381
|
-
|
387
|
+
if type(path) == str:
|
388
|
+
database, table = self.conn.db.database, path
|
389
|
+
else:
|
390
|
+
database, table = path
|
382
391
|
|
383
392
|
## Data.
|
384
393
|
data_table = Table(data)
|
@@ -486,7 +495,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
486
495
|
|
487
496
|
def handle_delete(
|
488
497
|
self,
|
489
|
-
|
498
|
+
path: str | tuple[str, str],
|
490
499
|
where: str | None = None,
|
491
500
|
order: str | None = None,
|
492
501
|
limit: int | str | None = None
|
@@ -496,7 +505,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
496
505
|
|
497
506
|
Parameters
|
498
507
|
----------
|
499
|
-
|
508
|
+
path : Path.
|
509
|
+
- `str`: Table name.
|
510
|
+
- `tuple[str, str]`: Database name and table name.
|
500
511
|
where : Clause `WHERE` content, join as `WHERE str`.
|
501
512
|
order : Clause `ORDER BY` content, join as `ORDER BY str`.
|
502
513
|
limit : Clause `LIMIT` content, join as `LIMIT int/str`.
|
@@ -507,9 +518,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
507
518
|
"""
|
508
519
|
|
509
520
|
# Handle parameter.
|
510
|
-
|
511
|
-
|
512
|
-
|
521
|
+
if type(path) == str:
|
522
|
+
database, table = self.conn.db.database, path
|
523
|
+
else:
|
524
|
+
database, table = path
|
513
525
|
|
514
526
|
# Generate SQL.
|
515
527
|
sqls = []
|
@@ -541,7 +553,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
541
553
|
|
542
554
|
def handle_copy(
|
543
555
|
self,
|
544
|
-
|
556
|
+
path: str | tuple[str, str],
|
545
557
|
fields: str | Iterable[str] | None = None,
|
546
558
|
where: str | None = None,
|
547
559
|
limit: int | str | tuple[int, int] | None = None
|
@@ -551,7 +563,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
551
563
|
|
552
564
|
Parameters
|
553
565
|
----------
|
554
|
-
|
566
|
+
path : Path.
|
567
|
+
- `str`: Table name.
|
568
|
+
- `tuple[str, str]`: Database name and table name.
|
555
569
|
fields : Select clause content.
|
556
570
|
- `None`: Is `SELECT *`.
|
557
571
|
- `str`: Join as `SELECT str`.
|
@@ -567,9 +581,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
|
|
567
581
|
"""
|
568
582
|
|
569
583
|
# Handle parameter.
|
570
|
-
|
571
|
-
|
572
|
-
|
584
|
+
if type(path) == str:
|
585
|
+
database, table = self.conn.db.database, path
|
586
|
+
else:
|
587
|
+
database, table = path
|
573
588
|
if fields is None:
|
574
589
|
fields = '*'
|
575
590
|
elif type(fields) != str:
|
@@ -623,7 +638,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
623
638
|
self,
|
624
639
|
sql: str | TextClause,
|
625
640
|
data: TableData | None = None,
|
626
|
-
|
641
|
+
echo: bool | None = None,
|
627
642
|
**kwdata: Any
|
628
643
|
) -> Result:
|
629
644
|
"""
|
@@ -633,8 +648,8 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
633
648
|
----------
|
634
649
|
sql : SQL in method `sqlalchemy.text` format, or `TextClause` object.
|
635
650
|
data : Data set for filling.
|
636
|
-
|
637
|
-
- `None`: Use attribute `Database.
|
651
|
+
echo : Whether report SQL execute information.
|
652
|
+
- `None`: Use attribute `Database.echo`.
|
638
653
|
- `bool`: Use this value.
|
639
654
|
kwdata : Keyword parameters for filling.
|
640
655
|
|
@@ -644,7 +659,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
644
659
|
"""
|
645
660
|
|
646
661
|
# Handle parameter.
|
647
|
-
sql, data,
|
662
|
+
sql, data, echo = self.handle_execute(sql, data, echo, **kwdata)
|
648
663
|
|
649
664
|
# Transaction.
|
650
665
|
self.conn.get_begin()
|
@@ -652,7 +667,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
652
667
|
# Execute.
|
653
668
|
|
654
669
|
## Report.
|
655
|
-
if
|
670
|
+
if echo:
|
656
671
|
execute = wrap_runtime(self.conn.connection.execute, to_return=True, to_print=False)
|
657
672
|
result, report_runtime, *_ = execute(sql, data)
|
658
673
|
report_info = (
|
@@ -665,9 +680,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
665
680
|
if sql_part != ''
|
666
681
|
]
|
667
682
|
if data == []:
|
668
|
-
|
683
|
+
recho(report_info, *sqls, title='SQL')
|
669
684
|
else:
|
670
|
-
|
685
|
+
recho(report_info, *sqls, data, title='SQL')
|
671
686
|
|
672
687
|
## Not report.
|
673
688
|
else:
|
@@ -686,14 +701,14 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
686
701
|
|
687
702
|
def select(
|
688
703
|
self,
|
689
|
-
|
704
|
+
path: str | tuple[str, str],
|
690
705
|
fields: str | Iterable[str] | None = None,
|
691
706
|
where: str | None = None,
|
692
707
|
group: str | None = None,
|
693
708
|
having: str | None = None,
|
694
709
|
order: str | None = None,
|
695
710
|
limit: int | str | tuple[int, int] | None = None,
|
696
|
-
|
711
|
+
echo: bool | None = None,
|
697
712
|
**kwdata: Any
|
698
713
|
) -> Result:
|
699
714
|
"""
|
@@ -701,7 +716,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
701
716
|
|
702
717
|
Parameters
|
703
718
|
----------
|
704
|
-
|
719
|
+
path : Path.
|
720
|
+
- `str`: Table name.
|
721
|
+
- `tuple[str, str]`: Database name and table name.
|
705
722
|
fields : Select clause content.
|
706
723
|
- `None`: Is `SELECT *`.
|
707
724
|
- `str`: Join as `SELECT str`.
|
@@ -715,8 +732,8 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
715
732
|
limit : Clause `LIMIT` content.
|
716
733
|
- `int | str`: Join as `LIMIT int/str`.
|
717
734
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
718
|
-
|
719
|
-
- `None`: Use attribute `Database.
|
735
|
+
echo : Whether report SQL execute information.
|
736
|
+
- `None`: Use attribute `Database.echo`.
|
720
737
|
kwdata : Keyword parameters for filling.
|
721
738
|
|
722
739
|
Returns
|
@@ -739,20 +756,20 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
739
756
|
"""
|
740
757
|
|
741
758
|
# Handle parameter.
|
742
|
-
sql = self.handle_select(
|
759
|
+
sql = self.handle_select(path, fields, where, group, having, order, limit)
|
743
760
|
|
744
761
|
# Execute SQL.
|
745
|
-
result = self.execute(sql,
|
762
|
+
result = self.execute(sql, echo=echo, **kwdata)
|
746
763
|
|
747
764
|
return result
|
748
765
|
|
749
766
|
|
750
767
|
def insert(
|
751
768
|
self,
|
752
|
-
|
769
|
+
path: str | tuple[str, str],
|
753
770
|
data: TableData,
|
754
771
|
duplicate: Literal['ignore', 'update'] | Container[str] | None = None,
|
755
|
-
|
772
|
+
echo: bool | None = None,
|
756
773
|
**kwdata: Any
|
757
774
|
) -> Result:
|
758
775
|
"""
|
@@ -760,15 +777,17 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
760
777
|
|
761
778
|
Parameters
|
762
779
|
----------
|
763
|
-
|
780
|
+
path : Path.
|
781
|
+
- `str`: Table name.
|
782
|
+
- `tuple[str, str]`: Database name and table name.
|
764
783
|
data : Insert data.
|
765
784
|
duplicate : Handle method when constraint error.
|
766
785
|
- `None`: Not handled.
|
767
786
|
- `ignore`: Use `UPDATE IGNORE INTO` clause.
|
768
787
|
- `update`: Use `ON DUPLICATE KEY UPDATE` clause and update all fields.
|
769
788
|
- `Container[str]`: Use `ON DUPLICATE KEY UPDATE` clause and update this fields.
|
770
|
-
|
771
|
-
- `None`: Use attribute `Database.
|
789
|
+
echo : Whether report SQL execute information.
|
790
|
+
- `None`: Use attribute `Database.echo`.
|
772
791
|
kwdata : Keyword parameters for filling.
|
773
792
|
- `str and first character is ':'`: Use this syntax.
|
774
793
|
- `Any`: Use this value.
|
@@ -779,7 +798,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
779
798
|
|
780
799
|
Examples
|
781
800
|
--------
|
782
|
-
Parameter `data` and `kwdata`.
|
783
801
|
>>> data = [{'key': 'a'}, {'key': 'b'}]
|
784
802
|
>>> kwdata = {'value1': 1, 'value2': ':(SELECT 2)'}
|
785
803
|
>>> result = Database.execute.insert('table', data, **kwdata)
|
@@ -791,20 +809,20 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
791
809
|
"""
|
792
810
|
|
793
811
|
# Handle parameter.
|
794
|
-
sql, kwdata = self.handle_insert(
|
812
|
+
sql, kwdata = self.handle_insert(path, data, duplicate, **kwdata)
|
795
813
|
|
796
814
|
# Execute SQL.
|
797
|
-
result = self.execute(sql, data,
|
815
|
+
result = self.execute(sql, data, echo, **kwdata)
|
798
816
|
|
799
817
|
return result
|
800
818
|
|
801
819
|
|
802
820
|
def update(
|
803
821
|
self,
|
804
|
-
|
822
|
+
path: str | tuple[str, str],
|
805
823
|
data: TableData,
|
806
824
|
where_fields: str | Iterable[str] | None = None,
|
807
|
-
|
825
|
+
echo: bool | None = None,
|
808
826
|
**kwdata: Any
|
809
827
|
) -> Result:
|
810
828
|
"""
|
@@ -812,7 +830,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
812
830
|
|
813
831
|
Parameters
|
814
832
|
----------
|
815
|
-
|
833
|
+
path : Path.
|
834
|
+
- `str`: Table name.
|
835
|
+
- `tuple[str, str]`: Database name and table name.
|
816
836
|
data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
|
817
837
|
- `Key`: Table field.
|
818
838
|
`literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
|
@@ -825,8 +845,8 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
825
845
|
- `None`: The first key value pair of each item is judged.
|
826
846
|
- `str`: This key value pair of each item is judged.
|
827
847
|
- `Iterable[str]`: Multiple judged, `and`: relationship.
|
828
|
-
|
829
|
-
- `None`: Use attribute `Database.
|
848
|
+
echo : Whether report SQL execute information.
|
849
|
+
- `None`: Use attribute `Database.echo`.
|
830
850
|
kwdata : Keyword parameters for filling.
|
831
851
|
- `str and first character is ':'`: Use this syntax.
|
832
852
|
- `Any`: Use this value.
|
@@ -837,7 +857,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
837
857
|
|
838
858
|
Examples
|
839
859
|
--------
|
840
|
-
Parameter `data` and `kwdata`.
|
841
860
|
>>> data = [{'key': 'a'}, {'key': 'b'}]
|
842
861
|
>>> kwdata = {'value': 1, 'name': ':`key`'}
|
843
862
|
>>> result = Database.execute.update('table', data, **kwdata)
|
@@ -849,21 +868,21 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
849
868
|
"""
|
850
869
|
|
851
870
|
# Handle parameter.
|
852
|
-
sql, data = self.handle_update(
|
871
|
+
sql, data = self.handle_update(path, data, where_fields, **kwdata)
|
853
872
|
|
854
873
|
# Execute SQL.
|
855
|
-
result = self.execute(sql, data,
|
874
|
+
result = self.execute(sql, data, echo)
|
856
875
|
|
857
876
|
return result
|
858
877
|
|
859
878
|
|
860
879
|
def delete(
|
861
880
|
self,
|
862
|
-
|
881
|
+
path: str | tuple[str, str],
|
863
882
|
where: str | None = None,
|
864
883
|
order: str | None = None,
|
865
884
|
limit: int | str | None = None,
|
866
|
-
|
885
|
+
echo: bool | None = None,
|
867
886
|
**kwdata: Any
|
868
887
|
) -> Result:
|
869
888
|
"""
|
@@ -871,12 +890,14 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
871
890
|
|
872
891
|
Parameters
|
873
892
|
----------
|
874
|
-
|
893
|
+
path : Path.
|
894
|
+
- `str`: Table name.
|
895
|
+
- `tuple[str, str]`: Database name and table name.
|
875
896
|
where : Clause `WHERE` content, join as `WHERE str`.
|
876
897
|
order : Clause `ORDER BY` content, join as `ORDER BY str`.
|
877
898
|
limit : Clause `LIMIT` content, join as `LIMIT int/str`.
|
878
|
-
|
879
|
-
- `None`: Use attribute `Database.
|
899
|
+
echo : Whether report SQL execute information.
|
900
|
+
- `None`: Use attribute `Database.echo`.
|
880
901
|
kwdata : Keyword parameters for filling.
|
881
902
|
|
882
903
|
Returns
|
@@ -885,7 +906,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
885
906
|
|
886
907
|
Examples
|
887
908
|
--------
|
888
|
-
Parameter `where` and `kwdata`.
|
889
909
|
>>> where = '`id` IN :ids'
|
890
910
|
>>> ids = (1, 2)
|
891
911
|
>>> result = Database.execute.delete('table', where, ids=ids)
|
@@ -894,21 +914,21 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
894
914
|
"""
|
895
915
|
|
896
916
|
# Handle parameter.
|
897
|
-
sql = self.handle_delete(
|
917
|
+
sql = self.handle_delete(path, where, order, limit)
|
898
918
|
|
899
919
|
# Execute SQL.
|
900
|
-
result = self.execute(sql,
|
920
|
+
result = self.execute(sql, echo=echo, **kwdata)
|
901
921
|
|
902
922
|
return result
|
903
923
|
|
904
924
|
|
905
925
|
def copy(
|
906
926
|
self,
|
907
|
-
|
927
|
+
path: str | tuple[str, str],
|
908
928
|
fields: str | Iterable[str] | None = None,
|
909
929
|
where: str | None = None,
|
910
930
|
limit: int | str | tuple[int, int] | None = None,
|
911
|
-
|
931
|
+
echo: bool | None = None,
|
912
932
|
**kwdata: Any
|
913
933
|
) -> Result:
|
914
934
|
"""
|
@@ -916,7 +936,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
916
936
|
|
917
937
|
Parameters
|
918
938
|
----------
|
919
|
-
|
939
|
+
path : Path.
|
940
|
+
- `str`: Table name.
|
941
|
+
- `tuple[str, str]`: Database name and table name.
|
920
942
|
fields : Select clause content.
|
921
943
|
- `None`: Is `SELECT *`.
|
922
944
|
- `str`: Join as `SELECT str`.
|
@@ -925,6 +947,8 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
925
947
|
limit : Clause `LIMIT` content.
|
926
948
|
- `int | str`: Join as `LIMIT int/str`.
|
927
949
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
950
|
+
echo : Whether report SQL execute information.
|
951
|
+
- `None`: Use attribute `Database.echo`.
|
928
952
|
kwdata : Keyword parameters for filling.
|
929
953
|
|
930
954
|
Returns
|
@@ -933,7 +957,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
933
957
|
|
934
958
|
Examples
|
935
959
|
--------
|
936
|
-
Parameter `where` and `kwdata`.
|
937
960
|
>>> where = '`id` IN :ids'
|
938
961
|
>>> ids = (1, 2, 3)
|
939
962
|
>>> result = Database.execute.copy('table', where, 2, ids=ids, id=None, time=':NOW()')
|
@@ -942,19 +965,19 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
942
965
|
"""
|
943
966
|
|
944
967
|
# Handle parameter.
|
945
|
-
sql = self.handle_copy(
|
968
|
+
sql = self.handle_copy(path, fields, where, limit)
|
946
969
|
|
947
970
|
# Execute SQL.
|
948
|
-
result = self.execute(sql,
|
971
|
+
result = self.execute(sql, echo=echo, **kwdata)
|
949
972
|
|
950
973
|
return result
|
951
974
|
|
952
975
|
|
953
976
|
def count(
|
954
977
|
self,
|
955
|
-
|
978
|
+
path: str | tuple[str, str],
|
956
979
|
where: str | None = None,
|
957
|
-
|
980
|
+
echo: bool | None = None,
|
958
981
|
**kwdata: Any
|
959
982
|
) -> int:
|
960
983
|
"""
|
@@ -962,12 +985,14 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
962
985
|
|
963
986
|
Parameters
|
964
987
|
----------
|
965
|
-
|
988
|
+
path : Path.
|
989
|
+
- `str`: Table name.
|
990
|
+
- `tuple[str, str]`: Database name and table name.
|
966
991
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
967
992
|
- `None`: Match all.
|
968
993
|
- `str`: Match condition.
|
969
|
-
|
970
|
-
- `None`: Use attribute `Database.
|
994
|
+
echo : Whether report SQL execute information.
|
995
|
+
- `None`: Use attribute `Database.echo`.
|
971
996
|
kwdata : Keyword parameters for filling.
|
972
997
|
|
973
998
|
Returns
|
@@ -976,7 +1001,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
976
1001
|
|
977
1002
|
Examples
|
978
1003
|
--------
|
979
|
-
Parameter `where` and `kwdata`.
|
980
1004
|
>>> where = '`id` IN :ids'
|
981
1005
|
>>> ids = (1, 2)
|
982
1006
|
>>> result = Database.execute.count('table', where, ids=ids)
|
@@ -985,7 +1009,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
985
1009
|
"""
|
986
1010
|
|
987
1011
|
# Execute.
|
988
|
-
result = self.select(
|
1012
|
+
result = self.select(path, '1', where=where, echo=echo, **kwdata)
|
989
1013
|
count = len(tuple(result))
|
990
1014
|
|
991
1015
|
return count
|
@@ -993,9 +1017,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
993
1017
|
|
994
1018
|
def exist(
|
995
1019
|
self,
|
996
|
-
|
1020
|
+
path: str | tuple[str, str],
|
997
1021
|
where: str | None = None,
|
998
|
-
|
1022
|
+
echo: bool | None = None,
|
999
1023
|
**kwdata: Any
|
1000
1024
|
) -> bool:
|
1001
1025
|
"""
|
@@ -1003,12 +1027,14 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1003
1027
|
|
1004
1028
|
Parameters
|
1005
1029
|
----------
|
1006
|
-
|
1030
|
+
path : Path.
|
1031
|
+
- `str`: Table name.
|
1032
|
+
- `tuple[str, str]`: Database name and table name.
|
1007
1033
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
1008
1034
|
- `None`: Match all.
|
1009
1035
|
- `str`: Match condition.
|
1010
|
-
|
1011
|
-
- `None`: Use attribute `Database.
|
1036
|
+
echo : Whether report SQL execute information.
|
1037
|
+
- `None`: Use attribute `Database.echo`.
|
1012
1038
|
kwdata : Keyword parameters for filling.
|
1013
1039
|
|
1014
1040
|
Returns
|
@@ -1017,7 +1043,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1017
1043
|
|
1018
1044
|
Examples
|
1019
1045
|
--------
|
1020
|
-
Parameter `where` and `kwdata`.
|
1021
1046
|
>>> data = [{'id': 1}]
|
1022
1047
|
>>> Database.execute.insert('table', data)
|
1023
1048
|
>>> where = '`id` = :id_'
|
@@ -1028,7 +1053,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1028
1053
|
"""
|
1029
1054
|
|
1030
1055
|
# Execute.
|
1031
|
-
result = self.count(
|
1056
|
+
result = self.count(path, where, echo, **kwdata)
|
1032
1057
|
|
1033
1058
|
# Judge.
|
1034
1059
|
judge = result != 0
|
@@ -1040,7 +1065,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1040
1065
|
self,
|
1041
1066
|
sql: str | TextClause,
|
1042
1067
|
data: TableData,
|
1043
|
-
|
1068
|
+
echo: bool | None = None,
|
1044
1069
|
**kwdata: Any
|
1045
1070
|
) -> Generator[Result, Any, None]:
|
1046
1071
|
"""
|
@@ -1050,8 +1075,8 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1050
1075
|
----------
|
1051
1076
|
sql : SQL in method `sqlalchemy.text` format, or `TextClause` object.
|
1052
1077
|
data : Data set for filling.
|
1053
|
-
|
1054
|
-
- `None`: Use attribute `Database.
|
1078
|
+
echo : Whether report SQL execute information.
|
1079
|
+
- `None`: Use attribute `Database.echo`.
|
1055
1080
|
- `bool`: Use this value.
|
1056
1081
|
kwdata : Keyword parameters for filling.
|
1057
1082
|
|
@@ -1064,7 +1089,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1064
1089
|
func_generator = FunctionGenerator(
|
1065
1090
|
self.execute,
|
1066
1091
|
sql=sql,
|
1067
|
-
|
1092
|
+
echo=echo,
|
1068
1093
|
**kwdata
|
1069
1094
|
)
|
1070
1095
|
|
@@ -1079,24 +1104,24 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1079
1104
|
|
1080
1105
|
|
1081
1106
|
@overload
|
1082
|
-
def sleep(self,
|
1107
|
+
def sleep(self, echo: bool | None = None) -> int: ...
|
1083
1108
|
|
1084
1109
|
@overload
|
1085
|
-
def sleep(self, second: int,
|
1110
|
+
def sleep(self, second: int, echo: bool | None = None) -> int: ...
|
1086
1111
|
|
1087
1112
|
@overload
|
1088
|
-
def sleep(self, low: int = 0, high: int = 10,
|
1113
|
+
def sleep(self, low: int = 0, high: int = 10, echo: bool | None = None) -> int: ...
|
1089
1114
|
|
1090
1115
|
@overload
|
1091
|
-
def sleep(self, *thresholds: float,
|
1116
|
+
def sleep(self, *thresholds: float, echo: bool | None = None) -> float: ...
|
1092
1117
|
|
1093
1118
|
@overload
|
1094
|
-
def sleep(self, *thresholds: float, precision: Literal[0],
|
1119
|
+
def sleep(self, *thresholds: float, precision: Literal[0], echo: bool | None = None) -> int: ...
|
1095
1120
|
|
1096
1121
|
@overload
|
1097
|
-
def sleep(self, *thresholds: float, precision: int,
|
1122
|
+
def sleep(self, *thresholds: float, precision: int, echo: bool | None = None) -> float: ...
|
1098
1123
|
|
1099
|
-
def sleep(self, *thresholds: float, precision: int | None = None,
|
1124
|
+
def sleep(self, *thresholds: float, precision: int | None = None, echo: bool | None = None) -> float:
|
1100
1125
|
"""
|
1101
1126
|
Let the database wait random seconds.
|
1102
1127
|
|
@@ -1109,8 +1134,8 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1109
1134
|
precision : Precision of random range, that is maximum decimal digits of return value.
|
1110
1135
|
- `None`: Set to Maximum decimal digits of element of parameter `thresholds`.
|
1111
1136
|
- `int`: Set to this value.
|
1112
|
-
|
1113
|
-
- `None`: Use attribute `Database.
|
1137
|
+
echo : Whether report SQL execute information.
|
1138
|
+
- `None`: Use attribute `Database.echo`.
|
1114
1139
|
- `bool`: Use this value.
|
1115
1140
|
|
1116
1141
|
Returns
|
@@ -1128,7 +1153,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
|
|
1128
1153
|
|
1129
1154
|
# Sleep.
|
1130
1155
|
sql = f'SELECT SLEEP({second})'
|
1131
|
-
self.execute(sql,
|
1156
|
+
self.execute(sql, echo=echo)
|
1132
1157
|
|
1133
1158
|
return second
|
1134
1159
|
|
@@ -1143,7 +1168,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1143
1168
|
self,
|
1144
1169
|
sql: str | TextClause,
|
1145
1170
|
data: TableData | None = None,
|
1146
|
-
|
1171
|
+
echo: bool | None = None,
|
1147
1172
|
**kwdata: Any
|
1148
1173
|
) -> Result:
|
1149
1174
|
"""
|
@@ -1153,9 +1178,8 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1153
1178
|
----------
|
1154
1179
|
sql : SQL in method `sqlalchemy.text` format, or `TextClause` object.
|
1155
1180
|
data : Data set for filling.
|
1156
|
-
|
1157
|
-
- `None`: Use attribute `
|
1158
|
-
- `bool`: Use this value.
|
1181
|
+
echo : Whether report SQL execute information.
|
1182
|
+
- `None`: Use attribute `Database.echo`.
|
1159
1183
|
kwdata : Keyword parameters for filling.
|
1160
1184
|
|
1161
1185
|
Returns
|
@@ -1164,7 +1188,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1164
1188
|
"""
|
1165
1189
|
|
1166
1190
|
# Handle parameter.
|
1167
|
-
sql, data,
|
1191
|
+
sql, data, echo = self.handle_execute(sql, data, echo, **kwdata)
|
1168
1192
|
|
1169
1193
|
# Transaction.
|
1170
1194
|
await self.conn.get_begin()
|
@@ -1172,7 +1196,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1172
1196
|
# Execute.
|
1173
1197
|
|
1174
1198
|
## Report.
|
1175
|
-
if
|
1199
|
+
if echo:
|
1176
1200
|
tm = TimeMark()
|
1177
1201
|
tm()
|
1178
1202
|
result = await self.conn.connection.execute(sql, data)
|
@@ -1201,9 +1225,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1201
1225
|
]
|
1202
1226
|
|
1203
1227
|
if data == []:
|
1204
|
-
|
1228
|
+
recho(report_info, *sqls, title='SQL')
|
1205
1229
|
else:
|
1206
|
-
|
1230
|
+
recho(report_info, *sqls, data, title='SQL')
|
1207
1231
|
|
1208
1232
|
## Not report.
|
1209
1233
|
else:
|
@@ -1223,14 +1247,14 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1223
1247
|
|
1224
1248
|
async def select(
|
1225
1249
|
self,
|
1226
|
-
|
1250
|
+
path: str | tuple[str, str],
|
1227
1251
|
fields: str | Iterable[str] | None = None,
|
1228
1252
|
where: str | None = None,
|
1229
1253
|
group: str | None = None,
|
1230
1254
|
having: str | None = None,
|
1231
1255
|
order: str | None = None,
|
1232
1256
|
limit: int | str | tuple[int, int] | None = None,
|
1233
|
-
|
1257
|
+
echo: bool | None = None,
|
1234
1258
|
**kwdata: Any
|
1235
1259
|
) -> Result:
|
1236
1260
|
"""
|
@@ -1238,7 +1262,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1238
1262
|
|
1239
1263
|
Parameters
|
1240
1264
|
----------
|
1241
|
-
|
1265
|
+
path : Path.
|
1266
|
+
- `str`: Table name.
|
1267
|
+
- `tuple[str, str]`: Database name and table name.
|
1242
1268
|
fields : Select clause content.
|
1243
1269
|
- `None`: Is `SELECT *`.
|
1244
1270
|
- `str`: Join as `SELECT str`.
|
@@ -1252,8 +1278,8 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1252
1278
|
limit : Clause `LIMIT` content.
|
1253
1279
|
- `int | str`: Join as `LIMIT int/str`.
|
1254
1280
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
1255
|
-
|
1256
|
-
- `None`: Use attribute `Database.
|
1281
|
+
echo : Whether report SQL execute information.
|
1282
|
+
- `None`: Use attribute `Database.echo`.
|
1257
1283
|
kwdata : Keyword parameters for filling.
|
1258
1284
|
|
1259
1285
|
Returns
|
@@ -1264,32 +1290,32 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1264
1290
|
--------
|
1265
1291
|
Parameter `fields`.
|
1266
1292
|
>>> fields = ['id', ':`id` + 1 AS `id_`']
|
1267
|
-
>>> result = Database.execute.select('table', fields)
|
1293
|
+
>>> result = await Database.execute.select('table', fields)
|
1268
1294
|
>>> print(result.to_table())
|
1269
1295
|
[{'id': 1, 'id_': 2}, ...]
|
1270
1296
|
|
1271
1297
|
Parameter `kwdata`.
|
1272
1298
|
>>> fields = '`id`, `id` + :value AS `id_`'
|
1273
|
-
>>> result = Database.execute.select('table', fields, value=1)
|
1299
|
+
>>> result = await Database.execute.select('table', fields, value=1)
|
1274
1300
|
>>> print(result.to_table())
|
1275
1301
|
[{'id': 1, 'id_': 2}, ...]
|
1276
1302
|
"""
|
1277
1303
|
|
1278
1304
|
# Handle parameter.
|
1279
|
-
sql = self.handle_select(
|
1305
|
+
sql = self.handle_select(path, fields, where, group, having, order, limit)
|
1280
1306
|
|
1281
1307
|
# Execute SQL.
|
1282
|
-
result = await self.execute(sql,
|
1308
|
+
result = await self.execute(sql, echo=echo, **kwdata)
|
1283
1309
|
|
1284
1310
|
return result
|
1285
1311
|
|
1286
1312
|
|
1287
1313
|
async def insert(
|
1288
1314
|
self,
|
1289
|
-
|
1315
|
+
path: str | tuple[str, str],
|
1290
1316
|
data: TableData,
|
1291
1317
|
duplicate: Literal['ignore', 'update'] | Container[str] | None = None,
|
1292
|
-
|
1318
|
+
echo: bool | None = None,
|
1293
1319
|
**kwdata: Any
|
1294
1320
|
) -> Result:
|
1295
1321
|
"""
|
@@ -1297,15 +1323,17 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1297
1323
|
|
1298
1324
|
Parameters
|
1299
1325
|
----------
|
1300
|
-
|
1326
|
+
path : Path.
|
1327
|
+
- `str`: Table name.
|
1328
|
+
- `tuple[str, str]`: Database name and table name.
|
1301
1329
|
data : Insert data.
|
1302
1330
|
duplicate : Handle method when constraint error.
|
1303
1331
|
- `None`: Not handled.
|
1304
1332
|
- `ignore`: Use `UPDATE IGNORE INTO` clause.
|
1305
1333
|
- `update`: Use `ON DUPLICATE KEY UPDATE` clause and update all fields.
|
1306
1334
|
- `Container[str]`: Use `ON DUPLICATE KEY UPDATE` clause and update this fields.
|
1307
|
-
|
1308
|
-
- `None`: Use attribute `Database.
|
1335
|
+
echo : Whether report SQL execute information.
|
1336
|
+
- `None`: Use attribute `Database.echo`.
|
1309
1337
|
kwdata : Keyword parameters for filling.
|
1310
1338
|
- `str and first character is ':'`: Use this syntax.
|
1311
1339
|
- `Any`: Use this value.
|
@@ -1316,32 +1344,31 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1316
1344
|
|
1317
1345
|
Examples
|
1318
1346
|
--------
|
1319
|
-
Parameter `data` and `kwdata`.
|
1320
1347
|
>>> data = [{'key': 'a'}, {'key': 'b'}]
|
1321
1348
|
>>> kwdata = {'value1': 1, 'value2': ':(SELECT 2)'}
|
1322
|
-
>>> result = Database.execute.insert('table', data, **kwdata)
|
1349
|
+
>>> result = await Database.execute.insert('table', data, **kwdata)
|
1323
1350
|
>>> print(result.rowcount)
|
1324
1351
|
2
|
1325
|
-
>>> result = Database.execute.select('table')
|
1352
|
+
>>> result = await Database.execute.select('table')
|
1326
1353
|
>>> print(result.to_table())
|
1327
1354
|
[{'key': 'a', 'value1': 1, 'value2': 2}, {'key': 'b', 'value1': 1, 'value2': 2}]
|
1328
1355
|
"""
|
1329
1356
|
|
1330
1357
|
# Handle parameter.
|
1331
|
-
sql, kwdata = self.handle_insert(
|
1358
|
+
sql, kwdata = self.handle_insert(path, data, duplicate, **kwdata)
|
1332
1359
|
|
1333
1360
|
# Execute SQL.
|
1334
|
-
result = await self.execute(sql, data,
|
1361
|
+
result = await self.execute(sql, data, echo, **kwdata)
|
1335
1362
|
|
1336
1363
|
return result
|
1337
1364
|
|
1338
1365
|
|
1339
1366
|
async def update(
|
1340
1367
|
self,
|
1341
|
-
|
1368
|
+
path: str | tuple[str, str],
|
1342
1369
|
data: TableData,
|
1343
1370
|
where_fields: str | Iterable[str] | None = None,
|
1344
|
-
|
1371
|
+
echo: bool | None = None,
|
1345
1372
|
**kwdata: Any
|
1346
1373
|
) -> Result:
|
1347
1374
|
"""
|
@@ -1349,7 +1376,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1349
1376
|
|
1350
1377
|
Parameters
|
1351
1378
|
----------
|
1352
|
-
|
1379
|
+
path : Path.
|
1380
|
+
- `str`: Table name.
|
1381
|
+
- `tuple[str, str]`: Database name and table name.
|
1353
1382
|
data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
|
1354
1383
|
- `Key`: Table field.
|
1355
1384
|
`literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
|
@@ -1362,8 +1391,8 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1362
1391
|
- `None`: The first key value pair of each item is judged.
|
1363
1392
|
- `str`: This key value pair of each item is judged.
|
1364
1393
|
- `Iterable[str]`: Multiple judged, `and`: relationship.
|
1365
|
-
|
1366
|
-
- `None`: Use attribute `Database.
|
1394
|
+
echo : Whether report SQL execute information.
|
1395
|
+
- `None`: Use attribute `Database.echo`.
|
1367
1396
|
kwdata : Keyword parameters for filling.
|
1368
1397
|
- `str and first character is ':'`: Use this syntax.
|
1369
1398
|
- `Any`: Use this value.
|
@@ -1374,33 +1403,32 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1374
1403
|
|
1375
1404
|
Examples
|
1376
1405
|
--------
|
1377
|
-
Parameter `data` and `kwdata`.
|
1378
1406
|
>>> data = [{'key': 'a'}, {'key': 'b'}]
|
1379
1407
|
>>> kwdata = {'value': 1, 'name': ':`key`'}
|
1380
|
-
>>> result = Database.execute.update('table', data, **kwdata)
|
1408
|
+
>>> result = await Database.execute.update('table', data, **kwdata)
|
1381
1409
|
>>> print(result.rowcount)
|
1382
1410
|
2
|
1383
|
-
>>> result = Database.execute.select('table')
|
1411
|
+
>>> result = await Database.execute.select('table')
|
1384
1412
|
>>> print(result.to_table())
|
1385
1413
|
[{'key': 'a', 'value': 1, 'name': 'a'}, {'key': 'b', 'value': 1, 'name': 'b'}]
|
1386
1414
|
"""
|
1387
1415
|
|
1388
1416
|
# Handle parameter.
|
1389
|
-
sql, data = self.handle_update(
|
1417
|
+
sql, data = self.handle_update(path, data, where_fields, **kwdata)
|
1390
1418
|
|
1391
1419
|
# Execute SQL.
|
1392
|
-
result = await self.execute(sql, data,
|
1420
|
+
result = await self.execute(sql, data, echo)
|
1393
1421
|
|
1394
1422
|
return result
|
1395
1423
|
|
1396
1424
|
|
1397
1425
|
async def delete(
|
1398
1426
|
self,
|
1399
|
-
|
1427
|
+
path: str | tuple[str, str],
|
1400
1428
|
where: str | None = None,
|
1401
1429
|
order: str | None = None,
|
1402
1430
|
limit: int | str | None = None,
|
1403
|
-
|
1431
|
+
echo: bool | None = None,
|
1404
1432
|
**kwdata: Any
|
1405
1433
|
) -> Result:
|
1406
1434
|
"""
|
@@ -1408,12 +1436,14 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1408
1436
|
|
1409
1437
|
Parameters
|
1410
1438
|
----------
|
1411
|
-
|
1439
|
+
path : Path.
|
1440
|
+
- `str`: Table name.
|
1441
|
+
- `tuple[str, str]`: Database name and table name.
|
1412
1442
|
where : Clause `WHERE` content, join as `WHERE str`.
|
1413
1443
|
order : Clause `ORDER BY` content, join as `ORDER BY str`.
|
1414
1444
|
limit : Clause `LIMIT` content, join as `LIMIT int/str`.
|
1415
|
-
|
1416
|
-
- `None`: Use attribute `Database.
|
1445
|
+
echo : Whether report SQL execute information.
|
1446
|
+
- `None`: Use attribute `Database.echo`.
|
1417
1447
|
kwdata : Keyword parameters for filling.
|
1418
1448
|
|
1419
1449
|
Returns
|
@@ -1422,30 +1452,29 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1422
1452
|
|
1423
1453
|
Examples
|
1424
1454
|
--------
|
1425
|
-
Parameter `where` and `kwdata`.
|
1426
1455
|
>>> where = '`id` IN :ids'
|
1427
1456
|
>>> ids = (1, 2)
|
1428
|
-
>>> result = Database.execute.delete('table', where, ids=ids)
|
1457
|
+
>>> result = await Database.execute.delete('table', where, ids=ids)
|
1429
1458
|
>>> print(result.rowcount)
|
1430
1459
|
2
|
1431
1460
|
"""
|
1432
1461
|
|
1433
1462
|
# Handle parameter.
|
1434
|
-
sql = self.handle_delete(
|
1463
|
+
sql = self.handle_delete(path, where, order, limit)
|
1435
1464
|
|
1436
1465
|
# Execute SQL.
|
1437
|
-
result = await self.execute(sql,
|
1466
|
+
result = await self.execute(sql, echo=echo, **kwdata)
|
1438
1467
|
|
1439
1468
|
return result
|
1440
1469
|
|
1441
1470
|
|
1442
1471
|
async def copy(
|
1443
1472
|
self,
|
1444
|
-
|
1473
|
+
path: str | tuple[str, str],
|
1445
1474
|
fields: str | Iterable[str] | None = None,
|
1446
1475
|
where: str | None = None,
|
1447
1476
|
limit: int | str | tuple[int, int] | None = None,
|
1448
|
-
|
1477
|
+
echo: bool | None = None,
|
1449
1478
|
**kwdata: Any
|
1450
1479
|
) -> Result:
|
1451
1480
|
"""
|
@@ -1453,7 +1482,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1453
1482
|
|
1454
1483
|
Parameters
|
1455
1484
|
----------
|
1456
|
-
|
1485
|
+
path : Path.
|
1486
|
+
- `str`: Table name.
|
1487
|
+
- `tuple[str, str]`: Database name and table name.
|
1457
1488
|
fields : Select clause content.
|
1458
1489
|
- `None`: Is `SELECT *`.
|
1459
1490
|
- `str`: Join as `SELECT str`.
|
@@ -1462,6 +1493,8 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1462
1493
|
limit : Clause `LIMIT` content.
|
1463
1494
|
- `int | str`: Join as `LIMIT int/str`.
|
1464
1495
|
- `tuple[int, int]`: Join as `LIMIT int, int`.
|
1496
|
+
echo : Whether report SQL execute information.
|
1497
|
+
- `None`: Use attribute `Database.echo`.
|
1465
1498
|
kwdata : Keyword parameters for filling.
|
1466
1499
|
|
1467
1500
|
Returns
|
@@ -1470,28 +1503,27 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1470
1503
|
|
1471
1504
|
Examples
|
1472
1505
|
--------
|
1473
|
-
Parameter `where` and `kwdata`.
|
1474
1506
|
>>> where = '`id` IN :ids'
|
1475
1507
|
>>> ids = (1, 2, 3)
|
1476
|
-
>>> result = Database.execute.copy('table', where, 2, ids=ids
|
1508
|
+
>>> result = await Database.execute.copy('table', ['name', 'value'], where, 2, ids=ids)
|
1477
1509
|
>>> print(result.rowcount)
|
1478
1510
|
2
|
1479
1511
|
"""
|
1480
1512
|
|
1481
1513
|
# Handle parameter.
|
1482
|
-
sql = self.handle_copy(
|
1514
|
+
sql = self.handle_copy(path, fields, where, limit)
|
1483
1515
|
|
1484
1516
|
# Execute SQL.
|
1485
|
-
result = await self.execute(sql,
|
1517
|
+
result = await self.execute(sql, echo=echo, **kwdata)
|
1486
1518
|
|
1487
1519
|
return result
|
1488
1520
|
|
1489
1521
|
|
1490
1522
|
async def count(
|
1491
1523
|
self,
|
1492
|
-
|
1524
|
+
path: str | tuple[str, str],
|
1493
1525
|
where: str | None = None,
|
1494
|
-
|
1526
|
+
echo: bool | None = None,
|
1495
1527
|
**kwdata: Any
|
1496
1528
|
) -> int:
|
1497
1529
|
"""
|
@@ -1499,12 +1531,14 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1499
1531
|
|
1500
1532
|
Parameters
|
1501
1533
|
----------
|
1502
|
-
|
1534
|
+
path : Path.
|
1535
|
+
- `str`: Table name.
|
1536
|
+
- `tuple[str, str]`: Database name and table name.
|
1503
1537
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
1504
1538
|
- `None`: Match all.
|
1505
1539
|
- `str`: Match condition.
|
1506
|
-
|
1507
|
-
- `None`: Use attribute `Database.
|
1540
|
+
echo : Whether report SQL execute information.
|
1541
|
+
- `None`: Use attribute `Database.echo`.
|
1508
1542
|
kwdata : Keyword parameters for filling.
|
1509
1543
|
|
1510
1544
|
Returns
|
@@ -1513,16 +1547,15 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1513
1547
|
|
1514
1548
|
Examples
|
1515
1549
|
--------
|
1516
|
-
Parameter `where` and `kwdata`.
|
1517
1550
|
>>> where = '`id` IN :ids'
|
1518
1551
|
>>> ids = (1, 2)
|
1519
|
-
>>> result = Database.execute.count('table', where, ids=ids)
|
1552
|
+
>>> result = await Database.execute.count('table', where, ids=ids)
|
1520
1553
|
>>> print(result)
|
1521
1554
|
2
|
1522
1555
|
"""
|
1523
1556
|
|
1524
1557
|
# Execute.
|
1525
|
-
result = await self.select(
|
1558
|
+
result = await self.select(path, '1', where=where, echo=echo, **kwdata)
|
1526
1559
|
count = len(tuple(result))
|
1527
1560
|
|
1528
1561
|
return count
|
@@ -1530,9 +1563,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1530
1563
|
|
1531
1564
|
async def exist(
|
1532
1565
|
self,
|
1533
|
-
|
1566
|
+
path: str | tuple[str, str],
|
1534
1567
|
where: str | None = None,
|
1535
|
-
|
1568
|
+
echo: bool | None = None,
|
1536
1569
|
**kwdata: Any
|
1537
1570
|
) -> bool:
|
1538
1571
|
"""
|
@@ -1540,12 +1573,14 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1540
1573
|
|
1541
1574
|
Parameters
|
1542
1575
|
----------
|
1543
|
-
|
1576
|
+
path : Path.
|
1577
|
+
- `str`: Table name.
|
1578
|
+
- `tuple[str, str]`: Database name and table name.
|
1544
1579
|
where : Match condition, `WHERE` clause content, join as `WHERE str`.
|
1545
1580
|
- `None`: Match all.
|
1546
1581
|
- `str`: Match condition.
|
1547
|
-
|
1548
|
-
- `None`: Use attribute `Database.
|
1582
|
+
echo : Whether report SQL execute information.
|
1583
|
+
- `None`: Use attribute `Database.echo`.
|
1549
1584
|
kwdata : Keyword parameters for filling.
|
1550
1585
|
|
1551
1586
|
Returns
|
@@ -1554,18 +1589,17 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1554
1589
|
|
1555
1590
|
Examples
|
1556
1591
|
--------
|
1557
|
-
Parameter `where` and `kwdata`.
|
1558
1592
|
>>> data = [{'id': 1}]
|
1559
1593
|
>>> Database.execute.insert('table', data)
|
1560
1594
|
>>> where = '`id` = :id_'
|
1561
1595
|
>>> id_ = 1
|
1562
|
-
>>> result = Database.execute.exist('table', where, id_=id_)
|
1596
|
+
>>> result = await Database.execute.exist('table', where, id_=id_)
|
1563
1597
|
>>> print(result)
|
1564
1598
|
True
|
1565
1599
|
"""
|
1566
1600
|
|
1567
1601
|
# Execute.
|
1568
|
-
result = await self.count(
|
1602
|
+
result = await self.count(path, where, echo, **kwdata)
|
1569
1603
|
|
1570
1604
|
# Judge.
|
1571
1605
|
judge = result != 0
|
@@ -1577,7 +1611,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1577
1611
|
self,
|
1578
1612
|
sql: str | TextClause,
|
1579
1613
|
data: TableData,
|
1580
|
-
|
1614
|
+
echo: bool | None = None,
|
1581
1615
|
**kwdata: Any
|
1582
1616
|
) -> AsyncGenerator[Result, Any]:
|
1583
1617
|
"""
|
@@ -1587,9 +1621,8 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1587
1621
|
----------
|
1588
1622
|
sql : SQL in method `sqlalchemy.text` format, or `TextClause` object.
|
1589
1623
|
data : Data set for filling.
|
1590
|
-
|
1591
|
-
- `None`: Use attribute `
|
1592
|
-
- `bool`: Use this value.
|
1624
|
+
echo : Whether report SQL execute information.
|
1625
|
+
- `None`: Use attribute `Database.echo`.
|
1593
1626
|
kwdata : Keyword parameters for filling.
|
1594
1627
|
|
1595
1628
|
Returns
|
@@ -1601,7 +1634,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1601
1634
|
func_generator = FunctionGenerator(
|
1602
1635
|
self.execute,
|
1603
1636
|
sql=sql,
|
1604
|
-
|
1637
|
+
echo=echo,
|
1605
1638
|
**kwdata
|
1606
1639
|
)
|
1607
1640
|
|
@@ -1616,24 +1649,24 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1616
1649
|
|
1617
1650
|
|
1618
1651
|
@overload
|
1619
|
-
async def sleep(self,
|
1652
|
+
async def sleep(self, echo: bool | None = None) -> int: ...
|
1620
1653
|
|
1621
1654
|
@overload
|
1622
|
-
async def sleep(self, second: int,
|
1655
|
+
async def sleep(self, second: int, echo: bool | None = None) -> int: ...
|
1623
1656
|
|
1624
1657
|
@overload
|
1625
|
-
async def sleep(self, low: int = 0, high: int = 10,
|
1658
|
+
async def sleep(self, low: int = 0, high: int = 10, echo: bool | None = None) -> int: ...
|
1626
1659
|
|
1627
1660
|
@overload
|
1628
|
-
async def sleep(self, *thresholds: float,
|
1661
|
+
async def sleep(self, *thresholds: float, echo: bool | None = None) -> float: ...
|
1629
1662
|
|
1630
1663
|
@overload
|
1631
|
-
async def sleep(self, *thresholds: float, precision: Literal[0],
|
1664
|
+
async def sleep(self, *thresholds: float, precision: Literal[0], echo: bool | None = None) -> int: ...
|
1632
1665
|
|
1633
1666
|
@overload
|
1634
|
-
async def sleep(self, *thresholds: float, precision: int,
|
1667
|
+
async def sleep(self, *thresholds: float, precision: int, echo: bool | None = None) -> float: ...
|
1635
1668
|
|
1636
|
-
async def sleep(self, *thresholds: float, precision: int | None = None,
|
1669
|
+
async def sleep(self, *thresholds: float, precision: int | None = None, echo: bool | None = None) -> float:
|
1637
1670
|
"""
|
1638
1671
|
Asynchronous let the database wait random seconds.
|
1639
1672
|
|
@@ -1646,9 +1679,8 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1646
1679
|
precision : Precision of random range, that is maximum decimal digits of return value.
|
1647
1680
|
- `None`: Set to Maximum decimal digits of element of parameter `thresholds`.
|
1648
1681
|
- `int`: Set to this value.
|
1649
|
-
|
1650
|
-
- `None`: Use attribute `
|
1651
|
-
- `bool`: Use this value.
|
1682
|
+
echo : Whether report SQL execute information.
|
1683
|
+
- `None`: Use attribute `Database.echo`.
|
1652
1684
|
|
1653
1685
|
Returns
|
1654
1686
|
-------
|
@@ -1665,6 +1697,6 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
|
|
1665
1697
|
|
1666
1698
|
# Sleep.
|
1667
1699
|
sql = f'SELECT SLEEP({second})'
|
1668
|
-
await self.execute(sql,
|
1700
|
+
await self.execute(sql, echo=echo)
|
1669
1701
|
|
1670
1702
|
return second
|