sqlspec 0.26.0__py3-none-any.whl → 0.27.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sqlspec might be problematic. Click here for more details.
- sqlspec/__init__.py +7 -15
- sqlspec/_serialization.py +55 -25
- sqlspec/_typing.py +62 -52
- sqlspec/adapters/adbc/_types.py +1 -1
- sqlspec/adapters/adbc/adk/__init__.py +5 -0
- sqlspec/adapters/adbc/adk/store.py +870 -0
- sqlspec/adapters/adbc/config.py +62 -12
- sqlspec/adapters/adbc/data_dictionary.py +52 -2
- sqlspec/adapters/adbc/driver.py +144 -45
- sqlspec/adapters/adbc/litestar/__init__.py +5 -0
- sqlspec/adapters/adbc/litestar/store.py +504 -0
- sqlspec/adapters/adbc/type_converter.py +44 -50
- sqlspec/adapters/aiosqlite/_types.py +1 -1
- sqlspec/adapters/aiosqlite/adk/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/adk/store.py +527 -0
- sqlspec/adapters/aiosqlite/config.py +86 -16
- sqlspec/adapters/aiosqlite/data_dictionary.py +34 -2
- sqlspec/adapters/aiosqlite/driver.py +127 -38
- sqlspec/adapters/aiosqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/litestar/store.py +281 -0
- sqlspec/adapters/aiosqlite/pool.py +7 -7
- sqlspec/adapters/asyncmy/__init__.py +7 -1
- sqlspec/adapters/asyncmy/_types.py +1 -1
- sqlspec/adapters/asyncmy/adk/__init__.py +5 -0
- sqlspec/adapters/asyncmy/adk/store.py +493 -0
- sqlspec/adapters/asyncmy/config.py +59 -17
- sqlspec/adapters/asyncmy/data_dictionary.py +41 -2
- sqlspec/adapters/asyncmy/driver.py +293 -62
- sqlspec/adapters/asyncmy/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncmy/litestar/store.py +296 -0
- sqlspec/adapters/asyncpg/__init__.py +2 -1
- sqlspec/adapters/asyncpg/_type_handlers.py +71 -0
- sqlspec/adapters/asyncpg/_types.py +11 -7
- sqlspec/adapters/asyncpg/adk/__init__.py +5 -0
- sqlspec/adapters/asyncpg/adk/store.py +450 -0
- sqlspec/adapters/asyncpg/config.py +57 -36
- sqlspec/adapters/asyncpg/data_dictionary.py +41 -2
- sqlspec/adapters/asyncpg/driver.py +153 -23
- sqlspec/adapters/asyncpg/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncpg/litestar/store.py +253 -0
- sqlspec/adapters/bigquery/_types.py +1 -1
- sqlspec/adapters/bigquery/adk/__init__.py +5 -0
- sqlspec/adapters/bigquery/adk/store.py +576 -0
- sqlspec/adapters/bigquery/config.py +25 -11
- sqlspec/adapters/bigquery/data_dictionary.py +42 -2
- sqlspec/adapters/bigquery/driver.py +352 -144
- sqlspec/adapters/bigquery/litestar/__init__.py +5 -0
- sqlspec/adapters/bigquery/litestar/store.py +327 -0
- sqlspec/adapters/bigquery/type_converter.py +55 -23
- sqlspec/adapters/duckdb/_types.py +2 -2
- sqlspec/adapters/duckdb/adk/__init__.py +14 -0
- sqlspec/adapters/duckdb/adk/store.py +553 -0
- sqlspec/adapters/duckdb/config.py +79 -21
- sqlspec/adapters/duckdb/data_dictionary.py +41 -2
- sqlspec/adapters/duckdb/driver.py +138 -43
- sqlspec/adapters/duckdb/litestar/__init__.py +5 -0
- sqlspec/adapters/duckdb/litestar/store.py +332 -0
- sqlspec/adapters/duckdb/pool.py +5 -5
- sqlspec/adapters/duckdb/type_converter.py +51 -21
- sqlspec/adapters/oracledb/_numpy_handlers.py +133 -0
- sqlspec/adapters/oracledb/_types.py +20 -2
- sqlspec/adapters/oracledb/adk/__init__.py +5 -0
- sqlspec/adapters/oracledb/adk/store.py +1745 -0
- sqlspec/adapters/oracledb/config.py +120 -36
- sqlspec/adapters/oracledb/data_dictionary.py +87 -20
- sqlspec/adapters/oracledb/driver.py +292 -84
- sqlspec/adapters/oracledb/litestar/__init__.py +5 -0
- sqlspec/adapters/oracledb/litestar/store.py +767 -0
- sqlspec/adapters/oracledb/migrations.py +316 -25
- sqlspec/adapters/oracledb/type_converter.py +91 -16
- sqlspec/adapters/psqlpy/_type_handlers.py +44 -0
- sqlspec/adapters/psqlpy/_types.py +2 -1
- sqlspec/adapters/psqlpy/adk/__init__.py +5 -0
- sqlspec/adapters/psqlpy/adk/store.py +482 -0
- sqlspec/adapters/psqlpy/config.py +45 -19
- sqlspec/adapters/psqlpy/data_dictionary.py +41 -2
- sqlspec/adapters/psqlpy/driver.py +101 -31
- sqlspec/adapters/psqlpy/litestar/__init__.py +5 -0
- sqlspec/adapters/psqlpy/litestar/store.py +272 -0
- sqlspec/adapters/psqlpy/type_converter.py +40 -11
- sqlspec/adapters/psycopg/_type_handlers.py +80 -0
- sqlspec/adapters/psycopg/_types.py +2 -1
- sqlspec/adapters/psycopg/adk/__init__.py +5 -0
- sqlspec/adapters/psycopg/adk/store.py +944 -0
- sqlspec/adapters/psycopg/config.py +65 -37
- sqlspec/adapters/psycopg/data_dictionary.py +77 -3
- sqlspec/adapters/psycopg/driver.py +200 -78
- sqlspec/adapters/psycopg/litestar/__init__.py +5 -0
- sqlspec/adapters/psycopg/litestar/store.py +554 -0
- sqlspec/adapters/sqlite/__init__.py +2 -1
- sqlspec/adapters/sqlite/_type_handlers.py +86 -0
- sqlspec/adapters/sqlite/_types.py +1 -1
- sqlspec/adapters/sqlite/adk/__init__.py +5 -0
- sqlspec/adapters/sqlite/adk/store.py +572 -0
- sqlspec/adapters/sqlite/config.py +85 -16
- sqlspec/adapters/sqlite/data_dictionary.py +34 -2
- sqlspec/adapters/sqlite/driver.py +120 -52
- sqlspec/adapters/sqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/sqlite/litestar/store.py +318 -0
- sqlspec/adapters/sqlite/pool.py +5 -5
- sqlspec/base.py +45 -26
- sqlspec/builder/__init__.py +73 -4
- sqlspec/builder/_base.py +91 -58
- sqlspec/builder/_column.py +5 -5
- sqlspec/builder/_ddl.py +98 -89
- sqlspec/builder/_delete.py +5 -4
- sqlspec/builder/_dml.py +388 -0
- sqlspec/{_sql.py → builder/_factory.py} +41 -44
- sqlspec/builder/_insert.py +5 -82
- sqlspec/builder/{mixins/_join_operations.py → _join.py} +145 -143
- sqlspec/builder/_merge.py +446 -11
- sqlspec/builder/_parsing_utils.py +9 -11
- sqlspec/builder/_select.py +1313 -25
- sqlspec/builder/_update.py +11 -42
- sqlspec/cli.py +76 -69
- sqlspec/config.py +231 -60
- sqlspec/core/__init__.py +5 -4
- sqlspec/core/cache.py +18 -18
- sqlspec/core/compiler.py +6 -8
- sqlspec/core/filters.py +37 -37
- sqlspec/core/hashing.py +9 -9
- sqlspec/core/parameters.py +76 -45
- sqlspec/core/result.py +102 -46
- sqlspec/core/splitter.py +16 -17
- sqlspec/core/statement.py +32 -31
- sqlspec/core/type_conversion.py +3 -2
- sqlspec/driver/__init__.py +1 -3
- sqlspec/driver/_async.py +95 -161
- sqlspec/driver/_common.py +133 -80
- sqlspec/driver/_sync.py +95 -162
- sqlspec/driver/mixins/_result_tools.py +20 -236
- sqlspec/driver/mixins/_sql_translator.py +4 -4
- sqlspec/exceptions.py +70 -7
- sqlspec/extensions/adk/__init__.py +53 -0
- sqlspec/extensions/adk/_types.py +51 -0
- sqlspec/extensions/adk/converters.py +172 -0
- sqlspec/extensions/adk/migrations/0001_create_adk_tables.py +144 -0
- sqlspec/extensions/adk/migrations/__init__.py +0 -0
- sqlspec/extensions/adk/service.py +181 -0
- sqlspec/extensions/adk/store.py +536 -0
- sqlspec/extensions/aiosql/adapter.py +73 -53
- sqlspec/extensions/litestar/__init__.py +21 -4
- sqlspec/extensions/litestar/cli.py +54 -10
- sqlspec/extensions/litestar/config.py +59 -266
- sqlspec/extensions/litestar/handlers.py +46 -17
- sqlspec/extensions/litestar/migrations/0001_create_session_table.py +137 -0
- sqlspec/extensions/litestar/migrations/__init__.py +3 -0
- sqlspec/extensions/litestar/plugin.py +324 -223
- sqlspec/extensions/litestar/providers.py +25 -25
- sqlspec/extensions/litestar/store.py +265 -0
- sqlspec/loader.py +30 -49
- sqlspec/migrations/base.py +200 -76
- sqlspec/migrations/commands.py +591 -62
- sqlspec/migrations/context.py +6 -9
- sqlspec/migrations/fix.py +199 -0
- sqlspec/migrations/loaders.py +47 -19
- sqlspec/migrations/runner.py +241 -75
- sqlspec/migrations/tracker.py +237 -21
- sqlspec/migrations/utils.py +51 -3
- sqlspec/migrations/validation.py +177 -0
- sqlspec/protocols.py +66 -36
- sqlspec/storage/_utils.py +98 -0
- sqlspec/storage/backends/fsspec.py +134 -106
- sqlspec/storage/backends/local.py +78 -51
- sqlspec/storage/backends/obstore.py +278 -162
- sqlspec/storage/registry.py +75 -39
- sqlspec/typing.py +14 -84
- sqlspec/utils/config_resolver.py +6 -6
- sqlspec/utils/correlation.py +4 -5
- sqlspec/utils/data_transformation.py +3 -2
- sqlspec/utils/deprecation.py +9 -8
- sqlspec/utils/fixtures.py +4 -4
- sqlspec/utils/logging.py +46 -6
- sqlspec/utils/module_loader.py +2 -2
- sqlspec/utils/schema.py +288 -0
- sqlspec/utils/serializers.py +3 -3
- sqlspec/utils/sync_tools.py +21 -17
- sqlspec/utils/text.py +1 -2
- sqlspec/utils/type_guards.py +111 -20
- sqlspec/utils/version.py +433 -0
- {sqlspec-0.26.0.dist-info → sqlspec-0.27.0.dist-info}/METADATA +40 -21
- sqlspec-0.27.0.dist-info/RECORD +207 -0
- sqlspec/builder/mixins/__init__.py +0 -55
- sqlspec/builder/mixins/_cte_and_set_ops.py +0 -253
- sqlspec/builder/mixins/_delete_operations.py +0 -50
- sqlspec/builder/mixins/_insert_operations.py +0 -282
- sqlspec/builder/mixins/_merge_operations.py +0 -698
- sqlspec/builder/mixins/_order_limit_operations.py +0 -145
- sqlspec/builder/mixins/_pivot_operations.py +0 -157
- sqlspec/builder/mixins/_select_operations.py +0 -930
- sqlspec/builder/mixins/_update_operations.py +0 -199
- sqlspec/builder/mixins/_where_clause.py +0 -1298
- sqlspec-0.26.0.dist-info/RECORD +0 -157
- sqlspec-0.26.0.dist-info/licenses/NOTICE +0 -29
- {sqlspec-0.26.0.dist-info → sqlspec-0.27.0.dist-info}/WHEEL +0 -0
- {sqlspec-0.26.0.dist-info → sqlspec-0.27.0.dist-info}/entry_points.txt +0 -0
- {sqlspec-0.26.0.dist-info → sqlspec-0.27.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
# pyright: reportPrivateUsage=false
|
|
2
|
-
"""UPDATE operation mixins.
|
|
3
|
-
|
|
4
|
-
Provides mixins for UPDATE statement functionality including
|
|
5
|
-
table specification, SET clauses, and FROM clauses.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from collections.abc import Mapping
|
|
9
|
-
from typing import Any, Optional, Union
|
|
10
|
-
|
|
11
|
-
from mypy_extensions import trait
|
|
12
|
-
from sqlglot import exp
|
|
13
|
-
from typing_extensions import Self
|
|
14
|
-
|
|
15
|
-
from sqlspec.builder._parsing_utils import extract_sql_object_expression
|
|
16
|
-
from sqlspec.exceptions import SQLBuilderError
|
|
17
|
-
from sqlspec.utils.type_guards import has_query_builder_parameters
|
|
18
|
-
|
|
19
|
-
__all__ = ("UpdateFromClauseMixin", "UpdateSetClauseMixin", "UpdateTableClauseMixin")
|
|
20
|
-
|
|
21
|
-
MIN_SET_ARGS = 2
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@trait
|
|
25
|
-
class UpdateTableClauseMixin:
|
|
26
|
-
"""Mixin providing TABLE clause for UPDATE builders."""
|
|
27
|
-
|
|
28
|
-
__slots__ = ()
|
|
29
|
-
|
|
30
|
-
def get_expression(self) -> Optional[exp.Expression]: ...
|
|
31
|
-
def set_expression(self, expression: exp.Expression) -> None: ...
|
|
32
|
-
|
|
33
|
-
def table(self, table_name: str, alias: Optional[str] = None) -> Self:
|
|
34
|
-
"""Set the table to update.
|
|
35
|
-
|
|
36
|
-
Args:
|
|
37
|
-
table_name: The name of the table.
|
|
38
|
-
alias: Optional alias for the table.
|
|
39
|
-
|
|
40
|
-
Returns:
|
|
41
|
-
The current builder instance for method chaining.
|
|
42
|
-
"""
|
|
43
|
-
current_expr = self.get_expression()
|
|
44
|
-
if current_expr is None or not isinstance(current_expr, exp.Update):
|
|
45
|
-
self.set_expression(exp.Update(this=None, expressions=[], joins=[]))
|
|
46
|
-
current_expr = self.get_expression()
|
|
47
|
-
|
|
48
|
-
assert current_expr is not None
|
|
49
|
-
table_expr: exp.Expression = exp.to_table(table_name, alias=alias)
|
|
50
|
-
current_expr.set("this", table_expr)
|
|
51
|
-
setattr(self, "_table", table_name)
|
|
52
|
-
return self
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
@trait
|
|
56
|
-
class UpdateSetClauseMixin:
|
|
57
|
-
"""Mixin providing SET clause for UPDATE builders."""
|
|
58
|
-
|
|
59
|
-
__slots__ = ()
|
|
60
|
-
|
|
61
|
-
def get_expression(self) -> Optional[exp.Expression]: ...
|
|
62
|
-
def set_expression(self, expression: exp.Expression) -> None: ...
|
|
63
|
-
|
|
64
|
-
def add_parameter(self, value: Any, name: Optional[str] = None) -> tuple[Any, str]:
|
|
65
|
-
"""Add parameter - provided by QueryBuilder."""
|
|
66
|
-
msg = "Method must be provided by QueryBuilder subclass"
|
|
67
|
-
raise NotImplementedError(msg)
|
|
68
|
-
|
|
69
|
-
def _generate_unique_parameter_name(self, base_name: str) -> str:
|
|
70
|
-
"""Generate unique parameter name - provided by QueryBuilder."""
|
|
71
|
-
msg = "Method must be provided by QueryBuilder subclass"
|
|
72
|
-
raise NotImplementedError(msg)
|
|
73
|
-
|
|
74
|
-
def _process_update_value(self, val: Any, col: Any) -> exp.Expression:
|
|
75
|
-
"""Process a value for UPDATE assignment, handling SQL objects and parameters.
|
|
76
|
-
|
|
77
|
-
Args:
|
|
78
|
-
val: The value to process
|
|
79
|
-
col: The column name for parameter naming
|
|
80
|
-
|
|
81
|
-
Returns:
|
|
82
|
-
The processed expression for the value
|
|
83
|
-
"""
|
|
84
|
-
if isinstance(val, exp.Expression):
|
|
85
|
-
return val
|
|
86
|
-
if has_query_builder_parameters(val):
|
|
87
|
-
subquery = val.build()
|
|
88
|
-
sql_str = subquery.sql if hasattr(subquery, "sql") and not callable(subquery.sql) else str(subquery)
|
|
89
|
-
value_expr = exp.paren(exp.maybe_parse(sql_str, dialect=getattr(self, "dialect", None)))
|
|
90
|
-
if has_query_builder_parameters(val):
|
|
91
|
-
for p_name, p_value in val.parameters.items():
|
|
92
|
-
self.add_parameter(p_value, name=p_name)
|
|
93
|
-
return value_expr
|
|
94
|
-
if hasattr(val, "expression") and hasattr(val, "sql"):
|
|
95
|
-
return extract_sql_object_expression(val, builder=self)
|
|
96
|
-
column_name = col if isinstance(col, str) else str(col)
|
|
97
|
-
if "." in column_name:
|
|
98
|
-
column_name = column_name.split(".")[-1]
|
|
99
|
-
param_name = self._generate_unique_parameter_name(column_name)
|
|
100
|
-
param_name = self.add_parameter(val, name=param_name)[1]
|
|
101
|
-
return exp.Placeholder(this=param_name)
|
|
102
|
-
|
|
103
|
-
def set(self, *args: Any, **kwargs: Any) -> Self:
|
|
104
|
-
"""Set columns and values for the UPDATE statement.
|
|
105
|
-
|
|
106
|
-
Supports:
|
|
107
|
-
- set_(column, value)
|
|
108
|
-
- set_(mapping)
|
|
109
|
-
- set_(**kwargs)
|
|
110
|
-
- set_(mapping, **kwargs)
|
|
111
|
-
|
|
112
|
-
Args:
|
|
113
|
-
*args: Either (column, value) or a mapping.
|
|
114
|
-
**kwargs: Column-value pairs to set.
|
|
115
|
-
|
|
116
|
-
Raises:
|
|
117
|
-
SQLBuilderError: If the current expression is not an UPDATE statement or usage is invalid.
|
|
118
|
-
|
|
119
|
-
Returns:
|
|
120
|
-
The current builder instance for method chaining.
|
|
121
|
-
"""
|
|
122
|
-
current_expr = self.get_expression()
|
|
123
|
-
if current_expr is None:
|
|
124
|
-
self.set_expression(exp.Update())
|
|
125
|
-
current_expr = self.get_expression()
|
|
126
|
-
|
|
127
|
-
if not isinstance(current_expr, exp.Update):
|
|
128
|
-
msg = "Cannot add SET clause to non-UPDATE expression."
|
|
129
|
-
raise SQLBuilderError(msg)
|
|
130
|
-
assignments = []
|
|
131
|
-
if len(args) == MIN_SET_ARGS and not kwargs:
|
|
132
|
-
col, val = args
|
|
133
|
-
col_expr = col if isinstance(col, exp.Column) else exp.column(col)
|
|
134
|
-
value_expr = self._process_update_value(val, col)
|
|
135
|
-
assignments.append(exp.EQ(this=col_expr, expression=value_expr))
|
|
136
|
-
elif (len(args) == 1 and isinstance(args[0], Mapping)) or kwargs:
|
|
137
|
-
all_values = dict(args[0] if args else {}, **kwargs)
|
|
138
|
-
for col, val in all_values.items():
|
|
139
|
-
value_expr = self._process_update_value(val, col)
|
|
140
|
-
assignments.append(exp.EQ(this=exp.column(col), expression=value_expr))
|
|
141
|
-
else:
|
|
142
|
-
msg = "Invalid arguments for set(): use (column, value), mapping, or kwargs."
|
|
143
|
-
raise SQLBuilderError(msg)
|
|
144
|
-
existing = current_expr.args.get("expressions", [])
|
|
145
|
-
current_expr.set("expressions", existing + assignments)
|
|
146
|
-
return self
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
@trait
|
|
150
|
-
class UpdateFromClauseMixin:
|
|
151
|
-
"""Mixin providing FROM clause for UPDATE builders (e.g., PostgreSQL style)."""
|
|
152
|
-
|
|
153
|
-
__slots__ = ()
|
|
154
|
-
|
|
155
|
-
def get_expression(self) -> Optional[exp.Expression]: ...
|
|
156
|
-
def set_expression(self, expression: exp.Expression) -> None: ...
|
|
157
|
-
|
|
158
|
-
def from_(self, table: Union[str, exp.Expression, Any], alias: Optional[str] = None) -> Self:
|
|
159
|
-
"""Add a FROM clause to the UPDATE statement.
|
|
160
|
-
|
|
161
|
-
Args:
|
|
162
|
-
table: The table name, expression, or subquery to add to the FROM clause.
|
|
163
|
-
alias: Optional alias for the table in the FROM clause.
|
|
164
|
-
|
|
165
|
-
Returns:
|
|
166
|
-
The current builder instance for method chaining.
|
|
167
|
-
|
|
168
|
-
Raises:
|
|
169
|
-
SQLBuilderError: If the current expression is not an UPDATE statement.
|
|
170
|
-
"""
|
|
171
|
-
current_expr = self.get_expression()
|
|
172
|
-
if current_expr is None or not isinstance(current_expr, exp.Update):
|
|
173
|
-
msg = "Cannot add FROM clause to non-UPDATE expression. Set the main table first."
|
|
174
|
-
raise SQLBuilderError(msg)
|
|
175
|
-
table_expr: exp.Expression
|
|
176
|
-
if isinstance(table, str):
|
|
177
|
-
table_expr = exp.to_table(table, alias=alias)
|
|
178
|
-
elif has_query_builder_parameters(table):
|
|
179
|
-
subquery_builder_parameters = getattr(table, "_parameters", None)
|
|
180
|
-
if subquery_builder_parameters:
|
|
181
|
-
for p_name, p_value in subquery_builder_parameters.items():
|
|
182
|
-
self.add_parameter(p_value, name=p_name) # type: ignore[attr-defined]
|
|
183
|
-
subquery_exp = exp.paren(getattr(table, "_expression", exp.select()))
|
|
184
|
-
table_expr = exp.alias_(subquery_exp, alias) if alias else subquery_exp
|
|
185
|
-
elif isinstance(table, exp.Expression):
|
|
186
|
-
table_expr = exp.alias_(table, alias) if alias else table
|
|
187
|
-
else:
|
|
188
|
-
msg = f"Unsupported table type for FROM clause: {type(table)}"
|
|
189
|
-
raise SQLBuilderError(msg)
|
|
190
|
-
if current_expr.args.get("from") is None:
|
|
191
|
-
current_expr.set("from", exp.From(expressions=[]))
|
|
192
|
-
from_clause = current_expr.args["from"]
|
|
193
|
-
if hasattr(from_clause, "append"):
|
|
194
|
-
from_clause.append("expressions", table_expr)
|
|
195
|
-
else:
|
|
196
|
-
if not from_clause.expressions:
|
|
197
|
-
from_clause.expressions = []
|
|
198
|
-
from_clause.expressions.append(table_expr)
|
|
199
|
-
return self
|