sqlspec 0.9.0__py3-none-any.whl → 0.9.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.
Potentially problematic release.
This version of sqlspec might be problematic. Click here for more details.
- sqlspec/adapters/adbc/driver.py +135 -3
- sqlspec/adapters/aiosqlite/driver.py +136 -3
- sqlspec/adapters/asyncmy/driver.py +136 -3
- sqlspec/adapters/asyncpg/driver.py +136 -2
- sqlspec/adapters/duckdb/driver.py +141 -11
- sqlspec/adapters/oracledb/driver.py +270 -4
- sqlspec/adapters/psqlpy/config.py +6 -14
- sqlspec/adapters/psqlpy/driver.py +149 -3
- sqlspec/adapters/psycopg/driver.py +306 -58
- sqlspec/adapters/sqlite/driver.py +136 -34
- sqlspec/base.py +413 -9
- sqlspec/extensions/litestar/plugin.py +2 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/METADATA +141 -2
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/RECORD +17 -17
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/WHEEL +0 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/licenses/LICENSE +0 -0
- {sqlspec-0.9.0.dist-info → sqlspec-0.9.1.dist-info}/licenses/NOTICE +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
from contextlib import contextmanager
|
|
2
2
|
from sqlite3 import Connection, Cursor
|
|
3
|
-
from typing import TYPE_CHECKING, Any, Optional, Union, cast
|
|
3
|
+
from typing import TYPE_CHECKING, Any, Optional, Union, cast, overload
|
|
4
4
|
|
|
5
5
|
from sqlspec.base import SyncDriverAdapterProtocol, T
|
|
6
6
|
|
|
7
7
|
if TYPE_CHECKING:
|
|
8
|
-
from collections.abc import Generator
|
|
8
|
+
from collections.abc import Generator, Sequence
|
|
9
9
|
|
|
10
10
|
from sqlspec.typing import ModelDTOT, StatementParameterType
|
|
11
11
|
|
|
@@ -33,6 +33,29 @@ class SqliteDriver(SyncDriverAdapterProtocol["Connection"]):
|
|
|
33
33
|
finally:
|
|
34
34
|
cursor.close()
|
|
35
35
|
|
|
36
|
+
# --- Public API Methods --- #
|
|
37
|
+
@overload
|
|
38
|
+
def select(
|
|
39
|
+
self,
|
|
40
|
+
sql: str,
|
|
41
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
42
|
+
/,
|
|
43
|
+
*,
|
|
44
|
+
connection: "Optional[Connection]" = None,
|
|
45
|
+
schema_type: None = None,
|
|
46
|
+
**kwargs: Any,
|
|
47
|
+
) -> "Sequence[dict[str, Any]]": ...
|
|
48
|
+
@overload
|
|
49
|
+
def select(
|
|
50
|
+
self,
|
|
51
|
+
sql: str,
|
|
52
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
53
|
+
/,
|
|
54
|
+
*,
|
|
55
|
+
connection: "Optional[Connection]" = None,
|
|
56
|
+
schema_type: "type[ModelDTOT]",
|
|
57
|
+
**kwargs: Any,
|
|
58
|
+
) -> "Sequence[ModelDTOT]": ...
|
|
36
59
|
def select(
|
|
37
60
|
self,
|
|
38
61
|
sql: str,
|
|
@@ -42,7 +65,7 @@ class SqliteDriver(SyncDriverAdapterProtocol["Connection"]):
|
|
|
42
65
|
connection: Optional["Connection"] = None,
|
|
43
66
|
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
44
67
|
**kwargs: Any,
|
|
45
|
-
) -> "
|
|
68
|
+
) -> "Sequence[Union[ModelDTOT, dict[str, Any]]]":
|
|
46
69
|
"""Fetch data from the database.
|
|
47
70
|
|
|
48
71
|
Returns:
|
|
@@ -63,6 +86,28 @@ class SqliteDriver(SyncDriverAdapterProtocol["Connection"]):
|
|
|
63
86
|
return [cast("ModelDTOT", schema_type(**dict(zip(column_names, row)))) for row in results] # pyright: ignore[reportUnknownArgumentType]
|
|
64
87
|
return [dict(zip(column_names, row)) for row in results] # pyright: ignore[reportUnknownArgumentType]
|
|
65
88
|
|
|
89
|
+
@overload
|
|
90
|
+
def select_one(
|
|
91
|
+
self,
|
|
92
|
+
sql: str,
|
|
93
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
94
|
+
/,
|
|
95
|
+
*,
|
|
96
|
+
connection: "Optional[Connection]" = None,
|
|
97
|
+
schema_type: None = None,
|
|
98
|
+
**kwargs: Any,
|
|
99
|
+
) -> "dict[str, Any]": ...
|
|
100
|
+
@overload
|
|
101
|
+
def select_one(
|
|
102
|
+
self,
|
|
103
|
+
sql: str,
|
|
104
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
105
|
+
/,
|
|
106
|
+
*,
|
|
107
|
+
connection: "Optional[Connection]" = None,
|
|
108
|
+
schema_type: "type[ModelDTOT]",
|
|
109
|
+
**kwargs: Any,
|
|
110
|
+
) -> "ModelDTOT": ...
|
|
66
111
|
def select_one(
|
|
67
112
|
self,
|
|
68
113
|
sql: str,
|
|
@@ -92,6 +137,28 @@ class SqliteDriver(SyncDriverAdapterProtocol["Connection"]):
|
|
|
92
137
|
return dict(zip(column_names, result))
|
|
93
138
|
return schema_type(**dict(zip(column_names, result))) # type: ignore[return-value]
|
|
94
139
|
|
|
140
|
+
@overload
|
|
141
|
+
def select_one_or_none(
|
|
142
|
+
self,
|
|
143
|
+
sql: str,
|
|
144
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
145
|
+
/,
|
|
146
|
+
*,
|
|
147
|
+
connection: "Optional[Connection]" = None,
|
|
148
|
+
schema_type: None = None,
|
|
149
|
+
**kwargs: Any,
|
|
150
|
+
) -> "Optional[dict[str, Any]]": ...
|
|
151
|
+
@overload
|
|
152
|
+
def select_one_or_none(
|
|
153
|
+
self,
|
|
154
|
+
sql: str,
|
|
155
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
156
|
+
/,
|
|
157
|
+
*,
|
|
158
|
+
connection: "Optional[Connection]" = None,
|
|
159
|
+
schema_type: "type[ModelDTOT]",
|
|
160
|
+
**kwargs: Any,
|
|
161
|
+
) -> "Optional[ModelDTOT]": ...
|
|
95
162
|
def select_one_or_none(
|
|
96
163
|
self,
|
|
97
164
|
sql: str,
|
|
@@ -122,6 +189,28 @@ class SqliteDriver(SyncDriverAdapterProtocol["Connection"]):
|
|
|
122
189
|
return dict(zip(column_names, result))
|
|
123
190
|
return schema_type(**dict(zip(column_names, result))) # type: ignore[return-value]
|
|
124
191
|
|
|
192
|
+
@overload
|
|
193
|
+
def select_value(
|
|
194
|
+
self,
|
|
195
|
+
sql: str,
|
|
196
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
197
|
+
/,
|
|
198
|
+
*,
|
|
199
|
+
connection: "Optional[Connection]" = None,
|
|
200
|
+
schema_type: None = None,
|
|
201
|
+
**kwargs: Any,
|
|
202
|
+
) -> "Any": ...
|
|
203
|
+
@overload
|
|
204
|
+
def select_value(
|
|
205
|
+
self,
|
|
206
|
+
sql: str,
|
|
207
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
208
|
+
/,
|
|
209
|
+
*,
|
|
210
|
+
connection: "Optional[Connection]" = None,
|
|
211
|
+
schema_type: "type[T]",
|
|
212
|
+
**kwargs: Any,
|
|
213
|
+
) -> "T": ...
|
|
125
214
|
def select_value(
|
|
126
215
|
self,
|
|
127
216
|
sql: str,
|
|
@@ -150,6 +239,28 @@ class SqliteDriver(SyncDriverAdapterProtocol["Connection"]):
|
|
|
150
239
|
return result[0]
|
|
151
240
|
return schema_type(result[0]) # type: ignore[call-arg]
|
|
152
241
|
|
|
242
|
+
@overload
|
|
243
|
+
def select_value_or_none(
|
|
244
|
+
self,
|
|
245
|
+
sql: str,
|
|
246
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
247
|
+
/,
|
|
248
|
+
*,
|
|
249
|
+
connection: "Optional[Connection]" = None,
|
|
250
|
+
schema_type: None = None,
|
|
251
|
+
**kwargs: Any,
|
|
252
|
+
) -> "Optional[Any]": ...
|
|
253
|
+
@overload
|
|
254
|
+
def select_value_or_none(
|
|
255
|
+
self,
|
|
256
|
+
sql: str,
|
|
257
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
258
|
+
/,
|
|
259
|
+
*,
|
|
260
|
+
connection: "Optional[Connection]" = None,
|
|
261
|
+
schema_type: "type[T]",
|
|
262
|
+
**kwargs: Any,
|
|
263
|
+
) -> "Optional[T]": ...
|
|
153
264
|
def select_value_or_none(
|
|
154
265
|
self,
|
|
155
266
|
sql: str,
|
|
@@ -203,6 +314,28 @@ class SqliteDriver(SyncDriverAdapterProtocol["Connection"]):
|
|
|
203
314
|
cursor.execute(sql, parameters)
|
|
204
315
|
return cursor.rowcount if hasattr(cursor, "rowcount") else -1
|
|
205
316
|
|
|
317
|
+
@overload
|
|
318
|
+
def insert_update_delete_returning(
|
|
319
|
+
self,
|
|
320
|
+
sql: str,
|
|
321
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
322
|
+
/,
|
|
323
|
+
*,
|
|
324
|
+
connection: "Optional[Connection]" = None,
|
|
325
|
+
schema_type: None = None,
|
|
326
|
+
**kwargs: Any,
|
|
327
|
+
) -> "dict[str, Any]": ...
|
|
328
|
+
@overload
|
|
329
|
+
def insert_update_delete_returning(
|
|
330
|
+
self,
|
|
331
|
+
sql: str,
|
|
332
|
+
parameters: "Optional[StatementParameterType]" = None,
|
|
333
|
+
/,
|
|
334
|
+
*,
|
|
335
|
+
connection: "Optional[Connection]" = None,
|
|
336
|
+
schema_type: "type[ModelDTOT]",
|
|
337
|
+
**kwargs: Any,
|
|
338
|
+
) -> "ModelDTOT": ...
|
|
206
339
|
def insert_update_delete_returning(
|
|
207
340
|
self,
|
|
208
341
|
sql: str,
|
|
@@ -272,34 +405,3 @@ class SqliteDriver(SyncDriverAdapterProtocol["Connection"]):
|
|
|
272
405
|
cursor.execute(sql, parameters)
|
|
273
406
|
|
|
274
407
|
return cast("str", cursor.statusmessage) if hasattr(cursor, "statusmessage") else "DONE" # pyright: ignore[reportUnknownMemberType,reportAttributeAccessIssue]
|
|
275
|
-
|
|
276
|
-
def execute_script_returning(
|
|
277
|
-
self,
|
|
278
|
-
sql: str,
|
|
279
|
-
parameters: Optional["StatementParameterType"] = None,
|
|
280
|
-
/,
|
|
281
|
-
*,
|
|
282
|
-
connection: Optional["Connection"] = None,
|
|
283
|
-
schema_type: "Optional[type[ModelDTOT]]" = None,
|
|
284
|
-
**kwargs: Any,
|
|
285
|
-
) -> "Optional[Union[dict[str, Any], ModelDTOT]]":
|
|
286
|
-
"""Execute a script and return result.
|
|
287
|
-
|
|
288
|
-
Returns:
|
|
289
|
-
The first row of results.
|
|
290
|
-
"""
|
|
291
|
-
connection = self._connection(connection)
|
|
292
|
-
sql, parameters = self._process_sql_params(sql, parameters, **kwargs)
|
|
293
|
-
|
|
294
|
-
with self._with_cursor(connection) as cursor:
|
|
295
|
-
if not parameters:
|
|
296
|
-
cursor.execute(sql) # pyright: ignore[reportUnknownMemberType]
|
|
297
|
-
else:
|
|
298
|
-
cursor.execute(sql, parameters)
|
|
299
|
-
result = cursor.fetchall()
|
|
300
|
-
if len(result) == 0:
|
|
301
|
-
return None
|
|
302
|
-
column_names = [c[0] for c in cursor.description or []]
|
|
303
|
-
if schema_type is not None:
|
|
304
|
-
return cast("ModelDTOT", schema_type(**dict(zip(column_names, result[0]))))
|
|
305
|
-
return dict(zip(column_names, result[0]))
|