sqlspec 0.16.1__cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.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.
- 51ff5a9eadfdefd49f98__mypyc.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/__init__.py +92 -0
- sqlspec/__main__.py +12 -0
- sqlspec/__metadata__.py +14 -0
- sqlspec/_serialization.py +77 -0
- sqlspec/_sql.py +1780 -0
- sqlspec/_typing.py +680 -0
- sqlspec/adapters/__init__.py +0 -0
- sqlspec/adapters/adbc/__init__.py +5 -0
- sqlspec/adapters/adbc/_types.py +12 -0
- sqlspec/adapters/adbc/config.py +361 -0
- sqlspec/adapters/adbc/driver.py +512 -0
- sqlspec/adapters/aiosqlite/__init__.py +19 -0
- sqlspec/adapters/aiosqlite/_types.py +13 -0
- sqlspec/adapters/aiosqlite/config.py +253 -0
- sqlspec/adapters/aiosqlite/driver.py +248 -0
- sqlspec/adapters/asyncmy/__init__.py +19 -0
- sqlspec/adapters/asyncmy/_types.py +12 -0
- sqlspec/adapters/asyncmy/config.py +180 -0
- sqlspec/adapters/asyncmy/driver.py +274 -0
- sqlspec/adapters/asyncpg/__init__.py +21 -0
- sqlspec/adapters/asyncpg/_types.py +17 -0
- sqlspec/adapters/asyncpg/config.py +229 -0
- sqlspec/adapters/asyncpg/driver.py +344 -0
- sqlspec/adapters/bigquery/__init__.py +18 -0
- sqlspec/adapters/bigquery/_types.py +12 -0
- sqlspec/adapters/bigquery/config.py +298 -0
- sqlspec/adapters/bigquery/driver.py +558 -0
- sqlspec/adapters/duckdb/__init__.py +22 -0
- sqlspec/adapters/duckdb/_types.py +12 -0
- sqlspec/adapters/duckdb/config.py +504 -0
- sqlspec/adapters/duckdb/driver.py +368 -0
- sqlspec/adapters/oracledb/__init__.py +32 -0
- sqlspec/adapters/oracledb/_types.py +14 -0
- sqlspec/adapters/oracledb/config.py +317 -0
- sqlspec/adapters/oracledb/driver.py +538 -0
- sqlspec/adapters/psqlpy/__init__.py +16 -0
- sqlspec/adapters/psqlpy/_types.py +11 -0
- sqlspec/adapters/psqlpy/config.py +214 -0
- sqlspec/adapters/psqlpy/driver.py +530 -0
- sqlspec/adapters/psycopg/__init__.py +32 -0
- sqlspec/adapters/psycopg/_types.py +17 -0
- sqlspec/adapters/psycopg/config.py +426 -0
- sqlspec/adapters/psycopg/driver.py +796 -0
- sqlspec/adapters/sqlite/__init__.py +15 -0
- sqlspec/adapters/sqlite/_types.py +11 -0
- sqlspec/adapters/sqlite/config.py +240 -0
- sqlspec/adapters/sqlite/driver.py +294 -0
- sqlspec/base.py +571 -0
- sqlspec/builder/__init__.py +62 -0
- sqlspec/builder/_base.py +473 -0
- sqlspec/builder/_column.py +320 -0
- sqlspec/builder/_ddl.py +1346 -0
- sqlspec/builder/_ddl_utils.py +103 -0
- sqlspec/builder/_delete.py +76 -0
- sqlspec/builder/_insert.py +256 -0
- sqlspec/builder/_merge.py +71 -0
- sqlspec/builder/_parsing_utils.py +140 -0
- sqlspec/builder/_select.py +170 -0
- sqlspec/builder/_update.py +188 -0
- sqlspec/builder/mixins/__init__.py +55 -0
- sqlspec/builder/mixins/_cte_and_set_ops.py +222 -0
- sqlspec/builder/mixins/_delete_operations.py +41 -0
- sqlspec/builder/mixins/_insert_operations.py +244 -0
- sqlspec/builder/mixins/_join_operations.py +122 -0
- sqlspec/builder/mixins/_merge_operations.py +476 -0
- sqlspec/builder/mixins/_order_limit_operations.py +135 -0
- sqlspec/builder/mixins/_pivot_operations.py +153 -0
- sqlspec/builder/mixins/_select_operations.py +603 -0
- sqlspec/builder/mixins/_update_operations.py +187 -0
- sqlspec/builder/mixins/_where_clause.py +621 -0
- sqlspec/cli.py +247 -0
- sqlspec/config.py +395 -0
- sqlspec/core/__init__.py +63 -0
- sqlspec/core/cache.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/core/cache.py +871 -0
- sqlspec/core/compiler.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/core/compiler.py +417 -0
- sqlspec/core/filters.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/core/filters.py +830 -0
- sqlspec/core/hashing.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/core/hashing.py +310 -0
- sqlspec/core/parameters.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/core/parameters.py +1237 -0
- sqlspec/core/result.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/core/result.py +677 -0
- sqlspec/core/splitter.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/core/splitter.py +819 -0
- sqlspec/core/statement.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/core/statement.py +676 -0
- sqlspec/driver/__init__.py +19 -0
- sqlspec/driver/_async.py +502 -0
- sqlspec/driver/_common.py +631 -0
- sqlspec/driver/_sync.py +503 -0
- sqlspec/driver/mixins/__init__.py +6 -0
- sqlspec/driver/mixins/_result_tools.py +193 -0
- sqlspec/driver/mixins/_sql_translator.py +86 -0
- sqlspec/exceptions.py +193 -0
- sqlspec/extensions/__init__.py +0 -0
- sqlspec/extensions/aiosql/__init__.py +10 -0
- sqlspec/extensions/aiosql/adapter.py +461 -0
- sqlspec/extensions/litestar/__init__.py +6 -0
- sqlspec/extensions/litestar/_utils.py +52 -0
- sqlspec/extensions/litestar/cli.py +48 -0
- sqlspec/extensions/litestar/config.py +92 -0
- sqlspec/extensions/litestar/handlers.py +260 -0
- sqlspec/extensions/litestar/plugin.py +145 -0
- sqlspec/extensions/litestar/providers.py +454 -0
- sqlspec/loader.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/loader.py +760 -0
- sqlspec/migrations/__init__.py +35 -0
- sqlspec/migrations/base.py +414 -0
- sqlspec/migrations/commands.py +443 -0
- sqlspec/migrations/loaders.py +402 -0
- sqlspec/migrations/runner.py +213 -0
- sqlspec/migrations/tracker.py +140 -0
- sqlspec/migrations/utils.py +129 -0
- sqlspec/protocols.py +407 -0
- sqlspec/py.typed +0 -0
- sqlspec/storage/__init__.py +23 -0
- sqlspec/storage/backends/__init__.py +0 -0
- sqlspec/storage/backends/base.py +163 -0
- sqlspec/storage/backends/fsspec.py +386 -0
- sqlspec/storage/backends/obstore.py +459 -0
- sqlspec/storage/capabilities.py +102 -0
- sqlspec/storage/registry.py +239 -0
- sqlspec/typing.py +299 -0
- sqlspec/utils/__init__.py +3 -0
- sqlspec/utils/correlation.py +150 -0
- sqlspec/utils/deprecation.py +106 -0
- sqlspec/utils/fixtures.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/fixtures.py +58 -0
- sqlspec/utils/logging.py +127 -0
- sqlspec/utils/module_loader.py +89 -0
- sqlspec/utils/serializers.py +4 -0
- sqlspec/utils/singleton.py +32 -0
- sqlspec/utils/sync_tools.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/sync_tools.py +237 -0
- sqlspec/utils/text.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/text.py +96 -0
- sqlspec/utils/type_guards.cpython-311-aarch64-linux-gnu.so +0 -0
- sqlspec/utils/type_guards.py +1139 -0
- sqlspec-0.16.1.dist-info/METADATA +365 -0
- sqlspec-0.16.1.dist-info/RECORD +148 -0
- sqlspec-0.16.1.dist-info/WHEEL +7 -0
- sqlspec-0.16.1.dist-info/entry_points.txt +2 -0
- sqlspec-0.16.1.dist-info/licenses/LICENSE +21 -0
- sqlspec-0.16.1.dist-info/licenses/NOTICE +29 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Update operation mixins for SQL builders."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from typing import Any, Optional, Union
|
|
5
|
+
|
|
6
|
+
from mypy_extensions import trait
|
|
7
|
+
from sqlglot import exp
|
|
8
|
+
from typing_extensions import Self
|
|
9
|
+
|
|
10
|
+
from sqlspec.exceptions import SQLBuilderError
|
|
11
|
+
from sqlspec.utils.type_guards import has_query_builder_parameters
|
|
12
|
+
|
|
13
|
+
__all__ = ("UpdateFromClauseMixin", "UpdateSetClauseMixin", "UpdateTableClauseMixin")
|
|
14
|
+
|
|
15
|
+
MIN_SET_ARGS = 2
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@trait
|
|
19
|
+
class UpdateTableClauseMixin:
|
|
20
|
+
"""Mixin providing TABLE clause for UPDATE builders."""
|
|
21
|
+
|
|
22
|
+
__slots__ = ()
|
|
23
|
+
|
|
24
|
+
# Type annotation for PyRight - this will be provided by the base class
|
|
25
|
+
_expression: Optional[exp.Expression]
|
|
26
|
+
|
|
27
|
+
def table(self, table_name: str, alias: Optional[str] = None) -> Self:
|
|
28
|
+
"""Set the table to update.
|
|
29
|
+
|
|
30
|
+
Args:
|
|
31
|
+
table_name: The name of the table.
|
|
32
|
+
alias: Optional alias for the table.
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
The current builder instance for method chaining.
|
|
36
|
+
"""
|
|
37
|
+
if self._expression is None or not isinstance(self._expression, exp.Update):
|
|
38
|
+
self._expression = exp.Update(this=None, expressions=[], joins=[])
|
|
39
|
+
table_expr: exp.Expression = exp.to_table(table_name, alias=alias)
|
|
40
|
+
self._expression.set("this", table_expr)
|
|
41
|
+
setattr(self, "_table", table_name)
|
|
42
|
+
return self
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@trait
|
|
46
|
+
class UpdateSetClauseMixin:
|
|
47
|
+
"""Mixin providing SET clause for UPDATE builders."""
|
|
48
|
+
|
|
49
|
+
__slots__ = ()
|
|
50
|
+
|
|
51
|
+
# Type annotation for PyRight - this will be provided by the base class
|
|
52
|
+
_expression: Optional[exp.Expression]
|
|
53
|
+
|
|
54
|
+
def add_parameter(self, value: Any, name: Optional[str] = None) -> tuple[Any, str]:
|
|
55
|
+
"""Add parameter - provided by QueryBuilder."""
|
|
56
|
+
msg = "Method must be provided by QueryBuilder subclass"
|
|
57
|
+
raise NotImplementedError(msg)
|
|
58
|
+
|
|
59
|
+
def _generate_unique_parameter_name(self, base_name: str) -> str:
|
|
60
|
+
"""Generate unique parameter name - provided by QueryBuilder."""
|
|
61
|
+
msg = "Method must be provided by QueryBuilder subclass"
|
|
62
|
+
raise NotImplementedError(msg)
|
|
63
|
+
|
|
64
|
+
def set(self, *args: Any, **kwargs: Any) -> Self:
|
|
65
|
+
"""Set columns and values for the UPDATE statement.
|
|
66
|
+
|
|
67
|
+
Supports:
|
|
68
|
+
- set(column, value)
|
|
69
|
+
- set(mapping)
|
|
70
|
+
- set(**kwargs)
|
|
71
|
+
- set(mapping, **kwargs)
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
*args: Either (column, value) or a mapping.
|
|
75
|
+
**kwargs: Column-value pairs to set.
|
|
76
|
+
|
|
77
|
+
Raises:
|
|
78
|
+
SQLBuilderError: If the current expression is not an UPDATE statement or usage is invalid.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
The current builder instance for method chaining.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
if self._expression is None:
|
|
85
|
+
self._expression = exp.Update()
|
|
86
|
+
if not isinstance(self._expression, exp.Update):
|
|
87
|
+
msg = "Cannot add SET clause to non-UPDATE expression."
|
|
88
|
+
raise SQLBuilderError(msg)
|
|
89
|
+
assignments = []
|
|
90
|
+
if len(args) == MIN_SET_ARGS and not kwargs:
|
|
91
|
+
col, val = args
|
|
92
|
+
col_expr = col if isinstance(col, exp.Column) else exp.column(col)
|
|
93
|
+
if isinstance(val, exp.Expression):
|
|
94
|
+
value_expr = val
|
|
95
|
+
elif has_query_builder_parameters(val):
|
|
96
|
+
subquery = val.build()
|
|
97
|
+
sql_str = subquery.sql if hasattr(subquery, "sql") and not callable(subquery.sql) else str(subquery)
|
|
98
|
+
value_expr = exp.paren(exp.maybe_parse(sql_str, dialect=getattr(self, "dialect", None)))
|
|
99
|
+
if has_query_builder_parameters(val):
|
|
100
|
+
for p_name, p_value in val.parameters.items():
|
|
101
|
+
self.add_parameter(p_value, name=p_name)
|
|
102
|
+
else:
|
|
103
|
+
column_name = col if isinstance(col, str) else str(col)
|
|
104
|
+
if "." in column_name:
|
|
105
|
+
column_name = column_name.split(".")[-1]
|
|
106
|
+
param_name = self._generate_unique_parameter_name(column_name)
|
|
107
|
+
param_name = self.add_parameter(val, name=param_name)[1]
|
|
108
|
+
value_expr = exp.Placeholder(this=param_name)
|
|
109
|
+
assignments.append(exp.EQ(this=col_expr, expression=value_expr))
|
|
110
|
+
elif (len(args) == 1 and isinstance(args[0], Mapping)) or kwargs:
|
|
111
|
+
all_values = dict(args[0] if args else {}, **kwargs)
|
|
112
|
+
for col, val in all_values.items():
|
|
113
|
+
if isinstance(val, exp.Expression):
|
|
114
|
+
value_expr = val
|
|
115
|
+
elif has_query_builder_parameters(val):
|
|
116
|
+
subquery = val.build()
|
|
117
|
+
sql_str = subquery.sql if hasattr(subquery, "sql") and not callable(subquery.sql) else str(subquery)
|
|
118
|
+
value_expr = exp.paren(exp.maybe_parse(sql_str, dialect=getattr(self, "dialect", None)))
|
|
119
|
+
if has_query_builder_parameters(val):
|
|
120
|
+
for p_name, p_value in val.parameters.items():
|
|
121
|
+
self.add_parameter(p_value, name=p_name)
|
|
122
|
+
else:
|
|
123
|
+
column_name = col if isinstance(col, str) else str(col)
|
|
124
|
+
if "." in column_name:
|
|
125
|
+
column_name = column_name.split(".")[-1]
|
|
126
|
+
param_name = self._generate_unique_parameter_name(column_name)
|
|
127
|
+
param_name = self.add_parameter(val, name=param_name)[1]
|
|
128
|
+
value_expr = exp.Placeholder(this=param_name)
|
|
129
|
+
assignments.append(exp.EQ(this=exp.column(col), expression=value_expr))
|
|
130
|
+
else:
|
|
131
|
+
msg = "Invalid arguments for set(): use (column, value), mapping, or kwargs."
|
|
132
|
+
raise SQLBuilderError(msg)
|
|
133
|
+
existing = self._expression.args.get("expressions", [])
|
|
134
|
+
self._expression.set("expressions", existing + assignments)
|
|
135
|
+
return self
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@trait
|
|
139
|
+
class UpdateFromClauseMixin:
|
|
140
|
+
"""Mixin providing FROM clause for UPDATE builders (e.g., PostgreSQL style)."""
|
|
141
|
+
|
|
142
|
+
__slots__ = ()
|
|
143
|
+
|
|
144
|
+
# Type annotation for PyRight - this will be provided by the base class
|
|
145
|
+
_expression: Optional[exp.Expression]
|
|
146
|
+
|
|
147
|
+
def from_(self, table: Union[str, exp.Expression, Any], alias: Optional[str] = None) -> Self:
|
|
148
|
+
"""Add a FROM clause to the UPDATE statement.
|
|
149
|
+
|
|
150
|
+
Args:
|
|
151
|
+
table: The table name, expression, or subquery to add to the FROM clause.
|
|
152
|
+
alias: Optional alias for the table in the FROM clause.
|
|
153
|
+
|
|
154
|
+
Returns:
|
|
155
|
+
The current builder instance for method chaining.
|
|
156
|
+
|
|
157
|
+
Raises:
|
|
158
|
+
SQLBuilderError: If the current expression is not an UPDATE statement.
|
|
159
|
+
"""
|
|
160
|
+
if self._expression is None or not isinstance(self._expression, exp.Update):
|
|
161
|
+
msg = "Cannot add FROM clause to non-UPDATE expression. Set the main table first."
|
|
162
|
+
raise SQLBuilderError(msg)
|
|
163
|
+
table_expr: exp.Expression
|
|
164
|
+
if isinstance(table, str):
|
|
165
|
+
table_expr = exp.to_table(table, alias=alias)
|
|
166
|
+
elif has_query_builder_parameters(table):
|
|
167
|
+
subquery_builder_parameters = getattr(table, "_parameters", None)
|
|
168
|
+
if subquery_builder_parameters:
|
|
169
|
+
for p_name, p_value in subquery_builder_parameters.items():
|
|
170
|
+
self.add_parameter(p_value, name=p_name) # type: ignore[attr-defined]
|
|
171
|
+
subquery_exp = exp.paren(getattr(table, "_expression", exp.select()))
|
|
172
|
+
table_expr = exp.alias_(subquery_exp, alias) if alias else subquery_exp
|
|
173
|
+
elif isinstance(table, exp.Expression):
|
|
174
|
+
table_expr = exp.alias_(table, alias) if alias else table
|
|
175
|
+
else:
|
|
176
|
+
msg = f"Unsupported table type for FROM clause: {type(table)}"
|
|
177
|
+
raise SQLBuilderError(msg)
|
|
178
|
+
if self._expression.args.get("from") is None:
|
|
179
|
+
self._expression.set("from", exp.From(expressions=[]))
|
|
180
|
+
from_clause = self._expression.args["from"]
|
|
181
|
+
if hasattr(from_clause, "append"):
|
|
182
|
+
from_clause.append("expressions", table_expr)
|
|
183
|
+
else:
|
|
184
|
+
if not from_clause.expressions:
|
|
185
|
+
from_clause.expressions = []
|
|
186
|
+
from_clause.expressions.append(table_expr)
|
|
187
|
+
return self
|