reydb 1.1.60__py3-none-any.whl → 1.2.0__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/rexec.py CHANGED
@@ -24,11 +24,12 @@ 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, extract_path
27
+ from .rbase import DatabaseBase, handle_sql, handle_data
28
28
 
29
29
 
30
30
  __all__ = (
31
31
  'Result',
32
+ 'DatabaseExecuteSuper',
32
33
  'DatabaseExecute',
33
34
  'DatabaseExecuteAsync'
34
35
  )
@@ -70,7 +71,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
70
71
  **kwdata: Any
71
72
  ) -> tuple[TextClause, list[dict], bool]:
72
73
  """
73
- Handle parameters before execute SQL.
74
+ Handle method of execute SQL.
74
75
 
75
76
  Parameters
76
77
  ----------
@@ -106,7 +107,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
106
107
 
107
108
  def handle_select(
108
109
  self,
109
- table: str,
110
+ path: str | tuple[str, str],
110
111
  fields: str | Iterable[str] | None = None,
111
112
  where: str | None = None,
112
113
  group: str | None = None,
@@ -115,11 +116,13 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
115
116
  limit: int | str | tuple[int, int] | None = None
116
117
  ) -> str:
117
118
  """
118
- Handle parameters before execute select SQL.
119
+ Handle method of execute select SQL.
119
120
 
120
121
  Parameters
121
122
  ----------
122
- table : Table name, can include database name.
123
+ path : Path.
124
+ - `str`: Table name.
125
+ - `tuple[str, str]`: Database name and table name.
123
126
  fields : Select clause content.
124
127
  - `None`: Is `SELECT *`.
125
128
  - `str`: Join as `SELECT str`.
@@ -140,9 +143,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
140
143
  """
141
144
 
142
145
  # Handle parameter.
143
- database = self.conn.db.database
144
- if '.' in table:
145
- database, table, _ = extract_path(table)
146
+ if type(path) == str:
147
+ database, table = self.conn.db.database, path
148
+ else:
149
+ database, table = path
146
150
 
147
151
  # Generate SQL.
148
152
  sql_list = []
@@ -208,17 +212,19 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
208
212
 
209
213
  def handle_insert(
210
214
  self,
211
- table: str,
215
+ path: str | tuple[str, str],
212
216
  data: TableData,
213
217
  duplicate: Literal['ignore', 'update'] | Container[str] | None = None,
214
218
  **kwdata: Any
215
219
  ) -> Result:
216
220
  """
217
- Handle parameters before execute insert SQL.
221
+ Handle method of execute insert SQL.
218
222
 
219
223
  Parameters
220
224
  ----------
221
- table : Table name, can include database name.
225
+ path : Path.
226
+ - `str`: Table name.
227
+ - `tuple[str, str]`: Database name and table name.
222
228
  data : Insert data.
223
229
  duplicate : Handle method when constraint error.
224
230
  - `None`: Not handled.
@@ -235,9 +241,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
235
241
  """
236
242
 
237
243
  # Handle parameter.
238
- database = self.conn.db.database
239
- if '.' in table:
240
- database, table, _ = extract_path(table)
244
+ if type(path) == str:
245
+ database, table = self.conn.db.database, path
246
+ else:
247
+ database, table = path
241
248
 
242
249
  ## Data.
243
250
  data_table = Table(data)
@@ -342,7 +349,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
342
349
 
343
350
  def handle_update(
344
351
  self,
345
- table: str,
352
+ path: str | tuple[str, str],
346
353
  data: TableData,
347
354
  where_fields: str | Iterable[str] | None = None,
348
355
  **kwdata: Any
@@ -352,7 +359,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
352
359
 
353
360
  Parameters
354
361
  ----------
355
- table : Table name, can include database name.
362
+ path : Path.
363
+ - `str`: Table name.
364
+ - `tuple[str, str]`: Database name and table name.
356
365
  data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
357
366
  - `Key`: Table field.
358
367
  `literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
@@ -375,9 +384,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
375
384
  """
376
385
 
377
386
  # Handle parameter.
378
- database = self.conn.db.database
379
- if '.' in table:
380
- database, table, _ = extract_path(table)
387
+ if type(path) == str:
388
+ database, table = self.conn.db.database, path
389
+ else:
390
+ database, table = path
381
391
 
382
392
  ## Data.
383
393
  data_table = Table(data)
@@ -485,7 +495,7 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
485
495
 
486
496
  def handle_delete(
487
497
  self,
488
- table: str,
498
+ path: str | tuple[str, str],
489
499
  where: str | None = None,
490
500
  order: str | None = None,
491
501
  limit: int | str | None = None
@@ -495,7 +505,9 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
495
505
 
496
506
  Parameters
497
507
  ----------
498
- table : Table name, can include database name.
508
+ path : Path.
509
+ - `str`: Table name.
510
+ - `tuple[str, str]`: Database name and table name.
499
511
  where : Clause `WHERE` content, join as `WHERE str`.
500
512
  order : Clause `ORDER BY` content, join as `ORDER BY str`.
501
513
  limit : Clause `LIMIT` content, join as `LIMIT int/str`.
@@ -506,9 +518,10 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
506
518
  """
507
519
 
508
520
  # Handle parameter.
509
- database = self.conn.db.database
510
- if '.' in table:
511
- database, table, _ = extract_path(table)
521
+ if type(path) == str:
522
+ database, table = self.conn.db.database, path
523
+ else:
524
+ database, table = path
512
525
 
513
526
  # Generate SQL.
514
527
  sqls = []
@@ -540,26 +553,27 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
540
553
 
541
554
  def handle_copy(
542
555
  self,
543
- table: str,
556
+ path: str | tuple[str, str],
557
+ fields: str | Iterable[str] | None = None,
544
558
  where: str | None = None,
545
- limit: int | str | tuple[int, int] | None = None,
546
- **kwdata: Any
559
+ limit: int | str | tuple[int, int] | None = None
547
560
  ) -> Result:
548
561
  """
549
562
  Execute inesrt SQL of copy records.
550
563
 
551
564
  Parameters
552
565
  ----------
553
- table : Table name, can include database name.
566
+ path : Path.
567
+ - `str`: Table name.
568
+ - `tuple[str, str]`: Database name and table name.
569
+ fields : Select clause content.
570
+ - `None`: Is `SELECT *`.
571
+ - `str`: Join as `SELECT str`.
572
+ - `Iterable[str]`: Join as `SELECT str`.
554
573
  where : Clause `WHERE` content, join as `WHERE str`.
555
574
  limit : Clause `LIMIT` content.
556
575
  - `int | str`: Join as `LIMIT int/str`.
557
576
  - `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
577
 
564
578
  Returns
565
579
  -------
@@ -567,75 +581,27 @@ class DatabaseExecuteSuper(DatabaseBase, Generic[DatabaseConnectionT]):
567
581
  """
568
582
 
569
583
  # Handle parameter.
570
- database = self.conn.db.database
571
- if '.' in table:
572
- database, table, _ = extract_path(table)
573
- table_info: list[dict] = self.conn.db.info(database)(table)()
574
- field_key = 'COLUMN_NAME'
575
- fields = [
576
- row[field_key]
577
- for row in table_info
578
- ]
579
- pattern = '(?<!\\\\):(\\w+)'
580
- if type(where) == str:
581
- where_keys = findall(pattern, where)
584
+ if type(path) == str:
585
+ database, table = self.conn.db.database, path
582
586
  else:
583
- where_keys = ()
587
+ database, table = path
588
+ if fields is None:
589
+ fields = '*'
590
+ elif type(fields) != str:
591
+ fields = ', '.join(fields)
584
592
 
585
593
  # Generate SQL.
586
594
  sqls = []
587
595
 
588
596
  ## Part 'INSERT' syntax.
589
- sql_fields = ', '.join(
590
- f'`{field}`'
591
- for field in fields
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})'
597
+ sql_insert = f'INSERT INTO `{database}`.`{table}`'
598
+ if fields != '*':
599
+ sql_insert += f'({fields})'
609
600
  sqls.append(sql_insert)
610
601
 
611
602
  ## 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
603
  sql_select = (
638
- f'SELECT {sql_values}\n'
604
+ f'SELECT {fields}\n'
639
605
  f'FROM `{database}`.`{table}`'
640
606
  )
641
607
  sqls.append(sql_select)
@@ -735,7 +701,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
735
701
 
736
702
  def select(
737
703
  self,
738
- table: str,
704
+ path: str | tuple[str, str],
739
705
  fields: str | Iterable[str] | None = None,
740
706
  where: str | None = None,
741
707
  group: str | None = None,
@@ -750,7 +716,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
750
716
 
751
717
  Parameters
752
718
  ----------
753
- table : Table name, can include database name.
719
+ path : Path.
720
+ - `str`: Table name.
721
+ - `tuple[str, str]`: Database name and table name.
754
722
  fields : Select clause content.
755
723
  - `None`: Is `SELECT *`.
756
724
  - `str`: Join as `SELECT str`.
@@ -788,7 +756,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
788
756
  """
789
757
 
790
758
  # Handle parameter.
791
- sql = self.handle_select(table, fields, where, group, having, order, limit)
759
+ sql = self.handle_select(path, fields, where, group, having, order, limit)
792
760
 
793
761
  # Execute SQL.
794
762
  result = self.execute(sql, report=report, **kwdata)
@@ -798,7 +766,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
798
766
 
799
767
  def insert(
800
768
  self,
801
- table: str,
769
+ path: str | tuple[str, str],
802
770
  data: TableData,
803
771
  duplicate: Literal['ignore', 'update'] | Container[str] | None = None,
804
772
  report: bool | None = None,
@@ -809,7 +777,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
809
777
 
810
778
  Parameters
811
779
  ----------
812
- table : Table name, can include database name.
780
+ path : Path.
781
+ - `str`: Table name.
782
+ - `tuple[str, str]`: Database name and table name.
813
783
  data : Insert data.
814
784
  duplicate : Handle method when constraint error.
815
785
  - `None`: Not handled.
@@ -828,7 +798,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
828
798
 
829
799
  Examples
830
800
  --------
831
- Parameter `data` and `kwdata`.
832
801
  >>> data = [{'key': 'a'}, {'key': 'b'}]
833
802
  >>> kwdata = {'value1': 1, 'value2': ':(SELECT 2)'}
834
803
  >>> result = Database.execute.insert('table', data, **kwdata)
@@ -840,7 +809,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
840
809
  """
841
810
 
842
811
  # Handle parameter.
843
- sql, kwdata = self.handle_insert(table, data, duplicate, **kwdata)
812
+ sql, kwdata = self.handle_insert(path, data, duplicate, **kwdata)
844
813
 
845
814
  # Execute SQL.
846
815
  result = self.execute(sql, data, report, **kwdata)
@@ -850,7 +819,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
850
819
 
851
820
  def update(
852
821
  self,
853
- table: str,
822
+ path: str | tuple[str, str],
854
823
  data: TableData,
855
824
  where_fields: str | Iterable[str] | None = None,
856
825
  report: bool | None = None,
@@ -861,7 +830,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
861
830
 
862
831
  Parameters
863
832
  ----------
864
- table : Table name, can include database name.
833
+ path : Path.
834
+ - `str`: Table name.
835
+ - `tuple[str, str]`: Database name and table name.
865
836
  data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
866
837
  - `Key`: Table field.
867
838
  `literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
@@ -886,7 +857,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
886
857
 
887
858
  Examples
888
859
  --------
889
- Parameter `data` and `kwdata`.
890
860
  >>> data = [{'key': 'a'}, {'key': 'b'}]
891
861
  >>> kwdata = {'value': 1, 'name': ':`key`'}
892
862
  >>> result = Database.execute.update('table', data, **kwdata)
@@ -898,7 +868,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
898
868
  """
899
869
 
900
870
  # Handle parameter.
901
- sql, data = self.handle_update(table, data, where_fields, **kwdata)
871
+ sql, data = self.handle_update(path, data, where_fields, **kwdata)
902
872
 
903
873
  # Execute SQL.
904
874
  result = self.execute(sql, data, report)
@@ -908,7 +878,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
908
878
 
909
879
  def delete(
910
880
  self,
911
- table: str,
881
+ path: str | tuple[str, str],
912
882
  where: str | None = None,
913
883
  order: str | None = None,
914
884
  limit: int | str | None = None,
@@ -920,7 +890,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
920
890
 
921
891
  Parameters
922
892
  ----------
923
- table : Table name, can include database name.
893
+ path : Path.
894
+ - `str`: Table name.
895
+ - `tuple[str, str]`: Database name and table name.
924
896
  where : Clause `WHERE` content, join as `WHERE str`.
925
897
  order : Clause `ORDER BY` content, join as `ORDER BY str`.
926
898
  limit : Clause `LIMIT` content, join as `LIMIT int/str`.
@@ -934,7 +906,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
934
906
 
935
907
  Examples
936
908
  --------
937
- Parameter `where` and `kwdata`.
938
909
  >>> where = '`id` IN :ids'
939
910
  >>> ids = (1, 2)
940
911
  >>> result = Database.execute.delete('table', where, ids=ids)
@@ -943,7 +914,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
943
914
  """
944
915
 
945
916
  # Handle parameter.
946
- sql = self.handle_delete(table, where, order, limit)
917
+ sql = self.handle_delete(path, where, order, limit)
947
918
 
948
919
  # Execute SQL.
949
920
  result = self.execute(sql, report=report, **kwdata)
@@ -953,7 +924,8 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
953
924
 
954
925
  def copy(
955
926
  self,
956
- table: str,
927
+ path: str | tuple[str, str],
928
+ fields: str | Iterable[str] | None = None,
957
929
  where: str | None = None,
958
930
  limit: int | str | tuple[int, int] | None = None,
959
931
  report: bool | None = None,
@@ -964,18 +936,18 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
964
936
 
965
937
  Parameters
966
938
  ----------
967
- table : Table name, can include database name.
939
+ path : Path.
940
+ - `str`: Table name.
941
+ - `tuple[str, str]`: Database name and table name.
942
+ fields : Select clause content.
943
+ - `None`: Is `SELECT *`.
944
+ - `str`: Join as `SELECT str`.
945
+ - `Iterable[str]`: Join as `SELECT str`.
968
946
  where : Clause `WHERE` content, join as `WHERE str`.
969
947
  limit : Clause `LIMIT` content.
970
948
  - `int | str`: Join as `LIMIT int/str`.
971
949
  - `tuple[int, int]`: Join as `LIMIT int, int`.
972
- report : Whether report SQL execute information.
973
- - `None`: Use attribute `Database.report`.
974
950
  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
951
 
980
952
  Returns
981
953
  -------
@@ -983,7 +955,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
983
955
 
984
956
  Examples
985
957
  --------
986
- Parameter `where` and `kwdata`.
987
958
  >>> where = '`id` IN :ids'
988
959
  >>> ids = (1, 2, 3)
989
960
  >>> result = Database.execute.copy('table', where, 2, ids=ids, id=None, time=':NOW()')
@@ -992,7 +963,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
992
963
  """
993
964
 
994
965
  # Handle parameter.
995
- sql = self.handle_copy(table, where, limit, **kwdata)
966
+ sql = self.handle_copy(path, fields, where, limit)
996
967
 
997
968
  # Execute SQL.
998
969
  result = self.execute(sql, report=report, **kwdata)
@@ -1002,7 +973,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
1002
973
 
1003
974
  def count(
1004
975
  self,
1005
- table: str,
976
+ path: str | tuple[str, str],
1006
977
  where: str | None = None,
1007
978
  report: bool | None = None,
1008
979
  **kwdata: Any
@@ -1012,7 +983,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
1012
983
 
1013
984
  Parameters
1014
985
  ----------
1015
- table : Table name, can include database name.
986
+ path : Path.
987
+ - `str`: Table name.
988
+ - `tuple[str, str]`: Database name and table name.
1016
989
  where : Match condition, `WHERE` clause content, join as `WHERE str`.
1017
990
  - `None`: Match all.
1018
991
  - `str`: Match condition.
@@ -1026,7 +999,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
1026
999
 
1027
1000
  Examples
1028
1001
  --------
1029
- Parameter `where` and `kwdata`.
1030
1002
  >>> where = '`id` IN :ids'
1031
1003
  >>> ids = (1, 2)
1032
1004
  >>> result = Database.execute.count('table', where, ids=ids)
@@ -1035,7 +1007,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
1035
1007
  """
1036
1008
 
1037
1009
  # Execute.
1038
- result = self.select(table, '1', where=where, report=report, **kwdata)
1010
+ result = self.select(path, '1', where=where, report=report, **kwdata)
1039
1011
  count = len(tuple(result))
1040
1012
 
1041
1013
  return count
@@ -1043,7 +1015,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
1043
1015
 
1044
1016
  def exist(
1045
1017
  self,
1046
- table: str,
1018
+ path: str | tuple[str, str],
1047
1019
  where: str | None = None,
1048
1020
  report: bool | None = None,
1049
1021
  **kwdata: Any
@@ -1053,7 +1025,9 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
1053
1025
 
1054
1026
  Parameters
1055
1027
  ----------
1056
- table : Table name, can include database name.
1028
+ path : Path.
1029
+ - `str`: Table name.
1030
+ - `tuple[str, str]`: Database name and table name.
1057
1031
  where : Match condition, `WHERE` clause content, join as `WHERE str`.
1058
1032
  - `None`: Match all.
1059
1033
  - `str`: Match condition.
@@ -1067,7 +1041,6 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
1067
1041
 
1068
1042
  Examples
1069
1043
  --------
1070
- Parameter `where` and `kwdata`.
1071
1044
  >>> data = [{'id': 1}]
1072
1045
  >>> Database.execute.insert('table', data)
1073
1046
  >>> where = '`id` = :id_'
@@ -1078,7 +1051,7 @@ class DatabaseExecute(DatabaseExecuteSuper['rconn.DatabaseConnection']):
1078
1051
  """
1079
1052
 
1080
1053
  # Execute.
1081
- result = self.count(table, where, report, **kwdata)
1054
+ result = self.count(path, where, report, **kwdata)
1082
1055
 
1083
1056
  # Judge.
1084
1057
  judge = result != 0
@@ -1273,7 +1246,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1273
1246
 
1274
1247
  async def select(
1275
1248
  self,
1276
- table: str,
1249
+ path: str | tuple[str, str],
1277
1250
  fields: str | Iterable[str] | None = None,
1278
1251
  where: str | None = None,
1279
1252
  group: str | None = None,
@@ -1288,7 +1261,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1288
1261
 
1289
1262
  Parameters
1290
1263
  ----------
1291
- table : Table name, can include database name.
1264
+ path : Path.
1265
+ - `str`: Table name.
1266
+ - `tuple[str, str]`: Database name and table name.
1292
1267
  fields : Select clause content.
1293
1268
  - `None`: Is `SELECT *`.
1294
1269
  - `str`: Join as `SELECT str`.
@@ -1314,19 +1289,19 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1314
1289
  --------
1315
1290
  Parameter `fields`.
1316
1291
  >>> fields = ['id', ':`id` + 1 AS `id_`']
1317
- >>> result = Database.execute.select('table', fields)
1292
+ >>> result = await Database.execute.select('table', fields)
1318
1293
  >>> print(result.to_table())
1319
1294
  [{'id': 1, 'id_': 2}, ...]
1320
1295
 
1321
1296
  Parameter `kwdata`.
1322
1297
  >>> fields = '`id`, `id` + :value AS `id_`'
1323
- >>> result = Database.execute.select('table', fields, value=1)
1298
+ >>> result = await Database.execute.select('table', fields, value=1)
1324
1299
  >>> print(result.to_table())
1325
1300
  [{'id': 1, 'id_': 2}, ...]
1326
1301
  """
1327
1302
 
1328
1303
  # Handle parameter.
1329
- sql = self.handle_select(table, fields, where, group, having, order, limit)
1304
+ sql = self.handle_select(path, fields, where, group, having, order, limit)
1330
1305
 
1331
1306
  # Execute SQL.
1332
1307
  result = await self.execute(sql, report=report, **kwdata)
@@ -1336,7 +1311,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1336
1311
 
1337
1312
  async def insert(
1338
1313
  self,
1339
- table: str,
1314
+ path: str | tuple[str, str],
1340
1315
  data: TableData,
1341
1316
  duplicate: Literal['ignore', 'update'] | Container[str] | None = None,
1342
1317
  report: bool | None = None,
@@ -1347,7 +1322,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1347
1322
 
1348
1323
  Parameters
1349
1324
  ----------
1350
- table : Table name, can include database name.
1325
+ path : Path.
1326
+ - `str`: Table name.
1327
+ - `tuple[str, str]`: Database name and table name.
1351
1328
  data : Insert data.
1352
1329
  duplicate : Handle method when constraint error.
1353
1330
  - `None`: Not handled.
@@ -1366,19 +1343,18 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1366
1343
 
1367
1344
  Examples
1368
1345
  --------
1369
- Parameter `data` and `kwdata`.
1370
1346
  >>> data = [{'key': 'a'}, {'key': 'b'}]
1371
1347
  >>> kwdata = {'value1': 1, 'value2': ':(SELECT 2)'}
1372
- >>> result = Database.execute.insert('table', data, **kwdata)
1348
+ >>> result = await Database.execute.insert('table', data, **kwdata)
1373
1349
  >>> print(result.rowcount)
1374
1350
  2
1375
- >>> result = Database.execute.select('table')
1351
+ >>> result = await Database.execute.select('table')
1376
1352
  >>> print(result.to_table())
1377
1353
  [{'key': 'a', 'value1': 1, 'value2': 2}, {'key': 'b', 'value1': 1, 'value2': 2}]
1378
1354
  """
1379
1355
 
1380
1356
  # Handle parameter.
1381
- sql, kwdata = self.handle_insert(table, data, duplicate, **kwdata)
1357
+ sql, kwdata = self.handle_insert(path, data, duplicate, **kwdata)
1382
1358
 
1383
1359
  # Execute SQL.
1384
1360
  result = await self.execute(sql, data, report, **kwdata)
@@ -1388,7 +1364,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1388
1364
 
1389
1365
  async def update(
1390
1366
  self,
1391
- table: str,
1367
+ path: str | tuple[str, str],
1392
1368
  data: TableData,
1393
1369
  where_fields: str | Iterable[str] | None = None,
1394
1370
  report: bool | None = None,
@@ -1399,7 +1375,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1399
1375
 
1400
1376
  Parameters
1401
1377
  ----------
1402
- table : Table name, can include database name.
1378
+ path : Path.
1379
+ - `str`: Table name.
1380
+ - `tuple[str, str]`: Database name and table name.
1403
1381
  data : Update data, clause `SET` and `WHERE` and `ORDER BY` and `LIMIT` content.
1404
1382
  - `Key`: Table field.
1405
1383
  `literal['order']`: Clause `ORDER BY` content, join as `ORDER BY str`.
@@ -1424,19 +1402,18 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1424
1402
 
1425
1403
  Examples
1426
1404
  --------
1427
- Parameter `data` and `kwdata`.
1428
1405
  >>> data = [{'key': 'a'}, {'key': 'b'}]
1429
1406
  >>> kwdata = {'value': 1, 'name': ':`key`'}
1430
- >>> result = Database.execute.update('table', data, **kwdata)
1407
+ >>> result = await Database.execute.update('table', data, **kwdata)
1431
1408
  >>> print(result.rowcount)
1432
1409
  2
1433
- >>> result = Database.execute.select('table')
1410
+ >>> result = await Database.execute.select('table')
1434
1411
  >>> print(result.to_table())
1435
1412
  [{'key': 'a', 'value': 1, 'name': 'a'}, {'key': 'b', 'value': 1, 'name': 'b'}]
1436
1413
  """
1437
1414
 
1438
1415
  # Handle parameter.
1439
- sql, data = self.handle_update(table, data, where_fields, **kwdata)
1416
+ sql, data = self.handle_update(path, data, where_fields, **kwdata)
1440
1417
 
1441
1418
  # Execute SQL.
1442
1419
  result = await self.execute(sql, data, report)
@@ -1446,7 +1423,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1446
1423
 
1447
1424
  async def delete(
1448
1425
  self,
1449
- table: str,
1426
+ path: str | tuple[str, str],
1450
1427
  where: str | None = None,
1451
1428
  order: str | None = None,
1452
1429
  limit: int | str | None = None,
@@ -1458,7 +1435,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1458
1435
 
1459
1436
  Parameters
1460
1437
  ----------
1461
- table : Table name, can include database name.
1438
+ path : Path.
1439
+ - `str`: Table name.
1440
+ - `tuple[str, str]`: Database name and table name.
1462
1441
  where : Clause `WHERE` content, join as `WHERE str`.
1463
1442
  order : Clause `ORDER BY` content, join as `ORDER BY str`.
1464
1443
  limit : Clause `LIMIT` content, join as `LIMIT int/str`.
@@ -1472,16 +1451,15 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1472
1451
 
1473
1452
  Examples
1474
1453
  --------
1475
- Parameter `where` and `kwdata`.
1476
1454
  >>> where = '`id` IN :ids'
1477
1455
  >>> ids = (1, 2)
1478
- >>> result = Database.execute.delete('table', where, ids=ids)
1456
+ >>> result = await Database.execute.delete('table', where, ids=ids)
1479
1457
  >>> print(result.rowcount)
1480
1458
  2
1481
1459
  """
1482
1460
 
1483
1461
  # Handle parameter.
1484
- sql = self.handle_delete(table, where, order, limit)
1462
+ sql = self.handle_delete(path, where, order, limit)
1485
1463
 
1486
1464
  # Execute SQL.
1487
1465
  result = await self.execute(sql, report=report, **kwdata)
@@ -1491,7 +1469,8 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1491
1469
 
1492
1470
  async def copy(
1493
1471
  self,
1494
- table: str,
1472
+ path: str | tuple[str, str],
1473
+ fields: str | Iterable[str] | None = None,
1495
1474
  where: str | None = None,
1496
1475
  limit: int | str | tuple[int, int] | None = None,
1497
1476
  report: bool | None = None,
@@ -1502,18 +1481,18 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1502
1481
 
1503
1482
  Parameters
1504
1483
  ----------
1505
- table : Table name, can include database name.
1484
+ path : Path.
1485
+ - `str`: Table name.
1486
+ - `tuple[str, str]`: Database name and table name.
1487
+ fields : Select clause content.
1488
+ - `None`: Is `SELECT *`.
1489
+ - `str`: Join as `SELECT str`.
1490
+ - `Iterable[str]`: Join as `SELECT str`.
1506
1491
  where : Clause `WHERE` content, join as `WHERE str`.
1507
1492
  limit : Clause `LIMIT` content.
1508
1493
  - `int | str`: Join as `LIMIT int/str`.
1509
1494
  - `tuple[int, int]`: Join as `LIMIT int, int`.
1510
- report : Whether report SQL execute information.
1511
- - `None`: Use attribute `Database.report`.
1512
1495
  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
1496
 
1518
1497
  Returns
1519
1498
  -------
@@ -1521,16 +1500,15 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1521
1500
 
1522
1501
  Examples
1523
1502
  --------
1524
- Parameter `where` and `kwdata`.
1525
1503
  >>> where = '`id` IN :ids'
1526
1504
  >>> ids = (1, 2, 3)
1527
- >>> result = Database.execute.copy('table', where, 2, ids=ids, id=None, time=':NOW()')
1505
+ >>> result = await Database.execute.copy('table', ['name', 'value'], where, 2, ids=ids)
1528
1506
  >>> print(result.rowcount)
1529
1507
  2
1530
1508
  """
1531
1509
 
1532
1510
  # Handle parameter.
1533
- sql = self.handle_copy(table, where, limit, **kwdata)
1511
+ sql = self.handle_copy(path, fields, where, limit)
1534
1512
 
1535
1513
  # Execute SQL.
1536
1514
  result = await self.execute(sql, report=report, **kwdata)
@@ -1540,7 +1518,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1540
1518
 
1541
1519
  async def count(
1542
1520
  self,
1543
- table: str,
1521
+ path: str | tuple[str, str],
1544
1522
  where: str | None = None,
1545
1523
  report: bool | None = None,
1546
1524
  **kwdata: Any
@@ -1550,7 +1528,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1550
1528
 
1551
1529
  Parameters
1552
1530
  ----------
1553
- table : Table name, can include database name.
1531
+ path : Path.
1532
+ - `str`: Table name.
1533
+ - `tuple[str, str]`: Database name and table name.
1554
1534
  where : Match condition, `WHERE` clause content, join as `WHERE str`.
1555
1535
  - `None`: Match all.
1556
1536
  - `str`: Match condition.
@@ -1564,16 +1544,15 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1564
1544
 
1565
1545
  Examples
1566
1546
  --------
1567
- Parameter `where` and `kwdata`.
1568
1547
  >>> where = '`id` IN :ids'
1569
1548
  >>> ids = (1, 2)
1570
- >>> result = Database.execute.count('table', where, ids=ids)
1549
+ >>> result = await Database.execute.count('table', where, ids=ids)
1571
1550
  >>> print(result)
1572
1551
  2
1573
1552
  """
1574
1553
 
1575
1554
  # Execute.
1576
- result = await self.select(table, '1', where=where, report=report, **kwdata)
1555
+ result = await self.select(path, '1', where=where, report=report, **kwdata)
1577
1556
  count = len(tuple(result))
1578
1557
 
1579
1558
  return count
@@ -1581,7 +1560,7 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1581
1560
 
1582
1561
  async def exist(
1583
1562
  self,
1584
- table: str,
1563
+ path: str | tuple[str, str],
1585
1564
  where: str | None = None,
1586
1565
  report: bool | None = None,
1587
1566
  **kwdata: Any
@@ -1591,7 +1570,9 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1591
1570
 
1592
1571
  Parameters
1593
1572
  ----------
1594
- table : Table name, can include database name.
1573
+ path : Path.
1574
+ - `str`: Table name.
1575
+ - `tuple[str, str]`: Database name and table name.
1595
1576
  where : Match condition, `WHERE` clause content, join as `WHERE str`.
1596
1577
  - `None`: Match all.
1597
1578
  - `str`: Match condition.
@@ -1605,18 +1586,17 @@ class DatabaseExecuteAsync(DatabaseExecuteSuper['rconn.DatabaseConnectionAsync']
1605
1586
 
1606
1587
  Examples
1607
1588
  --------
1608
- Parameter `where` and `kwdata`.
1609
1589
  >>> data = [{'id': 1}]
1610
1590
  >>> Database.execute.insert('table', data)
1611
1591
  >>> where = '`id` = :id_'
1612
1592
  >>> id_ = 1
1613
- >>> result = Database.execute.exist('table', where, id_=id_)
1593
+ >>> result = await Database.execute.exist('table', where, id_=id_)
1614
1594
  >>> print(result)
1615
1595
  True
1616
1596
  """
1617
1597
 
1618
1598
  # Execute.
1619
- result = await self.count(table, where, report, **kwdata)
1599
+ result = await self.count(path, where, report, **kwdata)
1620
1600
 
1621
1601
  # Judge.
1622
1602
  judge = result != 0