singlestoredb 1.16.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- singlestoredb/__init__.py +75 -0
- singlestoredb/ai/__init__.py +2 -0
- singlestoredb/ai/chat.py +139 -0
- singlestoredb/ai/embeddings.py +128 -0
- singlestoredb/alchemy/__init__.py +90 -0
- singlestoredb/apps/__init__.py +3 -0
- singlestoredb/apps/_cloud_functions.py +90 -0
- singlestoredb/apps/_config.py +72 -0
- singlestoredb/apps/_connection_info.py +18 -0
- singlestoredb/apps/_dashboards.py +47 -0
- singlestoredb/apps/_process.py +32 -0
- singlestoredb/apps/_python_udfs.py +100 -0
- singlestoredb/apps/_stdout_supress.py +30 -0
- singlestoredb/apps/_uvicorn_util.py +36 -0
- singlestoredb/auth.py +245 -0
- singlestoredb/config.py +484 -0
- singlestoredb/connection.py +1487 -0
- singlestoredb/converters.py +950 -0
- singlestoredb/docstring/__init__.py +33 -0
- singlestoredb/docstring/attrdoc.py +126 -0
- singlestoredb/docstring/common.py +230 -0
- singlestoredb/docstring/epydoc.py +267 -0
- singlestoredb/docstring/google.py +412 -0
- singlestoredb/docstring/numpydoc.py +562 -0
- singlestoredb/docstring/parser.py +100 -0
- singlestoredb/docstring/py.typed +1 -0
- singlestoredb/docstring/rest.py +256 -0
- singlestoredb/docstring/tests/__init__.py +1 -0
- singlestoredb/docstring/tests/_pydoctor.py +21 -0
- singlestoredb/docstring/tests/test_epydoc.py +729 -0
- singlestoredb/docstring/tests/test_google.py +1007 -0
- singlestoredb/docstring/tests/test_numpydoc.py +1100 -0
- singlestoredb/docstring/tests/test_parse_from_object.py +109 -0
- singlestoredb/docstring/tests/test_parser.py +248 -0
- singlestoredb/docstring/tests/test_rest.py +547 -0
- singlestoredb/docstring/tests/test_util.py +70 -0
- singlestoredb/docstring/util.py +141 -0
- singlestoredb/exceptions.py +120 -0
- singlestoredb/functions/__init__.py +16 -0
- singlestoredb/functions/decorator.py +201 -0
- singlestoredb/functions/dtypes.py +1793 -0
- singlestoredb/functions/ext/__init__.py +1 -0
- singlestoredb/functions/ext/arrow.py +375 -0
- singlestoredb/functions/ext/asgi.py +2133 -0
- singlestoredb/functions/ext/json.py +420 -0
- singlestoredb/functions/ext/mmap.py +413 -0
- singlestoredb/functions/ext/rowdat_1.py +724 -0
- singlestoredb/functions/ext/timer.py +89 -0
- singlestoredb/functions/ext/utils.py +218 -0
- singlestoredb/functions/signature.py +1578 -0
- singlestoredb/functions/typing/__init__.py +41 -0
- singlestoredb/functions/typing/numpy.py +20 -0
- singlestoredb/functions/typing/pandas.py +2 -0
- singlestoredb/functions/typing/polars.py +2 -0
- singlestoredb/functions/typing/pyarrow.py +2 -0
- singlestoredb/functions/utils.py +421 -0
- singlestoredb/fusion/__init__.py +11 -0
- singlestoredb/fusion/graphql.py +213 -0
- singlestoredb/fusion/handler.py +916 -0
- singlestoredb/fusion/handlers/__init__.py +0 -0
- singlestoredb/fusion/handlers/export.py +525 -0
- singlestoredb/fusion/handlers/files.py +690 -0
- singlestoredb/fusion/handlers/job.py +660 -0
- singlestoredb/fusion/handlers/models.py +250 -0
- singlestoredb/fusion/handlers/stage.py +502 -0
- singlestoredb/fusion/handlers/utils.py +324 -0
- singlestoredb/fusion/handlers/workspace.py +956 -0
- singlestoredb/fusion/registry.py +249 -0
- singlestoredb/fusion/result.py +399 -0
- singlestoredb/http/__init__.py +27 -0
- singlestoredb/http/connection.py +1267 -0
- singlestoredb/magics/__init__.py +34 -0
- singlestoredb/magics/run_personal.py +137 -0
- singlestoredb/magics/run_shared.py +134 -0
- singlestoredb/management/__init__.py +9 -0
- singlestoredb/management/billing_usage.py +148 -0
- singlestoredb/management/cluster.py +462 -0
- singlestoredb/management/export.py +295 -0
- singlestoredb/management/files.py +1102 -0
- singlestoredb/management/inference_api.py +105 -0
- singlestoredb/management/job.py +887 -0
- singlestoredb/management/manager.py +373 -0
- singlestoredb/management/organization.py +226 -0
- singlestoredb/management/region.py +169 -0
- singlestoredb/management/utils.py +423 -0
- singlestoredb/management/workspace.py +1927 -0
- singlestoredb/mysql/__init__.py +177 -0
- singlestoredb/mysql/_auth.py +298 -0
- singlestoredb/mysql/charset.py +214 -0
- singlestoredb/mysql/connection.py +2032 -0
- singlestoredb/mysql/constants/CLIENT.py +38 -0
- singlestoredb/mysql/constants/COMMAND.py +32 -0
- singlestoredb/mysql/constants/CR.py +78 -0
- singlestoredb/mysql/constants/ER.py +474 -0
- singlestoredb/mysql/constants/EXTENDED_TYPE.py +3 -0
- singlestoredb/mysql/constants/FIELD_TYPE.py +48 -0
- singlestoredb/mysql/constants/FLAG.py +15 -0
- singlestoredb/mysql/constants/SERVER_STATUS.py +10 -0
- singlestoredb/mysql/constants/VECTOR_TYPE.py +6 -0
- singlestoredb/mysql/constants/__init__.py +0 -0
- singlestoredb/mysql/converters.py +271 -0
- singlestoredb/mysql/cursors.py +896 -0
- singlestoredb/mysql/err.py +92 -0
- singlestoredb/mysql/optionfile.py +20 -0
- singlestoredb/mysql/protocol.py +450 -0
- singlestoredb/mysql/tests/__init__.py +19 -0
- singlestoredb/mysql/tests/base.py +126 -0
- singlestoredb/mysql/tests/conftest.py +37 -0
- singlestoredb/mysql/tests/test_DictCursor.py +132 -0
- singlestoredb/mysql/tests/test_SSCursor.py +141 -0
- singlestoredb/mysql/tests/test_basic.py +452 -0
- singlestoredb/mysql/tests/test_connection.py +851 -0
- singlestoredb/mysql/tests/test_converters.py +58 -0
- singlestoredb/mysql/tests/test_cursor.py +141 -0
- singlestoredb/mysql/tests/test_err.py +16 -0
- singlestoredb/mysql/tests/test_issues.py +514 -0
- singlestoredb/mysql/tests/test_load_local.py +75 -0
- singlestoredb/mysql/tests/test_nextset.py +88 -0
- singlestoredb/mysql/tests/test_optionfile.py +27 -0
- singlestoredb/mysql/tests/thirdparty/__init__.py +6 -0
- singlestoredb/mysql/tests/thirdparty/test_MySQLdb/__init__.py +9 -0
- singlestoredb/mysql/tests/thirdparty/test_MySQLdb/capabilities.py +323 -0
- singlestoredb/mysql/tests/thirdparty/test_MySQLdb/dbapi20.py +865 -0
- singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py +110 -0
- singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_dbapi20.py +224 -0
- singlestoredb/mysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py +101 -0
- singlestoredb/mysql/times.py +23 -0
- singlestoredb/notebook/__init__.py +16 -0
- singlestoredb/notebook/_objects.py +213 -0
- singlestoredb/notebook/_portal.py +352 -0
- singlestoredb/py.typed +0 -0
- singlestoredb/pytest.py +352 -0
- singlestoredb/server/__init__.py +0 -0
- singlestoredb/server/docker.py +452 -0
- singlestoredb/server/free_tier.py +267 -0
- singlestoredb/tests/__init__.py +0 -0
- singlestoredb/tests/alltypes.sql +307 -0
- singlestoredb/tests/alltypes_no_nulls.sql +208 -0
- singlestoredb/tests/empty.sql +0 -0
- singlestoredb/tests/ext_funcs/__init__.py +702 -0
- singlestoredb/tests/local_infile.csv +3 -0
- singlestoredb/tests/test.ipynb +18 -0
- singlestoredb/tests/test.sql +680 -0
- singlestoredb/tests/test2.ipynb +18 -0
- singlestoredb/tests/test2.sql +1 -0
- singlestoredb/tests/test_basics.py +1332 -0
- singlestoredb/tests/test_config.py +318 -0
- singlestoredb/tests/test_connection.py +3103 -0
- singlestoredb/tests/test_dbapi.py +27 -0
- singlestoredb/tests/test_exceptions.py +45 -0
- singlestoredb/tests/test_ext_func.py +1472 -0
- singlestoredb/tests/test_ext_func_data.py +1101 -0
- singlestoredb/tests/test_fusion.py +1527 -0
- singlestoredb/tests/test_http.py +288 -0
- singlestoredb/tests/test_management.py +1599 -0
- singlestoredb/tests/test_plugin.py +33 -0
- singlestoredb/tests/test_results.py +171 -0
- singlestoredb/tests/test_types.py +132 -0
- singlestoredb/tests/test_udf.py +737 -0
- singlestoredb/tests/test_udf_returns.py +459 -0
- singlestoredb/tests/test_vectorstore.py +51 -0
- singlestoredb/tests/test_xdict.py +333 -0
- singlestoredb/tests/utils.py +141 -0
- singlestoredb/types.py +373 -0
- singlestoredb/utils/__init__.py +0 -0
- singlestoredb/utils/config.py +950 -0
- singlestoredb/utils/convert_rows.py +69 -0
- singlestoredb/utils/debug.py +13 -0
- singlestoredb/utils/dtypes.py +205 -0
- singlestoredb/utils/events.py +65 -0
- singlestoredb/utils/mogrify.py +151 -0
- singlestoredb/utils/results.py +585 -0
- singlestoredb/utils/xdict.py +425 -0
- singlestoredb/vectorstore.py +192 -0
- singlestoredb/warnings.py +5 -0
- singlestoredb-1.16.1.dist-info/METADATA +165 -0
- singlestoredb-1.16.1.dist-info/RECORD +183 -0
- singlestoredb-1.16.1.dist-info/WHEEL +5 -0
- singlestoredb-1.16.1.dist-info/entry_points.txt +2 -0
- singlestoredb-1.16.1.dist-info/licenses/LICENSE +201 -0
- singlestoredb-1.16.1.dist-info/top_level.txt +3 -0
- sqlx/__init__.py +4 -0
- sqlx/magic.py +113 -0
singlestoredb/types.py
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
"""SingleStoreDB data type utilities."""
|
|
3
|
+
import datetime
|
|
4
|
+
import decimal
|
|
5
|
+
import time
|
|
6
|
+
from typing import Dict
|
|
7
|
+
from typing import List
|
|
8
|
+
from typing import Set
|
|
9
|
+
from typing import Union
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Date = datetime.date
|
|
13
|
+
Time = datetime.time
|
|
14
|
+
Timestamp = datetime.datetime
|
|
15
|
+
Binary = bytes
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def DateFromTicks(ticks: int) -> Date:
|
|
19
|
+
"""
|
|
20
|
+
Convert ticks to a date object.
|
|
21
|
+
|
|
22
|
+
Parameters
|
|
23
|
+
----------
|
|
24
|
+
ticks : int
|
|
25
|
+
Number of seconds since the epoch
|
|
26
|
+
|
|
27
|
+
Returns
|
|
28
|
+
-------
|
|
29
|
+
Date
|
|
30
|
+
|
|
31
|
+
"""
|
|
32
|
+
return Date(*time.localtime(ticks)[:3])
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def TimeFromTicks(ticks: int) -> Time:
|
|
36
|
+
"""
|
|
37
|
+
Convert ticks to a time object.
|
|
38
|
+
|
|
39
|
+
Parameters
|
|
40
|
+
----------
|
|
41
|
+
ticks : int
|
|
42
|
+
Number of seconds since the epoch
|
|
43
|
+
|
|
44
|
+
Returns
|
|
45
|
+
-------
|
|
46
|
+
Time
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
return Time(*time.localtime(ticks)[3:6])
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def TimestampFromTicks(ticks: int) -> Timestamp:
|
|
53
|
+
"""
|
|
54
|
+
Convert ticks to a datetime object.
|
|
55
|
+
|
|
56
|
+
Parameters
|
|
57
|
+
----------
|
|
58
|
+
ticks : int
|
|
59
|
+
Number of seconds since the epoch
|
|
60
|
+
|
|
61
|
+
Returns
|
|
62
|
+
-------
|
|
63
|
+
Timestamp
|
|
64
|
+
|
|
65
|
+
"""
|
|
66
|
+
return Timestamp(*time.localtime(ticks)[:6])
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class DBAPIType(object):
|
|
70
|
+
"""
|
|
71
|
+
Base class for DB-API data types.
|
|
72
|
+
|
|
73
|
+
Parameters
|
|
74
|
+
----------
|
|
75
|
+
*values : int or str, optional
|
|
76
|
+
Names and codes of data types
|
|
77
|
+
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
def __init__(self, *values: Union[int, str, type, 'DBAPIType']):
|
|
81
|
+
self.values: Set[Union[int, str, type]] = set()
|
|
82
|
+
name: str = ''
|
|
83
|
+
code: int = -1
|
|
84
|
+
for item in values:
|
|
85
|
+
if isinstance(item, DBAPIType):
|
|
86
|
+
self.values.update(item.values)
|
|
87
|
+
if not name:
|
|
88
|
+
for item in item.values:
|
|
89
|
+
if not name and isinstance(item, str):
|
|
90
|
+
name = item
|
|
91
|
+
if code == -1 and isinstance(item, int):
|
|
92
|
+
code = item
|
|
93
|
+
else:
|
|
94
|
+
self.values.add(item)
|
|
95
|
+
if not name and isinstance(item, str):
|
|
96
|
+
name = item
|
|
97
|
+
if code == -1 and isinstance(item, int):
|
|
98
|
+
code = item
|
|
99
|
+
self.name = name or '<unknown>'
|
|
100
|
+
self.code = code
|
|
101
|
+
|
|
102
|
+
def __eq__(self, other: object) -> bool:
|
|
103
|
+
"""
|
|
104
|
+
Determine if `other` object is equivalent.
|
|
105
|
+
|
|
106
|
+
Parameters
|
|
107
|
+
----------
|
|
108
|
+
other : int or str or DBIAPIType
|
|
109
|
+
Object to compare to
|
|
110
|
+
|
|
111
|
+
Returns
|
|
112
|
+
-------
|
|
113
|
+
bool
|
|
114
|
+
|
|
115
|
+
"""
|
|
116
|
+
if isinstance(other, DBAPIType):
|
|
117
|
+
if other.values.intersection(self.values):
|
|
118
|
+
return True
|
|
119
|
+
elif other in self.values:
|
|
120
|
+
return True
|
|
121
|
+
return False
|
|
122
|
+
|
|
123
|
+
def __ne__(self, other: object) -> bool:
|
|
124
|
+
"""
|
|
125
|
+
Determine if `other` object is not equivalent.
|
|
126
|
+
|
|
127
|
+
Parameters
|
|
128
|
+
----------
|
|
129
|
+
other : int or str or DBIAPIType
|
|
130
|
+
Object to compare to
|
|
131
|
+
|
|
132
|
+
Returns
|
|
133
|
+
-------
|
|
134
|
+
bool
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
return not (self.__eq__(other))
|
|
138
|
+
|
|
139
|
+
def __str__(self) -> str:
|
|
140
|
+
"""Return string representation."""
|
|
141
|
+
return '<{} object [{}]>'.format(
|
|
142
|
+
type(self).__name__,
|
|
143
|
+
', '.join(sorted(str(x) for x in self.values)),
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def __repr__(self) -> str:
|
|
147
|
+
"""Return string representation."""
|
|
148
|
+
return str(self)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
class StringDBAPIType(DBAPIType):
|
|
152
|
+
"""STRING DB-API types."""
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class BinaryDBAPIType(DBAPIType):
|
|
156
|
+
"""BINARY DB-API types."""
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class NumberDBAPIType(DBAPIType):
|
|
160
|
+
"""NUMBER DB-API types."""
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
class DatetimeDBAPIType(DBAPIType):
|
|
164
|
+
"""DATETIME DB-API types."""
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class ColumnType(object):
|
|
168
|
+
"""Column types and utilities."""
|
|
169
|
+
|
|
170
|
+
# Note that the first name given will be the name returned by
|
|
171
|
+
# the `get_name` method.
|
|
172
|
+
DECIMAL = NumberDBAPIType(
|
|
173
|
+
'DECIMAL', 'DEC', 'FIXED', 'NUMERIC', 0, decimal.Decimal,
|
|
174
|
+
)
|
|
175
|
+
DEC = FIXED = NUMERIC = DECIMAL
|
|
176
|
+
TINY = TINYINT = BOOL = BOOLEAN = UNSIGNED_TINY = UNSIGNED_TINYINT = NumberDBAPIType(
|
|
177
|
+
'TINY', 'TINYINT', 'BOOL', 'BOOLEAN', 'UNSIGNED TINY', 'UNSIGNED TINYINT', 1,
|
|
178
|
+
)
|
|
179
|
+
SHORT = SMALLINT = UNSIGNED_SHORT = UNSIGNED_SMALLINT = NumberDBAPIType(
|
|
180
|
+
'SMALLINT', 'SHORT', 'UNSIGNED SHORT', 'UNSIGNED SMALLINT', 2,
|
|
181
|
+
)
|
|
182
|
+
LONG = INT = UNSIGNED_LONG = UNSIGNED_INT = NumberDBAPIType(
|
|
183
|
+
'LONG', 'INT', 'UNSIGNED LONG', 'UNSIGNED INT', 3,
|
|
184
|
+
)
|
|
185
|
+
FLOAT = NumberDBAPIType('FLOAT', 4)
|
|
186
|
+
DOUBLE = REAL = NumberDBAPIType('DOUBLE', 5, float)
|
|
187
|
+
NULL = DBAPIType('NULL', 6)
|
|
188
|
+
TIMESTAMP = DatetimeDBAPIType('TIMESTAMP', 7)
|
|
189
|
+
LONGLONG = BIGINT = UNSIGNED_LONGLONG = UNSIGNED_BIGINT = NumberDBAPIType(
|
|
190
|
+
'BIGINT', 'LONGLONG', 'UNSIGNED LONGLONG', 'UNSIGNED BIGINT', 8, int,
|
|
191
|
+
)
|
|
192
|
+
MEDIUMINT = INT24 = UNSIGNED_MEDIUMINT = UNSIGNED_INT24 = NumberDBAPIType(
|
|
193
|
+
'MEDIUMINT', 'INT24', 'UNSIGNED MEDIUMINT', 'UNSIGNED INT24', 9,
|
|
194
|
+
)
|
|
195
|
+
DATE = DBAPIType('DATE', 10, datetime.date)
|
|
196
|
+
TIME = DBAPIType('TIME', 11, datetime.time)
|
|
197
|
+
DATETIME = DatetimeDBAPIType('DATETIME', 12, datetime.datetime)
|
|
198
|
+
YEAR = DBAPIType('YEAR', 13)
|
|
199
|
+
NEWDATE = DBAPIType('NEWDATE', 14)
|
|
200
|
+
VARCHAR = StringDBAPIType('VARCHAR', 15, str)
|
|
201
|
+
VARBINARY = BinaryDBAPIType('VARBINARY', 15, bytearray, bytes)
|
|
202
|
+
BIT = NumberDBAPIType('BIT', 16)
|
|
203
|
+
JSON = DBAPIType('JSON', 245)
|
|
204
|
+
NEWDECIMAL = NumberDBAPIType('NEWDECIMAL', 246)
|
|
205
|
+
ENUM = StringDBAPIType('ENUM', 247)
|
|
206
|
+
SET = StringDBAPIType('SET', 248)
|
|
207
|
+
TINYBLOB = BinaryDBAPIType('TINYBLOB', 249)
|
|
208
|
+
TINYTEXT = StringDBAPIType('TINYTEXT', 249)
|
|
209
|
+
MEDIUMBLOB = BinaryDBAPIType('MEDIUMBLOB', 250)
|
|
210
|
+
MEDIUMTEXT = StringDBAPIType('MEDIUMTEXT', 250)
|
|
211
|
+
LONGBLOB = BinaryDBAPIType('LONGBLOB', 251)
|
|
212
|
+
LONGTEXT = StringDBAPIType('LONGTEXT', 251)
|
|
213
|
+
BLOB = BinaryDBAPIType('BLOB', 252)
|
|
214
|
+
TEXT = StringDBAPIType('TEXT', 252)
|
|
215
|
+
VARSTRING = StringDBAPIType('VARSTRING', 253)
|
|
216
|
+
BINARY = BinaryDBAPIType('BINARY', 254)
|
|
217
|
+
STRING = CHAR = StringDBAPIType('STRING', 'CHAR', 254)
|
|
218
|
+
GEOMETRY = DBAPIType('GEOMETRY', 255)
|
|
219
|
+
|
|
220
|
+
# Codes that map to multiple names must have a default specified
|
|
221
|
+
_default_name: Dict[int, str] = {
|
|
222
|
+
15: 'VARBINARY',
|
|
223
|
+
249: 'TINYBLOB',
|
|
224
|
+
250: 'MEDIUMBLOB',
|
|
225
|
+
251: 'LONGBLOB',
|
|
226
|
+
252: 'BLOB',
|
|
227
|
+
254: 'BINARY',
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
# Map of type name to type code
|
|
231
|
+
_type_name_map: Dict[str, int] = {}
|
|
232
|
+
|
|
233
|
+
# Map of type code to all type names
|
|
234
|
+
_type_code_map: Dict[int, str] = {}
|
|
235
|
+
|
|
236
|
+
# Map of Python type to type code
|
|
237
|
+
_type_type_map: Dict[type, int] = {}
|
|
238
|
+
|
|
239
|
+
@classmethod
|
|
240
|
+
def get_code(cls, name: str) -> int:
|
|
241
|
+
"""
|
|
242
|
+
Return the numeric database type code corresponding to `name`.
|
|
243
|
+
|
|
244
|
+
If `name` is given as an int, it is immediately returned.
|
|
245
|
+
|
|
246
|
+
Parameters
|
|
247
|
+
----------
|
|
248
|
+
name : str
|
|
249
|
+
Name of the database type
|
|
250
|
+
|
|
251
|
+
Returns
|
|
252
|
+
-------
|
|
253
|
+
int
|
|
254
|
+
|
|
255
|
+
"""
|
|
256
|
+
if isinstance(name, int):
|
|
257
|
+
return name
|
|
258
|
+
if not cls._type_name_map:
|
|
259
|
+
cls._update_type_maps()
|
|
260
|
+
if isinstance(name, type):
|
|
261
|
+
return cls._type_type_map[name]
|
|
262
|
+
return cls._type_name_map[name.upper()]
|
|
263
|
+
|
|
264
|
+
@classmethod
|
|
265
|
+
def get_name(cls, code: int) -> str:
|
|
266
|
+
"""
|
|
267
|
+
Return the database type name corresponding to integer value `code`.
|
|
268
|
+
|
|
269
|
+
If `code` is given as a string, it is immediately returned.
|
|
270
|
+
|
|
271
|
+
Parameters
|
|
272
|
+
----------
|
|
273
|
+
code : int
|
|
274
|
+
Integer code value of the database type
|
|
275
|
+
|
|
276
|
+
Returns
|
|
277
|
+
-------
|
|
278
|
+
str
|
|
279
|
+
|
|
280
|
+
"""
|
|
281
|
+
if not cls._type_code_map:
|
|
282
|
+
cls._update_type_maps()
|
|
283
|
+
if isinstance(code, str):
|
|
284
|
+
code = cls._type_name_map[code.upper()]
|
|
285
|
+
elif isinstance(code, type):
|
|
286
|
+
code = cls._type_type_map[code]
|
|
287
|
+
return cls._type_code_map[code]
|
|
288
|
+
|
|
289
|
+
@classmethod
|
|
290
|
+
def _update_type_maps(cls) -> None:
|
|
291
|
+
"""Update the type code and name maps."""
|
|
292
|
+
for k, v in vars(cls).items():
|
|
293
|
+
if not isinstance(v, DBAPIType):
|
|
294
|
+
continue
|
|
295
|
+
default_name = v.name
|
|
296
|
+
names = [x.upper() for x in v.values if isinstance(x, str)]
|
|
297
|
+
codes = [x for x in v.values if isinstance(x, int)]
|
|
298
|
+
types = [x for x in v.values if isinstance(x, type)]
|
|
299
|
+
for code in codes:
|
|
300
|
+
for name in names:
|
|
301
|
+
cls._type_name_map[name] = code
|
|
302
|
+
cls._type_code_map[code] = cls._default_name.get(code, default_name)
|
|
303
|
+
for typ in types:
|
|
304
|
+
cls._type_type_map[typ] = code
|
|
305
|
+
|
|
306
|
+
@classmethod
|
|
307
|
+
def get_string_types(cls) -> List[DBAPIType]:
|
|
308
|
+
"""
|
|
309
|
+
Return all database types that correspond to DB-API strings.
|
|
310
|
+
|
|
311
|
+
Returns
|
|
312
|
+
-------
|
|
313
|
+
list of StringDBAPIType instances
|
|
314
|
+
|
|
315
|
+
"""
|
|
316
|
+
return [v for k, v in vars(cls).items() if type(v) is StringDBAPIType]
|
|
317
|
+
|
|
318
|
+
@classmethod
|
|
319
|
+
def get_binary_types(cls) -> List[DBAPIType]:
|
|
320
|
+
"""
|
|
321
|
+
Return all database types that correspond to DB-API binary objects.
|
|
322
|
+
|
|
323
|
+
Returns
|
|
324
|
+
-------
|
|
325
|
+
list of BinaryDBAPIType instances
|
|
326
|
+
|
|
327
|
+
"""
|
|
328
|
+
return [v for k, v in vars(cls).items() if type(v) is BinaryDBAPIType]
|
|
329
|
+
|
|
330
|
+
@classmethod
|
|
331
|
+
def get_number_types(cls) -> List[DBAPIType]:
|
|
332
|
+
"""
|
|
333
|
+
Return all database types that correspond to DB-API number objects.
|
|
334
|
+
|
|
335
|
+
Returns
|
|
336
|
+
-------
|
|
337
|
+
list of NumberDBAPIType instances
|
|
338
|
+
|
|
339
|
+
"""
|
|
340
|
+
return [v for k, v in vars(cls).items() if type(v) is NumberDBAPIType]
|
|
341
|
+
|
|
342
|
+
@classmethod
|
|
343
|
+
def get_datetime_types(cls) -> List[DBAPIType]:
|
|
344
|
+
"""
|
|
345
|
+
Return all database types that correspond to DB-API datetime objects.
|
|
346
|
+
|
|
347
|
+
Returns
|
|
348
|
+
-------
|
|
349
|
+
list of DatetimeDBAPIType instances
|
|
350
|
+
|
|
351
|
+
"""
|
|
352
|
+
return [v for k, v in vars(cls).items() if type(v) is DatetimeDBAPIType]
|
|
353
|
+
|
|
354
|
+
@classmethod
|
|
355
|
+
def get_non_dbapi_types(cls) -> List[DBAPIType]:
|
|
356
|
+
"""
|
|
357
|
+
Return all database types that do not correspond to DB-API typed objects.
|
|
358
|
+
|
|
359
|
+
Returns
|
|
360
|
+
-------
|
|
361
|
+
list of DBAPIType instances
|
|
362
|
+
|
|
363
|
+
"""
|
|
364
|
+
return [v for k, v in vars(cls).items() if type(v) is DBAPIType]
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
# DB-API type constants
|
|
368
|
+
STRING = DBAPIType(*ColumnType.get_string_types())
|
|
369
|
+
BINARY = DBAPIType(*ColumnType.get_binary_types())
|
|
370
|
+
NUMBER = DBAPIType(*ColumnType.get_number_types())
|
|
371
|
+
DATETIME = DBAPIType(*ColumnType.get_datetime_types())
|
|
372
|
+
UNKNOWN = DBAPIType(*ColumnType.get_non_dbapi_types())
|
|
373
|
+
ROWID = DBAPIType()
|
|
File without changes
|