mysqlengine 0.1.11.8__cp311-cp311-macosx_10_9_universal2.whl → 0.1.12.1__cp311-cp311-macosx_10_9_universal2.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.

Potentially problematic release.


This version of mysqlengine might be problematic. Click here for more details.

mysqlengine/database.py CHANGED
@@ -41,11 +41,11 @@ datetime.import_datetime()
41
41
  import os, datetime
42
42
  from uuid import uuid4
43
43
  from asyncio import gather, wait_for
44
- from typing import Any, Union, Literal, Iterator
45
- from pandas import DataFrame, Series, read_parquet
44
+ from typing import Any, Union, Literal, Iterator, overload
46
45
  from cytimes.pydt import pydt
47
46
  from cytimes.pddt import pddt
48
47
  from cytimes import cydatetime as cydt
48
+ from pandas import DataFrame, Series, read_parquet
49
49
  from mysqlengine.logs import logger
50
50
  from mysqlengine import errors, settings, transcode, utils
51
51
  from mysqlengine.regex import Regex, TableRegex
@@ -807,6 +807,189 @@ class Table:
807
807
  resolve_absent_table=resolve_absent_table,
808
808
  )
809
809
 
810
+ @overload
811
+ async def fetch_query(
812
+ self,
813
+ stmt: str,
814
+ args: Union[list, tuple, None] = None,
815
+ conn: Union[Connection, None] = None,
816
+ cursor: type[DictCursor | SSDictCursor] = DictCursor,
817
+ timeout: Union[int, None] = None,
818
+ warnings: bool = True,
819
+ *,
820
+ resolve_absent_table: bool = False,
821
+ ) -> tuple[dict[str, Any]]:
822
+ """Execute a SQL statement and fetch the result.
823
+
824
+ :param stmt: `<str>` The plain SQL statement to be executed.
825
+ :param args: `<list/tuple>` Arguments for the `'%s'` placeholders in 'stmt'. Defaults to `None`.
826
+ :param conn: `<Connection>` Specific connection to execute this query. Defaults to `None`.
827
+ - If provided, the conn will be used to execute the SQL 'stmt'.
828
+ This parameter is typically used within the `acquire()` or
829
+ `transaction()` context.
830
+ - If `None`, a temporary conn will be acquired from the Server pool
831
+ to execute the `stmt`. After execution, the temporary conn will
832
+ execute `COMMIT` and release back to the Server pool.
833
+
834
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
835
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
836
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
837
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
838
+
839
+ :param timeout: `<int>` Query execution timeout in seconds. Dafaults to `None`.
840
+ - If set to `None` or `0`, `tables.server.query_timeout` will be used
841
+ as the default timeout.
842
+ - `SQLQueryTimeoutError` will be raised when the timeout is reached.
843
+
844
+ :param warnings: `<bool>` Whether to issue any SQL related warnings. Defaults to `True`.
845
+
846
+ :param resolve_absent_table: `<bool>` Whether to resolve absent table. Defaults to `False`.
847
+ - If `True`, when `stmt` involves a table that does not exist, an attempt
848
+ will be made to create the missing table (if it belongs to the current
849
+ database). If creation failed, an `SQLQueryProgrammingError` will be
850
+ raised; otherwise, an `SQLQueryTableDontExistsError` will be raised.
851
+ - If `False`, when `stmt` involves a table that does not exist, instead of
852
+ raising an error, an empty `<tuple>` will be returned as the execution
853
+ result.
854
+
855
+ :raises: Subclass of `QueryError`.
856
+ :return `<tuple[dict[str, Any]]>`: The fetched result.
857
+
858
+ Example:
859
+ >>> await db.user.fetch_query(
860
+ "SELECT name, price FROM db.user WHERE id = %s",
861
+ args=(1,), # does not support multi-rows arguments.
862
+ conn=None,
863
+ cursor=DictCursor,
864
+ resolve_absent_table=False,
865
+ timeout=10,
866
+ warnings=True,
867
+ )
868
+ """
869
+ ...
870
+
871
+ @overload
872
+ async def fetch_query(
873
+ self,
874
+ stmt: str,
875
+ args: Union[list, tuple, None] = None,
876
+ conn: Union[Connection, None] = None,
877
+ cursor: type[DfCursor | SSDfCursor] = DictCursor,
878
+ timeout: Union[int, None] = None,
879
+ warnings: bool = True,
880
+ *,
881
+ resolve_absent_table: bool = False,
882
+ ) -> DataFrame:
883
+ """Execute a SQL statement and fetch the result.
884
+
885
+ :param stmt: `<str>` The plain SQL statement to be executed.
886
+ :param args: `<list/tuple>` Arguments for the `'%s'` placeholders in 'stmt'. Defaults to `None`.
887
+ :param conn: `<Connection>` Specific connection to execute this query. Defaults to `None`.
888
+ - If provided, the conn will be used to execute the SQL 'stmt'.
889
+ This parameter is typically used within the `acquire()` or
890
+ `transaction()` context.
891
+ - If `None`, a temporary conn will be acquired from the Server pool
892
+ to execute the `stmt`. After execution, the temporary conn will
893
+ execute `COMMIT` and release back to the Server pool.
894
+
895
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
896
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
897
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
898
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
899
+
900
+ :param timeout: `<int>` Query execution timeout in seconds. Dafaults to `None`.
901
+ - If set to `None` or `0`, `tables.server.query_timeout` will be used
902
+ as the default timeout.
903
+ - `SQLQueryTimeoutError` will be raised when the timeout is reached.
904
+
905
+ :param warnings: `<bool>` Whether to issue any SQL related warnings. Defaults to `True`.
906
+
907
+ :param resolve_absent_table: `<bool>` Whether to resolve absent table. Defaults to `False`.
908
+ - If `True`, when `stmt` involves a table that does not exist, an attempt
909
+ will be made to create the missing table (if it belongs to the current
910
+ database). If creation failed, an `SQLQueryProgrammingError` will be
911
+ raised; otherwise, an `SQLQueryTableDontExistsError` will be raised.
912
+ - If `False`, when `stmt` involves a table that does not exist, instead of
913
+ raising an error, an empty `<DataFrame>` will be returned as the execution
914
+ result.
915
+
916
+ :raises: Subclass of `QueryError`.
917
+ :return `<DataFrame>`: The fetched result.
918
+
919
+ Example:
920
+ >>> await db.user.fetch_query(
921
+ "SELECT name, price FROM db.user WHERE id = %s",
922
+ args=(1,), # does not support multi-rows arguments.
923
+ conn=None,
924
+ cursor=DictCursor,
925
+ resolve_absent_table=False,
926
+ timeout=10,
927
+ warnings=True,
928
+ )
929
+ """
930
+ ...
931
+
932
+ @overload
933
+ async def fetch_query(
934
+ self,
935
+ stmt: str,
936
+ args: Union[list, tuple, None] = None,
937
+ conn: Union[Connection, None] = None,
938
+ cursor: type[Cursor | SSCursor] = DictCursor,
939
+ timeout: Union[int, None] = None,
940
+ warnings: bool = True,
941
+ *,
942
+ resolve_absent_table: bool = False,
943
+ ) -> tuple[tuple[Any]]:
944
+ """Execute a SQL statement and fetch the result.
945
+
946
+ :param stmt: `<str>` The plain SQL statement to be executed.
947
+ :param args: `<list/tuple>` Arguments for the `'%s'` placeholders in 'stmt'. Defaults to `None`.
948
+ :param conn: `<Connection>` Specific connection to execute this query. Defaults to `None`.
949
+ - If provided, the conn will be used to execute the SQL 'stmt'.
950
+ This parameter is typically used within the `acquire()` or
951
+ `transaction()` context.
952
+ - If `None`, a temporary conn will be acquired from the Server pool
953
+ to execute the `stmt`. After execution, the temporary conn will
954
+ execute `COMMIT` and release back to the Server pool.
955
+
956
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
957
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
958
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
959
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
960
+
961
+ :param timeout: `<int>` Query execution timeout in seconds. Dafaults to `None`.
962
+ - If set to `None` or `0`, `tables.server.query_timeout` will be used
963
+ as the default timeout.
964
+ - `SQLQueryTimeoutError` will be raised when the timeout is reached.
965
+
966
+ :param warnings: `<bool>` Whether to issue any SQL related warnings. Defaults to `True`.
967
+
968
+ :param resolve_absent_table: `<bool>` Whether to resolve absent table. Defaults to `False`.
969
+ - If `True`, when `stmt` involves a table that does not exist, an attempt
970
+ will be made to create the missing table (if it belongs to the current
971
+ database). If creation failed, an `SQLQueryProgrammingError` will be
972
+ raised; otherwise, an `SQLQueryTableDontExistsError` will be raised.
973
+ - If `False`, when `stmt` involves a table that does not exist, instead of
974
+ raising an error, an empty `tuple[tuple]` will be returned as the execution
975
+ result.
976
+
977
+ :raises: Subclass of `QueryError`.
978
+ :return `<tuple[tuple]>`: The fetched result.
979
+
980
+ Example:
981
+ >>> await db.user.fetch_query(
982
+ "SELECT name, price FROM db.user WHERE id = %s",
983
+ args=(1,), # does not support multi-rows arguments.
984
+ conn=None,
985
+ cursor=DictCursor,
986
+ resolve_absent_table=False,
987
+ timeout=10,
988
+ warnings=True,
989
+ )
990
+ """
991
+ ...
992
+
810
993
  async def fetch_query(
811
994
  self,
812
995
  stmt: str,
@@ -819,7 +1002,7 @@ class Table:
819
1002
  warnings: bool = True,
820
1003
  *,
821
1004
  resolve_absent_table: bool = False,
822
- ) -> Union[tuple[dict | Any], DataFrame]:
1005
+ ) -> Union[tuple[dict[str, Any] | tuple[Any]], DataFrame]:
823
1006
  """Execute a SQL statement and fetch the result.
824
1007
 
825
1008
  :param stmt: `<str>` The plain SQL statement to be executed.
@@ -834,8 +1017,8 @@ class Table:
834
1017
 
835
1018
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
836
1019
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
837
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
838
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
1020
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1021
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
839
1022
 
840
1023
  :param timeout: `<int>` Query execution timeout in seconds. Dafaults to `None`.
841
1024
  - If set to `None` or `0`, `tables.server.query_timeout` will be used
@@ -1126,6 +1309,159 @@ class Table:
1126
1309
  await cur.execute("TRUNCATE TABLE %s.%s;" % (self._db._name, name))
1127
1310
  return True
1128
1311
 
1312
+ @overload
1313
+ async def information(
1314
+ self,
1315
+ *info: Literal[
1316
+ "*",
1317
+ "table_name",
1318
+ "table_catalog",
1319
+ "table_schema",
1320
+ "table_type",
1321
+ "engine",
1322
+ "version",
1323
+ "row_format",
1324
+ "table_rows",
1325
+ "avg_row_length",
1326
+ "data_length",
1327
+ "max_data_length",
1328
+ "index_length",
1329
+ "data_free",
1330
+ "auto_increment",
1331
+ "create_time",
1332
+ "update_time",
1333
+ "check_time",
1334
+ "table_collation",
1335
+ "checksum",
1336
+ "create_options",
1337
+ "table_comment",
1338
+ ],
1339
+ cursor: type[DictCursor | SSDictCursor] = DictCursor,
1340
+ ) -> tuple[dict[str, Any]]:
1341
+ """Select table information from `INFORMATION_SCHEMA`.
1342
+
1343
+ Available information options:
1344
+ - 'table_name', 'table_catalog', 'table_schema', 'table_type', 'engine', 'version',
1345
+ - 'row_format', 'table_rows', 'avg_row_length', 'data_length', 'max_data_length',
1346
+ - 'index_length', 'data_free', 'auto_increment', 'create_time', 'update_time',
1347
+ - 'check_time', 'table_collation', 'checksum', 'create_options', 'table_comment'
1348
+
1349
+ :param info: `<str>` The information to be selected.
1350
+ - If not specified, defaults to `'table_name'`.
1351
+ - Use `'*'` to select all information.
1352
+
1353
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1354
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1355
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1356
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1357
+
1358
+ :raise: Subclass of `QueryError`.
1359
+ :return `<tuple[dict]>`: Table information..
1360
+ """
1361
+ ...
1362
+
1363
+ @overload
1364
+ async def information(
1365
+ self,
1366
+ *info: Literal[
1367
+ "*",
1368
+ "table_name",
1369
+ "table_catalog",
1370
+ "table_schema",
1371
+ "table_type",
1372
+ "engine",
1373
+ "version",
1374
+ "row_format",
1375
+ "table_rows",
1376
+ "avg_row_length",
1377
+ "data_length",
1378
+ "max_data_length",
1379
+ "index_length",
1380
+ "data_free",
1381
+ "auto_increment",
1382
+ "create_time",
1383
+ "update_time",
1384
+ "check_time",
1385
+ "table_collation",
1386
+ "checksum",
1387
+ "create_options",
1388
+ "table_comment",
1389
+ ],
1390
+ cursor: type[DfCursor | SSDfCursor] = DictCursor,
1391
+ ) -> DataFrame:
1392
+ """Select table information from `INFORMATION_SCHEMA`.
1393
+
1394
+ Available information options:
1395
+ - 'table_name', 'table_catalog', 'table_schema', 'table_type', 'engine', 'version',
1396
+ - 'row_format', 'table_rows', 'avg_row_length', 'data_length', 'max_data_length',
1397
+ - 'index_length', 'data_free', 'auto_increment', 'create_time', 'update_time',
1398
+ - 'check_time', 'table_collation', 'checksum', 'create_options', 'table_comment'
1399
+
1400
+ :param info: `<str>` The information to be selected.
1401
+ - If not specified, defaults to `'table_name'`.
1402
+ - Use `'*'` to select all information.
1403
+
1404
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1405
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1406
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1407
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1408
+
1409
+ :raise: Subclass of `QueryError`.
1410
+ :return `<DataFrame>`: Table information.
1411
+ """
1412
+ ...
1413
+
1414
+ @overload
1415
+ async def information(
1416
+ self,
1417
+ *info: Literal[
1418
+ "*",
1419
+ "table_name",
1420
+ "table_catalog",
1421
+ "table_schema",
1422
+ "table_type",
1423
+ "engine",
1424
+ "version",
1425
+ "row_format",
1426
+ "table_rows",
1427
+ "avg_row_length",
1428
+ "data_length",
1429
+ "max_data_length",
1430
+ "index_length",
1431
+ "data_free",
1432
+ "auto_increment",
1433
+ "create_time",
1434
+ "update_time",
1435
+ "check_time",
1436
+ "table_collation",
1437
+ "checksum",
1438
+ "create_options",
1439
+ "table_comment",
1440
+ ],
1441
+ cursor: type[Cursor | SSCursor] = DictCursor,
1442
+ ) -> tuple[tuple[Any]]:
1443
+ """Select table information from `INFORMATION_SCHEMA`.
1444
+
1445
+ Available information options:
1446
+ - 'table_name', 'table_catalog', 'table_schema', 'table_type', 'engine', 'version',
1447
+ - 'row_format', 'table_rows', 'avg_row_length', 'data_length', 'max_data_length',
1448
+ - 'index_length', 'data_free', 'auto_increment', 'create_time', 'update_time',
1449
+ - 'check_time', 'table_collation', 'checksum', 'create_options', 'table_comment'
1450
+
1451
+ :param info: `<str>` The information to be selected.
1452
+ - If not specified, defaults to `'table_name'`.
1453
+ - Use `'*'` to select all information.
1454
+
1455
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1456
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1457
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1458
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1459
+
1460
+ :raise: Subclass of `QueryError`.
1461
+ :return `<tuple[tuple]>`: Table information.
1462
+ """
1463
+ ...
1464
+
1129
1465
  async def information(
1130
1466
  self,
1131
1467
  *info: Literal[
@@ -1155,7 +1491,7 @@ class Table:
1155
1491
  cursor: type[
1156
1492
  DictCursor | SSDictCursor | DfCursor | SSDfCursor | Cursor | SSCursor
1157
1493
  ] = DictCursor,
1158
- ) -> Union[tuple[dict | Any], DataFrame]:
1494
+ ) -> Union[tuple[dict[str, Any] | tuple[Any]], DataFrame]:
1159
1495
  """Select table information from `INFORMATION_SCHEMA`.
1160
1496
 
1161
1497
  Available information options:
@@ -1170,11 +1506,11 @@ class Table:
1170
1506
 
1171
1507
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1172
1508
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1173
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
1174
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
1509
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1510
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1175
1511
 
1176
1512
  :raise: Subclass of `QueryError`.
1177
- :return `<tuple/DataFrame>`: Table information. (depends on 'cursor' type).
1513
+ :return `<tuple/DataFrame>`: Table information (depends on 'cursor' type).
1178
1514
  """
1179
1515
  # Check info
1180
1516
  info_: str
@@ -1195,21 +1531,72 @@ class Table:
1195
1531
  )
1196
1532
  return await cur.fetchall()
1197
1533
 
1534
+ @overload
1535
+ async def describe(
1536
+ self,
1537
+ cursor: type[DictCursor | SSDictCursor] = DictCursor,
1538
+ ) -> tuple[dict[str, Any]]:
1539
+ """`DESCRIBE` the table.
1540
+
1541
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1542
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1543
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1544
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1545
+
1546
+ :raise: Subclass of `QueryError`.
1547
+ :return `<tuple[dict]>`: Table description.
1548
+ """
1549
+ ...
1550
+
1551
+ @overload
1552
+ async def describe(
1553
+ self,
1554
+ cursor: type[DfCursor | SSDfCursor] = DictCursor,
1555
+ ) -> DataFrame:
1556
+ """`DESCRIBE` the table.
1557
+
1558
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1559
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1560
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1561
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1562
+
1563
+ :raise: Subclass of `QueryError`.
1564
+ :return `<DataFrame>`: Table description.
1565
+ """
1566
+ ...
1567
+
1568
+ @overload
1569
+ async def describe(
1570
+ self,
1571
+ cursor: type[Cursor | SSCursor] = DictCursor,
1572
+ ) -> tuple[tuple[Any]]:
1573
+ """`DESCRIBE` the table.
1574
+
1575
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1576
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1577
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1578
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1579
+
1580
+ :raise: Subclass of `QueryError`.
1581
+ :return `<tuple[tuple]>`: Table description.
1582
+ """
1583
+ ...
1584
+
1198
1585
  async def describe(
1199
1586
  self,
1200
1587
  cursor: type[
1201
1588
  DictCursor | SSDictCursor | DfCursor | SSDfCursor | Cursor | SSCursor
1202
1589
  ] = DictCursor,
1203
- ) -> Union[tuple[dict | Any], DataFrame]:
1590
+ ) -> Union[tuple[dict[str, Any] | tuple[Any]], DataFrame]:
1204
1591
  """`DESCRIBE` the table.
1205
1592
 
1206
1593
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1207
1594
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1208
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
1209
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
1595
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1596
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1210
1597
 
1211
1598
  :raise: Subclass of `QueryError`.
1212
- :return `<tuple/DataFrame>`: Table description. (depends on 'cursor' type).
1599
+ :return `<tuple/DataFrame>`: Table description (depends on 'cursor' type).
1213
1600
  """
1214
1601
  return await self._describe(self._name, cursor)
1215
1602
 
@@ -1225,11 +1612,11 @@ class Table:
1225
1612
  :param name: `<str>` Name of the table.
1226
1613
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution.
1227
1614
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1228
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
1229
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
1615
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1616
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1230
1617
 
1231
1618
  :raise: Subclass of `QueryError`.
1232
- :return `<tuple/DataFrame>`: Table description. (depends on 'cursor' type).
1619
+ :return `<tuple/DataFrame>`: Table description (depends on 'cursor' type).
1233
1620
  """
1234
1621
  # Execute describe query
1235
1622
  async with self._server.acquire() as conn:
@@ -1484,21 +1871,72 @@ class Table:
1484
1871
  )
1485
1872
  return True
1486
1873
 
1874
+ @overload
1875
+ async def show_index(
1876
+ self,
1877
+ cursor: type[DictCursor | SSDictCursor] = DictCursor,
1878
+ ) -> tuple[dict[str, Any]]:
1879
+ """`SHOW INDEX` from the table.
1880
+
1881
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1882
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1883
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1884
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1885
+
1886
+ :raise: Subclass of `QueryError`.
1887
+ :return `<tuple[dict]>`: Index information.
1888
+ """
1889
+ ...
1890
+
1891
+ @overload
1892
+ async def show_index(
1893
+ self,
1894
+ cursor: type[DfCursor | SSDfCursor] = DictCursor,
1895
+ ) -> DataFrame:
1896
+ """`SHOW INDEX` from the table.
1897
+
1898
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1899
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1900
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1901
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1902
+
1903
+ :raise: Subclass of `QueryError`.
1904
+ :return `<DataFrame>`: Index information.
1905
+ """
1906
+ ...
1907
+
1908
+ @overload
1909
+ async def show_index(
1910
+ self,
1911
+ cursor: type[Cursor | SSCursor] = DictCursor,
1912
+ ) -> tuple[tuple[Any]]:
1913
+ """`SHOW INDEX` from the table.
1914
+
1915
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1916
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1917
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1918
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1919
+
1920
+ :raise: Subclass of `QueryError`.
1921
+ :return `<tuple[tuple]>`: Index information.
1922
+ """
1923
+ ...
1924
+
1487
1925
  async def show_index(
1488
1926
  self,
1489
1927
  cursor: type[
1490
1928
  DictCursor | SSDictCursor | DfCursor | SSDfCursor | Cursor | SSCursor
1491
1929
  ] = DictCursor,
1492
- ) -> Union[tuple[dict | Any], DataFrame]:
1930
+ ) -> Union[tuple[dict[str, Any] | tuple[Any]], DataFrame]:
1493
1931
  """`SHOW INDEX` from the table.
1494
1932
 
1495
1933
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
1496
1934
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1497
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
1498
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
1935
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1936
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1499
1937
 
1500
1938
  :raise: Subclass of `QueryError`.
1501
- :return `<tuple/DataFrame>`: Index information. (depends on 'cursor' type).
1939
+ :return `<tuple/DataFrame>`: Index information (depends on 'cursor' type).
1502
1940
  """
1503
1941
  return await self._show_index(self._name, cursor)
1504
1942
 
@@ -1514,11 +1952,11 @@ class Table:
1514
1952
  :param name: `<str>` Name of the table.
1515
1953
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution.
1516
1954
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
1517
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
1518
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
1955
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
1956
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
1519
1957
 
1520
1958
  :raise: Subclass of `QueryError`.
1521
- :return `<tuple/DataFrame>`: Index information. (depends on 'cursor' type).
1959
+ :return `<tuple/DataFrame>`: Index information (depends on 'cursor' type).
1522
1960
  """
1523
1961
  # Execute show query
1524
1962
  async with self._server.acquire() as conn:
@@ -2191,46 +2629,130 @@ class Table:
2191
2629
  "combination.".format(repr(charset), repr(collate))
2192
2630
  ) from err
2193
2631
 
2194
- @cython.cfunc
2195
- @cython.inline(True)
2196
- def _validate_cursor(self, cursor: object):
2197
- "(cfunc) Validate cursor `<Cursor>` (internal use only)."
2198
- if not issubclass(cursor, Cursor):
2199
- raise errors.QueryValueError(
2200
- "<{}> Parameter 'cursor' only accepts subclass of `<Cursor>`, "
2201
- "instead of: {} {}".format(self._name, cursor, repr(cursor))
2202
- )
2632
+ @cython.cfunc
2633
+ @cython.inline(True)
2634
+ def _validate_cursor(self, cursor: object):
2635
+ "(cfunc) Validate cursor `<Cursor>` (internal use only)."
2636
+ if not issubclass(cursor, Cursor):
2637
+ raise errors.QueryValueError(
2638
+ "<{}> Parameter 'cursor' only accepts subclass of `<Cursor>`, "
2639
+ "instead of: {} {}".format(self._name, cursor, repr(cursor))
2640
+ )
2641
+
2642
+ # Escape data ---------------------------------------------------------
2643
+ @cython.cfunc
2644
+ @cython.inline(True)
2645
+ def _escape_item(self, item: object) -> str:
2646
+ "(cfunc) Escape item to Literal string `<str>`."
2647
+ return transcode.encode_item(item, self._server._backslash_escapes)
2648
+
2649
+ def escape_item(self, item: Any) -> str:
2650
+ "Escape item to Literal string `<str>`."
2651
+ return self._escape_item(item)
2652
+
2653
+ @cython.cfunc
2654
+ @cython.inline(True)
2655
+ def _escape_args(self, args: object) -> object:
2656
+ """(cfunc) Escape arguments to literal `<tuple/dict>`.
2657
+
2658
+ - If the given 'args' is type of `<dict>`, returns `<dict>`.
2659
+ - All other supported data types returns `<tuple>`.
2660
+ """
2661
+ return transcode.encode_args(args, self._server._backslash_escapes)
2662
+
2663
+ def escape_args(self, args: Union[list, tuple]) -> Union[tuple, dict]:
2664
+ """Escape arguments to literal `<tuple/dict>`.
2665
+
2666
+ - If the given 'args' is type of `<dict>`, returns `<dict>`.
2667
+ - All other supported data types returns `<tuple>`.
2668
+ """
2669
+ return self._escape_args(args)
2670
+
2671
+ # Filter data ---------------------------------------------------------
2672
+ @overload
2673
+ def filter_columns(self, data: dict, *columns: str) -> dict:
2674
+ """Filter Table data by columns.
2675
+
2676
+ :param data: The data of the Table to filter. Support data types:
2677
+ - `<dict>`: a single row of table data.
2678
+ - `<list[dict]>`: multiple rows of table data.
2679
+ - `<tuple[dict]>`: multiple rows of table data.
2680
+ - `<DataFrame>`: a pandas DataFrame of table data.
2681
+
2682
+ :param columns: `<str>` Columns to keep in the data.
2683
+ - If not provided, all columns in the data that
2684
+ belongs to the table will be kept.
2685
+ - If provided, only the specified columns that
2686
+ also belongs to the table will be kept.
2687
+
2688
+ :raise: `QueryDataError`
2689
+ :return `<dict>`: Table data filtered by columns.
2690
+ """
2691
+ ...
2692
+
2693
+ @overload
2694
+ def filter_columns(self, data: list[dict], *columns: str) -> list[dict]:
2695
+ """Filter Table data by columns.
2696
+
2697
+ :param data: The data of the Table to filter. Support data types:
2698
+ - `<dict>`: a single row of table data.
2699
+ - `<list[dict]>`: multiple rows of table data.
2700
+ - `<tuple[dict]>`: multiple rows of table data.
2701
+ - `<DataFrame>`: a pandas DataFrame of table data.
2702
+
2703
+ :param columns: `<str>` Columns to keep in the data.
2704
+ - If not provided, all columns in the data that
2705
+ belongs to the table will be kept.
2706
+ - If provided, only the specified columns that
2707
+ also belongs to the table will be kept.
2708
+
2709
+ :raise: `QueryDataError`
2710
+ :return `<list[dict]>`: Table data filtered by columns.
2711
+ """
2712
+ ...
2203
2713
 
2204
- # Escape data ---------------------------------------------------------
2205
- @cython.cfunc
2206
- @cython.inline(True)
2207
- def _escape_item(self, item: object) -> str:
2208
- "(cfunc) Escape item to Literal string `<str>`."
2209
- return transcode.encode_item(item, self._server._backslash_escapes)
2714
+ @overload
2715
+ def filter_columns(self, data: tuple[dict], *columns: str) -> tuple[dict]:
2716
+ """Filter Table data by columns.
2210
2717
 
2211
- def escape_item(self, item: Any) -> str:
2212
- "Escape item to Literal string `<str>`."
2213
- return self._escape_item(item)
2718
+ :param data: The data of the Table to filter. Support data types:
2719
+ - `<dict>`: a single row of table data.
2720
+ - `<list[dict]>`: multiple rows of table data.
2721
+ - `<tuple[dict]>`: multiple rows of table data.
2722
+ - `<DataFrame>`: a pandas DataFrame of table data.
2214
2723
 
2215
- @cython.cfunc
2216
- @cython.inline(True)
2217
- def _escape_args(self, args: object) -> object:
2218
- """(cfunc) Escape arguments to literal `<tuple/dict>`.
2724
+ :param columns: `<str>` Columns to keep in the data.
2725
+ - If not provided, all columns in the data that
2726
+ belongs to the table will be kept.
2727
+ - If provided, only the specified columns that
2728
+ also belongs to the table will be kept.
2219
2729
 
2220
- - If the given 'args' is type of `<dict>`, returns `<dict>`.
2221
- - All other supported data types returns `<tuple>`.
2730
+ :raise: `QueryDataError`
2731
+ :return `<tuple[dict]>`: Table data filtered by columns.
2222
2732
  """
2223
- return transcode.encode_args(args, self._server._backslash_escapes)
2733
+ ...
2224
2734
 
2225
- def escape_args(self, args: Union[list, tuple]) -> Union[tuple, dict]:
2226
- """Escape arguments to literal `<tuple/dict>`.
2735
+ @overload
2736
+ def filter_columns(self, data: DataFrame, *columns: str) -> DataFrame:
2737
+ """Filter Table data by columns.
2227
2738
 
2228
- - If the given 'args' is type of `<dict>`, returns `<dict>`.
2229
- - All other supported data types returns `<tuple>`.
2739
+ :param data: The data of the Table to filter. Support data types:
2740
+ - `<dict>`: a single row of table data.
2741
+ - `<list[dict]>`: multiple rows of table data.
2742
+ - `<tuple[dict]>`: multiple rows of table data.
2743
+ - `<DataFrame>`: a pandas DataFrame of table data.
2744
+
2745
+ :param columns: `<str>` Columns to keep in the data.
2746
+ - If not provided, all columns in the data that
2747
+ belongs to the table will be kept.
2748
+ - If provided, only the specified columns that
2749
+ also belongs to the table will be kept.
2750
+
2751
+ :raise: `QueryDataError`
2752
+ :return `<DataFrame>`: Table data filtered by columns (original data type).
2230
2753
  """
2231
- return self._escape_args(args)
2754
+ ...
2232
2755
 
2233
- # Filter data ---------------------------------------------------------
2234
2756
  def filter_columns(
2235
2757
  self,
2236
2758
  data: Union[dict, list[dict], tuple[dict], DataFrame],
@@ -3857,6 +4379,159 @@ class TimeTable(Table):
3857
4379
  raise i
3858
4380
  return True
3859
4381
 
4382
+ @overload
4383
+ async def information(
4384
+ self,
4385
+ *info: Literal[
4386
+ "*",
4387
+ "table_name",
4388
+ "table_catalog",
4389
+ "table_schema",
4390
+ "table_type",
4391
+ "engine",
4392
+ "version",
4393
+ "row_format",
4394
+ "table_rows",
4395
+ "avg_row_length",
4396
+ "data_length",
4397
+ "max_data_length",
4398
+ "index_length",
4399
+ "data_free",
4400
+ "auto_increment",
4401
+ "create_time",
4402
+ "update_time",
4403
+ "check_time",
4404
+ "table_collation",
4405
+ "checksum",
4406
+ "create_options",
4407
+ "table_comment",
4408
+ ],
4409
+ cursor: type[DictCursor | SSDictCursor] = DictCursor,
4410
+ ) -> tuple[dict[str, Any]]:
4411
+ """Select all sub-tables information from `INFORMATION_SCHEMA`.
4412
+
4413
+ Available information options:
4414
+ - 'table_name', 'table_catalog', 'table_schema', 'table_type', 'engine', 'version',
4415
+ - 'row_format', 'table_rows', 'avg_row_length', 'data_length', 'max_data_length',
4416
+ - 'index_length', 'data_free', 'auto_increment', 'create_time', 'update_time',
4417
+ - 'check_time', 'table_collation', 'checksum', 'create_options', 'table_comment'
4418
+
4419
+ :param info: `<str>` The information to be selected.
4420
+ - If not specified, defaults to `'table_name'`.
4421
+ - Use `'*'` to select all information.
4422
+
4423
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4424
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4425
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4426
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4427
+
4428
+ :raise: Subclass of `QueryError`.
4429
+ :return `<tuple[dict]>`: All sub-tables information.
4430
+ """
4431
+ ...
4432
+
4433
+ @overload
4434
+ async def information(
4435
+ self,
4436
+ *info: Literal[
4437
+ "*",
4438
+ "table_name",
4439
+ "table_catalog",
4440
+ "table_schema",
4441
+ "table_type",
4442
+ "engine",
4443
+ "version",
4444
+ "row_format",
4445
+ "table_rows",
4446
+ "avg_row_length",
4447
+ "data_length",
4448
+ "max_data_length",
4449
+ "index_length",
4450
+ "data_free",
4451
+ "auto_increment",
4452
+ "create_time",
4453
+ "update_time",
4454
+ "check_time",
4455
+ "table_collation",
4456
+ "checksum",
4457
+ "create_options",
4458
+ "table_comment",
4459
+ ],
4460
+ cursor: type[DfCursor | SSDfCursor] = DictCursor,
4461
+ ) -> DataFrame:
4462
+ """Select all sub-tables information from `INFORMATION_SCHEMA`.
4463
+
4464
+ Available information options:
4465
+ - 'table_name', 'table_catalog', 'table_schema', 'table_type', 'engine', 'version',
4466
+ - 'row_format', 'table_rows', 'avg_row_length', 'data_length', 'max_data_length',
4467
+ - 'index_length', 'data_free', 'auto_increment', 'create_time', 'update_time',
4468
+ - 'check_time', 'table_collation', 'checksum', 'create_options', 'table_comment'
4469
+
4470
+ :param info: `<str>` The information to be selected.
4471
+ - If not specified, defaults to `'table_name'`.
4472
+ - Use `'*'` to select all information.
4473
+
4474
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4475
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4476
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4477
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4478
+
4479
+ :raise: Subclass of `QueryError`.
4480
+ :return `<DataFrame>`: All sub-tables information.
4481
+ """
4482
+ ...
4483
+
4484
+ @overload
4485
+ async def information(
4486
+ self,
4487
+ *info: Literal[
4488
+ "*",
4489
+ "table_name",
4490
+ "table_catalog",
4491
+ "table_schema",
4492
+ "table_type",
4493
+ "engine",
4494
+ "version",
4495
+ "row_format",
4496
+ "table_rows",
4497
+ "avg_row_length",
4498
+ "data_length",
4499
+ "max_data_length",
4500
+ "index_length",
4501
+ "data_free",
4502
+ "auto_increment",
4503
+ "create_time",
4504
+ "update_time",
4505
+ "check_time",
4506
+ "table_collation",
4507
+ "checksum",
4508
+ "create_options",
4509
+ "table_comment",
4510
+ ],
4511
+ cursor: type[Cursor | SSCursor] = DictCursor,
4512
+ ) -> tuple[tuple[Any]]:
4513
+ """Select all sub-tables information from `INFORMATION_SCHEMA`.
4514
+
4515
+ Available information options:
4516
+ - 'table_name', 'table_catalog', 'table_schema', 'table_type', 'engine', 'version',
4517
+ - 'row_format', 'table_rows', 'avg_row_length', 'data_length', 'max_data_length',
4518
+ - 'index_length', 'data_free', 'auto_increment', 'create_time', 'update_time',
4519
+ - 'check_time', 'table_collation', 'checksum', 'create_options', 'table_comment'
4520
+
4521
+ :param info: `<str>` The information to be selected.
4522
+ - If not specified, defaults to `'table_name'`.
4523
+ - Use `'*'` to select all information.
4524
+
4525
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4526
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4527
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4528
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4529
+
4530
+ :raise: Subclass of `QueryError`.
4531
+ :return `<tuple[tuple]>`: All sub-tables information.
4532
+ """
4533
+ ...
4534
+
3860
4535
  async def information(
3861
4536
  self,
3862
4537
  *info: Literal[
@@ -3886,7 +4561,7 @@ class TimeTable(Table):
3886
4561
  cursor: type[
3887
4562
  DictCursor | SSDictCursor | DfCursor | SSDfCursor | Cursor | SSCursor
3888
4563
  ] = DictCursor,
3889
- ) -> Union[tuple[dict | Any], DataFrame]:
4564
+ ) -> Union[tuple[dict[str, Any] | tuple[Any]], DataFrame]:
3890
4565
  """Select all sub-tables information from `INFORMATION_SCHEMA`.
3891
4566
 
3892
4567
  Available information options:
@@ -3901,11 +4576,11 @@ class TimeTable(Table):
3901
4576
 
3902
4577
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
3903
4578
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
3904
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
3905
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
4579
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4580
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
3906
4581
 
3907
4582
  :raise: Subclass of `QueryError`.
3908
- :return `<tuple/DataFrame>`: All sub-tables information. (depends on 'cursor' type).
4583
+ :return `<tuple/DataFrame>`: All sub-tables information (depends on 'cursor' type).
3909
4584
  """
3910
4585
  # Check info
3911
4586
  info_: str
@@ -3926,21 +4601,72 @@ class TimeTable(Table):
3926
4601
  )
3927
4602
  return await cur.fetchall()
3928
4603
 
4604
+ @overload
4605
+ async def describe(
4606
+ self,
4607
+ cursor: type[DictCursor | SSDictCursor] = DictCursor,
4608
+ ) -> tuple[dict[str, Any]]:
4609
+ """`DESCRIBE` a sub-table.
4610
+
4611
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4612
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4613
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4614
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4615
+
4616
+ :raise: Subclass of `QueryError`.
4617
+ :return `<tuple[dict]>`: Table description.
4618
+ """
4619
+ ...
4620
+
4621
+ @overload
4622
+ async def describe(
4623
+ self,
4624
+ cursor: type[DfCursor | SSDfCursor] = DictCursor,
4625
+ ) -> DataFrame:
4626
+ """`DESCRIBE` a sub-table.
4627
+
4628
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4629
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4630
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4631
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4632
+
4633
+ :raise: Subclass of `QueryError`.
4634
+ :return `<DataFrame>`: Table description.
4635
+ """
4636
+ ...
4637
+
4638
+ @overload
4639
+ async def describe(
4640
+ self,
4641
+ cursor: type[Cursor | SSCursor] = DictCursor,
4642
+ ) -> tuple[tuple[Any]]:
4643
+ """`DESCRIBE` a sub-table.
4644
+
4645
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4646
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4647
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4648
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4649
+
4650
+ :raise: Subclass of `QueryError`.
4651
+ :return `<tuple[tuple]>`: Table description.
4652
+ """
4653
+ ...
4654
+
3929
4655
  async def describe(
3930
4656
  self,
3931
4657
  cursor: type[
3932
4658
  DictCursor | SSDictCursor | DfCursor | SSDfCursor | Cursor | SSCursor
3933
4659
  ] = DictCursor,
3934
- ) -> Union[tuple[dict | Any], DataFrame]:
4660
+ ) -> Union[tuple[dict[str, Any] | tuple[Any]], DataFrame]:
3935
4661
  """`DESCRIBE` a sub-table.
3936
4662
 
3937
4663
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
3938
4664
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
3939
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
3940
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
4665
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4666
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
3941
4667
 
3942
4668
  :raise: Subclass of `QueryError`.
3943
- :return `<tuple/DataFrame>`: Table description. (depends on 'cursor' type).
4669
+ :return `<tuple/DataFrame>`: Table description (depends on 'cursor' type).
3944
4670
  """
3945
4671
  # Get one sub-table name
3946
4672
  name = await self._get_one_name()
@@ -4162,31 +4888,82 @@ class TimeTable(Table):
4162
4888
  if not names:
4163
4889
  return False
4164
4890
 
4165
- # Execute drop index query
4166
- res: list = await gather(
4167
- *[self._drop_index(name, index) for name in names],
4168
- return_exceptions=True,
4169
- )
4170
- for i in res:
4171
- if isinstance(i, Exception):
4172
- raise i
4173
- return True
4891
+ # Execute drop index query
4892
+ res: list = await gather(
4893
+ *[self._drop_index(name, index) for name in names],
4894
+ return_exceptions=True,
4895
+ )
4896
+ for i in res:
4897
+ if isinstance(i, Exception):
4898
+ raise i
4899
+ return True
4900
+
4901
+ @overload
4902
+ async def show_index(
4903
+ self,
4904
+ cursor: type[DictCursor | SSDictCursor] = DictCursor,
4905
+ ) -> tuple[dict[str, Any]]:
4906
+ """`SHOW INDEX` of the TimeTable.
4907
+
4908
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4909
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4910
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4911
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4912
+
4913
+ :raise: Subclass of `QueryError`.
4914
+ :return `<tuple[dict]>`: Index information.
4915
+ """
4916
+ ...
4917
+
4918
+ @overload
4919
+ async def show_index(
4920
+ self,
4921
+ cursor: type[DfCursor | SSDfCursor] = DictCursor,
4922
+ ) -> DataFrame:
4923
+ """`SHOW INDEX` of the TimeTable.
4924
+
4925
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4926
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4927
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4928
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4929
+
4930
+ :raise: Subclass of `QueryError`.
4931
+ :return `<DataFrame>`: Index information.
4932
+ """
4933
+ ...
4934
+
4935
+ @overload
4936
+ async def show_index(
4937
+ self,
4938
+ cursor: type[Cursor | SSCursor] = DictCursor,
4939
+ ) -> tuple[tuple[Any]]:
4940
+ """`SHOW INDEX` of the TimeTable.
4941
+
4942
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4943
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4944
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4945
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4946
+
4947
+ :raise: Subclass of `QueryError`.
4948
+ :return `<tuple[tuple]>`: Index information.
4949
+ """
4950
+ ...
4174
4951
 
4175
4952
  async def show_index(
4176
4953
  self,
4177
4954
  cursor: type[
4178
4955
  DictCursor | SSDictCursor | DfCursor | SSDfCursor | Cursor | SSCursor
4179
4956
  ] = DictCursor,
4180
- ) -> Union[tuple[dict | Any], DataFrame]:
4957
+ ) -> Union[tuple[dict[str, Any] | tuple[Any]], DataFrame]:
4181
4958
  """`SHOW INDEX` of the TimeTable.
4182
4959
 
4183
4960
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
4184
4961
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
4185
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
4186
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
4962
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
4963
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
4187
4964
 
4188
4965
  :raise: Subclass of `QueryError`.
4189
- :return `<tuple/DataFrame>`: Index information. (depends on 'cursor' type).
4966
+ :return `<tuple/DataFrame>`: Index information (depends on 'cursor' type).
4190
4967
  """
4191
4968
  # Get one sub-table name
4192
4969
  name = await self._get_one_name()
@@ -5687,6 +6464,189 @@ class Database:
5687
6464
  else:
5688
6465
  return await execute_by_temp(timeout)
5689
6466
 
6467
+ @overload
6468
+ async def fetch_query(
6469
+ self,
6470
+ stmt: str,
6471
+ args: Union[list, tuple, None] = None,
6472
+ conn: Union[Connection, None] = None,
6473
+ cursor: type[DictCursor | SSDictCursor] = DictCursor,
6474
+ timeout: Union[int, None] = None,
6475
+ warnings: bool = True,
6476
+ *,
6477
+ resolve_absent_table: bool = False,
6478
+ ) -> tuple[dict[str, Any]]:
6479
+ """Execute a SQL statement and fetch the result.
6480
+
6481
+ :param stmt: `<str>` The plain SQL statement to be executed.
6482
+ :param args: `<list/tuple>` Arguments for the `'%s'` placeholders in 'stmt'. Defaults to `None`.
6483
+ :param conn: `<Connection>` Specific connection to execute this query. Defaults to `None`.
6484
+ - If provided, the conn will be used to execute the SQL 'stmt'.
6485
+ This parameter is typically used within the `acquire()` or
6486
+ `transaction()` context.
6487
+ - If `None`, a temporary conn will be acquired from the Server pool
6488
+ to execute the `stmt`. After execution, the temporary conn will
6489
+ execute `COMMIT` and release back to the Server pool.
6490
+
6491
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
6492
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
6493
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
6494
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
6495
+
6496
+ :param timeout: `<int>` Query execution timeout in seconds. Dafaults to `None`.
6497
+ - If set to `None` or `0`, `tables.server.query_timeout` will be used
6498
+ as the default timeout.
6499
+ - `SQLQueryTimeoutError` will be raised when the timeout is reached.
6500
+
6501
+ :param warnings: `<bool>` Whether to issue any SQL related warnings. Defaults to `True`.
6502
+
6503
+ :param resolve_absent_table: `<bool>` Whether to resolve absent table. Defaults to `False`.
6504
+ - If `True`, when `stmt` involves a table that does not exist, an attempt
6505
+ will be made to create the missing table (if it belongs to the current
6506
+ database). If creation failed, an `SQLQueryProgrammingError` will be
6507
+ raised; otherwise, an `SQLQueryTableDontExistsError` will be raised.
6508
+ - If `False`, when `stmt` involves a table that does not exist, instead of
6509
+ raising an error, an empty `<tuple>` will be returned as the execution
6510
+ result.
6511
+
6512
+ :raises: Subclass of `QueryError`.
6513
+ :return `<tuple[dict]>`: The fetched result.
6514
+
6515
+ Example:
6516
+ >>> await db.fetch_query(
6517
+ "SELECT name, price FROM db.user WHERE id = %s",
6518
+ args=(1,), # does not support multi-rows arguments.
6519
+ conn=None,
6520
+ cursor=DictCursor,
6521
+ resolve_absent_table=False,
6522
+ timeout=10,
6523
+ warnings=True,
6524
+ )
6525
+ """
6526
+ ...
6527
+
6528
+ @overload
6529
+ async def fetch_query(
6530
+ self,
6531
+ stmt: str,
6532
+ args: Union[list, tuple, None] = None,
6533
+ conn: Union[Connection, None] = None,
6534
+ cursor: type[DfCursor | SSDfCursor] = DictCursor,
6535
+ timeout: Union[int, None] = None,
6536
+ warnings: bool = True,
6537
+ *,
6538
+ resolve_absent_table: bool = False,
6539
+ ) -> DataFrame:
6540
+ """Execute a SQL statement and fetch the result.
6541
+
6542
+ :param stmt: `<str>` The plain SQL statement to be executed.
6543
+ :param args: `<list/tuple>` Arguments for the `'%s'` placeholders in 'stmt'. Defaults to `None`.
6544
+ :param conn: `<Connection>` Specific connection to execute this query. Defaults to `None`.
6545
+ - If provided, the conn will be used to execute the SQL 'stmt'.
6546
+ This parameter is typically used within the `acquire()` or
6547
+ `transaction()` context.
6548
+ - If `None`, a temporary conn will be acquired from the Server pool
6549
+ to execute the `stmt`. After execution, the temporary conn will
6550
+ execute `COMMIT` and release back to the Server pool.
6551
+
6552
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
6553
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
6554
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
6555
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
6556
+
6557
+ :param timeout: `<int>` Query execution timeout in seconds. Dafaults to `None`.
6558
+ - If set to `None` or `0`, `tables.server.query_timeout` will be used
6559
+ as the default timeout.
6560
+ - `SQLQueryTimeoutError` will be raised when the timeout is reached.
6561
+
6562
+ :param warnings: `<bool>` Whether to issue any SQL related warnings. Defaults to `True`.
6563
+
6564
+ :param resolve_absent_table: `<bool>` Whether to resolve absent table. Defaults to `False`.
6565
+ - If `True`, when `stmt` involves a table that does not exist, an attempt
6566
+ will be made to create the missing table (if it belongs to the current
6567
+ database). If creation failed, an `SQLQueryProgrammingError` will be
6568
+ raised; otherwise, an `SQLQueryTableDontExistsError` will be raised.
6569
+ - If `False`, when `stmt` involves a table that does not exist, instead of
6570
+ raising an error, an empty `<DataFrame>` will be returned as the execution
6571
+ result.
6572
+
6573
+ :raises: Subclass of `QueryError`.
6574
+ :return `<DataFrame>`: The fetched result.
6575
+
6576
+ Example:
6577
+ >>> await db.fetch_query(
6578
+ "SELECT name, price FROM db.user WHERE id = %s",
6579
+ args=(1,), # does not support multi-rows arguments.
6580
+ conn=None,
6581
+ cursor=DictCursor,
6582
+ resolve_absent_table=False,
6583
+ timeout=10,
6584
+ warnings=True,
6585
+ )
6586
+ """
6587
+ ...
6588
+
6589
+ @overload
6590
+ async def fetch_query(
6591
+ self,
6592
+ stmt: str,
6593
+ args: Union[list, tuple, None] = None,
6594
+ conn: Union[Connection, None] = None,
6595
+ cursor: type[Cursor | SSCursor] = DictCursor,
6596
+ timeout: Union[int, None] = None,
6597
+ warnings: bool = True,
6598
+ *,
6599
+ resolve_absent_table: bool = False,
6600
+ ) -> tuple[tuple[Any]]:
6601
+ """Execute a SQL statement and fetch the result.
6602
+
6603
+ :param stmt: `<str>` The plain SQL statement to be executed.
6604
+ :param args: `<list/tuple>` Arguments for the `'%s'` placeholders in 'stmt'. Defaults to `None`.
6605
+ :param conn: `<Connection>` Specific connection to execute this query. Defaults to `None`.
6606
+ - If provided, the conn will be used to execute the SQL 'stmt'.
6607
+ This parameter is typically used within the `acquire()` or
6608
+ `transaction()` context.
6609
+ - If `None`, a temporary conn will be acquired from the Server pool
6610
+ to execute the `stmt`. After execution, the temporary conn will
6611
+ execute `COMMIT` and release back to the Server pool.
6612
+
6613
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
6614
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
6615
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
6616
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
6617
+
6618
+ :param timeout: `<int>` Query execution timeout in seconds. Dafaults to `None`.
6619
+ - If set to `None` or `0`, `tables.server.query_timeout` will be used
6620
+ as the default timeout.
6621
+ - `SQLQueryTimeoutError` will be raised when the timeout is reached.
6622
+
6623
+ :param warnings: `<bool>` Whether to issue any SQL related warnings. Defaults to `True`.
6624
+
6625
+ :param resolve_absent_table: `<bool>` Whether to resolve absent table. Defaults to `False`.
6626
+ - If `True`, when `stmt` involves a table that does not exist, an attempt
6627
+ will be made to create the missing table (if it belongs to the current
6628
+ database). If creation failed, an `SQLQueryProgrammingError` will be
6629
+ raised; otherwise, an `SQLQueryTableDontExistsError` will be raised.
6630
+ - If `False`, when `stmt` involves a table that does not exist, instead of
6631
+ raising an error, an empty `tuple[tuple]` will be returned as the execution
6632
+ result.
6633
+
6634
+ :raises: Subclass of `QueryError`.
6635
+ :return `<tuple[tuple]>`: The fetched result.
6636
+
6637
+ Example:
6638
+ >>> await db.fetch_query(
6639
+ "SELECT name, price FROM db.user WHERE id = %s",
6640
+ args=(1,), # does not support multi-rows arguments.
6641
+ conn=None,
6642
+ cursor=DictCursor,
6643
+ resolve_absent_table=False,
6644
+ timeout=10,
6645
+ warnings=True,
6646
+ )
6647
+ """
6648
+ ...
6649
+
5690
6650
  async def fetch_query(
5691
6651
  self,
5692
6652
  stmt: str,
@@ -5699,7 +6659,7 @@ class Database:
5699
6659
  warnings: bool = True,
5700
6660
  *,
5701
6661
  resolve_absent_table: bool = False,
5702
- ) -> Union[tuple[dict | Any], DataFrame]:
6662
+ ) -> Union[tuple[dict[str, Any] | tuple[Any]], DataFrame]:
5703
6663
  """Execute a SQL statement and fetch the result.
5704
6664
 
5705
6665
  :param stmt: `<str>` The plain SQL statement to be executed.
@@ -5714,8 +6674,8 @@ class Database:
5714
6674
 
5715
6675
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
5716
6676
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
5717
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
5718
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
6677
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
6678
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
5719
6679
 
5720
6680
  :param timeout: `<int>` Query execution timeout in seconds. Dafaults to `None`.
5721
6681
  - If set to `None` or `0`, `tables.server.query_timeout` will be used
@@ -6006,6 +6966,108 @@ class Database:
6006
6966
  # Check existance
6007
6967
  return True if fetch and fetch[0] > 0 else False
6008
6968
 
6969
+ @overload
6970
+ async def information(
6971
+ self,
6972
+ *info: Literal[
6973
+ "*",
6974
+ "catelog_name",
6975
+ "schema_name",
6976
+ "default_character_set_name",
6977
+ "default_collation_name",
6978
+ "sql_path",
6979
+ "default_encryption",
6980
+ ],
6981
+ cursor: type[DictCursor | SSDictCursor] = DictCursor,
6982
+ ) -> tuple[dict[str, Any]]:
6983
+ """Select database information from `INFORMATION_SCHEMA`.
6984
+
6985
+ Available information options:
6986
+ - 'catelog_name', 'schema_name', 'default_character_set_name',
6987
+ - 'default_collation_name', 'sql_path', 'default_encryption'
6988
+
6989
+ :param info: `<str>` The information to be selected.
6990
+ - If not specified, defaults to `'schema_name'`.
6991
+ - Use `'*'` to select all information.
6992
+
6993
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
6994
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
6995
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
6996
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
6997
+
6998
+ :raise: Subclass of `QueryError`.
6999
+ :return `<tuple[dict]>`: Database information.
7000
+ """
7001
+ ...
7002
+
7003
+ @overload
7004
+ async def information(
7005
+ self,
7006
+ *info: Literal[
7007
+ "*",
7008
+ "catelog_name",
7009
+ "schema_name",
7010
+ "default_character_set_name",
7011
+ "default_collation_name",
7012
+ "sql_path",
7013
+ "default_encryption",
7014
+ ],
7015
+ cursor: type[DfCursor | SSDfCursor] = DictCursor,
7016
+ ) -> DataFrame:
7017
+ """Select database information from `INFORMATION_SCHEMA`.
7018
+
7019
+ Available information options:
7020
+ - 'catelog_name', 'schema_name', 'default_character_set_name',
7021
+ - 'default_collation_name', 'sql_path', 'default_encryption'
7022
+
7023
+ :param info: `<str>` The information to be selected.
7024
+ - If not specified, defaults to `'schema_name'`.
7025
+ - Use `'*'` to select all information.
7026
+
7027
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
7028
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
7029
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
7030
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
7031
+
7032
+ :raise: Subclass of `QueryError`.
7033
+ :return `<DataFrame>`: Database information.
7034
+ """
7035
+ ...
7036
+
7037
+ @overload
7038
+ async def information(
7039
+ self,
7040
+ *info: Literal[
7041
+ "*",
7042
+ "catelog_name",
7043
+ "schema_name",
7044
+ "default_character_set_name",
7045
+ "default_collation_name",
7046
+ "sql_path",
7047
+ "default_encryption",
7048
+ ],
7049
+ cursor: type[Cursor | SSCursor] = DictCursor,
7050
+ ) -> tuple[tuple[Any]]:
7051
+ """Select database information from `INFORMATION_SCHEMA`.
7052
+
7053
+ Available information options:
7054
+ - 'catelog_name', 'schema_name', 'default_character_set_name',
7055
+ - 'default_collation_name', 'sql_path', 'default_encryption'
7056
+
7057
+ :param info: `<str>` The information to be selected.
7058
+ - If not specified, defaults to `'schema_name'`.
7059
+ - Use `'*'` to select all information.
7060
+
7061
+ :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
7062
+ - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
7063
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
7064
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
7065
+
7066
+ :raise: Subclass of `QueryError`.
7067
+ :return `<tuple[tuple]>`: Database information.
7068
+ """
7069
+ ...
7070
+
6009
7071
  async def information(
6010
7072
  self,
6011
7073
  *info: Literal[
@@ -6020,7 +7082,7 @@ class Database:
6020
7082
  cursor: type[
6021
7083
  DictCursor | SSDictCursor | DfCursor | SSDfCursor | Cursor | SSCursor
6022
7084
  ] = DictCursor,
6023
- ) -> Union[tuple[dict | Any], DataFrame]:
7085
+ ) -> Union[tuple[dict[str, Any] | tuple[Any]], DataFrame]:
6024
7086
  """Select database information from `INFORMATION_SCHEMA`.
6025
7087
 
6026
7088
  Available information options:
@@ -6033,11 +7095,11 @@ class Database:
6033
7095
 
6034
7096
  :param cursor: `<type[Cursor]>` The `Cursor` class to use for query execution. Defaults to `DictCursor`.
6035
7097
  - `DictCursor/SSDictCursor`: Fetch result as `<tuple[dict]>`.
6036
- - `DfCursor/SSDfCursor`: Fetch result as `pandas.DataFrame`.
6037
- - `Cursor/SSCursor`: Fetch result as `<tuple[Any]>` (without column names).
7098
+ - `DfCursor/SSDfCursor`: Fetch result as `<pandas.DataFrame>`.
7099
+ - `Cursor/SSCursor`: Fetch result as `<tuple[tuple]>` (without column names).
6038
7100
 
6039
7101
  :raise: Subclass of `QueryError`.
6040
- :return `<tuple/DataFrame>`: Database information. (depends on 'cursor' type).
7102
+ :return `<tuple/DataFrame>`: Database information.
6041
7103
  """
6042
7104
  # Check info
6043
7105
  info_: str