sqlspec 0.14.1__py3-none-any.whl → 0.16.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.

Files changed (159) hide show
  1. sqlspec/__init__.py +50 -25
  2. sqlspec/__main__.py +1 -1
  3. sqlspec/__metadata__.py +1 -3
  4. sqlspec/_serialization.py +1 -2
  5. sqlspec/_sql.py +480 -121
  6. sqlspec/_typing.py +278 -142
  7. sqlspec/adapters/adbc/__init__.py +4 -3
  8. sqlspec/adapters/adbc/_types.py +12 -0
  9. sqlspec/adapters/adbc/config.py +115 -260
  10. sqlspec/adapters/adbc/driver.py +462 -367
  11. sqlspec/adapters/aiosqlite/__init__.py +18 -3
  12. sqlspec/adapters/aiosqlite/_types.py +13 -0
  13. sqlspec/adapters/aiosqlite/config.py +199 -129
  14. sqlspec/adapters/aiosqlite/driver.py +230 -269
  15. sqlspec/adapters/asyncmy/__init__.py +18 -3
  16. sqlspec/adapters/asyncmy/_types.py +12 -0
  17. sqlspec/adapters/asyncmy/config.py +80 -168
  18. sqlspec/adapters/asyncmy/driver.py +260 -225
  19. sqlspec/adapters/asyncpg/__init__.py +19 -4
  20. sqlspec/adapters/asyncpg/_types.py +17 -0
  21. sqlspec/adapters/asyncpg/config.py +82 -181
  22. sqlspec/adapters/asyncpg/driver.py +285 -383
  23. sqlspec/adapters/bigquery/__init__.py +17 -3
  24. sqlspec/adapters/bigquery/_types.py +12 -0
  25. sqlspec/adapters/bigquery/config.py +191 -258
  26. sqlspec/adapters/bigquery/driver.py +474 -646
  27. sqlspec/adapters/duckdb/__init__.py +14 -3
  28. sqlspec/adapters/duckdb/_types.py +12 -0
  29. sqlspec/adapters/duckdb/config.py +415 -351
  30. sqlspec/adapters/duckdb/driver.py +343 -413
  31. sqlspec/adapters/oracledb/__init__.py +19 -5
  32. sqlspec/adapters/oracledb/_types.py +14 -0
  33. sqlspec/adapters/oracledb/config.py +123 -379
  34. sqlspec/adapters/oracledb/driver.py +507 -560
  35. sqlspec/adapters/psqlpy/__init__.py +13 -3
  36. sqlspec/adapters/psqlpy/_types.py +11 -0
  37. sqlspec/adapters/psqlpy/config.py +93 -254
  38. sqlspec/adapters/psqlpy/driver.py +505 -234
  39. sqlspec/adapters/psycopg/__init__.py +19 -5
  40. sqlspec/adapters/psycopg/_types.py +17 -0
  41. sqlspec/adapters/psycopg/config.py +143 -403
  42. sqlspec/adapters/psycopg/driver.py +706 -872
  43. sqlspec/adapters/sqlite/__init__.py +14 -3
  44. sqlspec/adapters/sqlite/_types.py +11 -0
  45. sqlspec/adapters/sqlite/config.py +202 -118
  46. sqlspec/adapters/sqlite/driver.py +264 -303
  47. sqlspec/base.py +105 -9
  48. sqlspec/{statement/builder → builder}/__init__.py +12 -14
  49. sqlspec/{statement/builder → builder}/_base.py +120 -55
  50. sqlspec/{statement/builder → builder}/_column.py +17 -6
  51. sqlspec/{statement/builder → builder}/_ddl.py +46 -79
  52. sqlspec/{statement/builder → builder}/_ddl_utils.py +5 -10
  53. sqlspec/{statement/builder → builder}/_delete.py +6 -25
  54. sqlspec/{statement/builder → builder}/_insert.py +18 -65
  55. sqlspec/builder/_merge.py +56 -0
  56. sqlspec/{statement/builder → builder}/_parsing_utils.py +8 -11
  57. sqlspec/{statement/builder → builder}/_select.py +11 -56
  58. sqlspec/{statement/builder → builder}/_update.py +12 -18
  59. sqlspec/{statement/builder → builder}/mixins/__init__.py +10 -14
  60. sqlspec/{statement/builder → builder}/mixins/_cte_and_set_ops.py +48 -59
  61. sqlspec/{statement/builder → builder}/mixins/_insert_operations.py +34 -18
  62. sqlspec/{statement/builder → builder}/mixins/_join_operations.py +1 -3
  63. sqlspec/{statement/builder → builder}/mixins/_merge_operations.py +19 -9
  64. sqlspec/{statement/builder → builder}/mixins/_order_limit_operations.py +3 -3
  65. sqlspec/{statement/builder → builder}/mixins/_pivot_operations.py +4 -8
  66. sqlspec/{statement/builder → builder}/mixins/_select_operations.py +25 -38
  67. sqlspec/{statement/builder → builder}/mixins/_update_operations.py +15 -16
  68. sqlspec/{statement/builder → builder}/mixins/_where_clause.py +210 -137
  69. sqlspec/cli.py +4 -5
  70. sqlspec/config.py +180 -133
  71. sqlspec/core/__init__.py +63 -0
  72. sqlspec/core/cache.py +873 -0
  73. sqlspec/core/compiler.py +396 -0
  74. sqlspec/core/filters.py +830 -0
  75. sqlspec/core/hashing.py +310 -0
  76. sqlspec/core/parameters.py +1209 -0
  77. sqlspec/core/result.py +664 -0
  78. sqlspec/{statement → core}/splitter.py +321 -191
  79. sqlspec/core/statement.py +666 -0
  80. sqlspec/driver/__init__.py +7 -10
  81. sqlspec/driver/_async.py +387 -176
  82. sqlspec/driver/_common.py +527 -289
  83. sqlspec/driver/_sync.py +390 -172
  84. sqlspec/driver/mixins/__init__.py +2 -19
  85. sqlspec/driver/mixins/_result_tools.py +164 -0
  86. sqlspec/driver/mixins/_sql_translator.py +6 -3
  87. sqlspec/exceptions.py +5 -252
  88. sqlspec/extensions/aiosql/adapter.py +93 -96
  89. sqlspec/extensions/litestar/cli.py +1 -1
  90. sqlspec/extensions/litestar/config.py +0 -1
  91. sqlspec/extensions/litestar/handlers.py +15 -26
  92. sqlspec/extensions/litestar/plugin.py +18 -16
  93. sqlspec/extensions/litestar/providers.py +17 -52
  94. sqlspec/loader.py +424 -105
  95. sqlspec/migrations/__init__.py +12 -0
  96. sqlspec/migrations/base.py +92 -68
  97. sqlspec/migrations/commands.py +24 -106
  98. sqlspec/migrations/loaders.py +402 -0
  99. sqlspec/migrations/runner.py +49 -51
  100. sqlspec/migrations/tracker.py +31 -44
  101. sqlspec/migrations/utils.py +64 -24
  102. sqlspec/protocols.py +7 -183
  103. sqlspec/storage/__init__.py +1 -1
  104. sqlspec/storage/backends/base.py +37 -40
  105. sqlspec/storage/backends/fsspec.py +136 -112
  106. sqlspec/storage/backends/obstore.py +138 -160
  107. sqlspec/storage/capabilities.py +5 -4
  108. sqlspec/storage/registry.py +57 -106
  109. sqlspec/typing.py +136 -115
  110. sqlspec/utils/__init__.py +2 -3
  111. sqlspec/utils/correlation.py +0 -3
  112. sqlspec/utils/deprecation.py +6 -6
  113. sqlspec/utils/fixtures.py +6 -6
  114. sqlspec/utils/logging.py +0 -2
  115. sqlspec/utils/module_loader.py +7 -12
  116. sqlspec/utils/singleton.py +0 -1
  117. sqlspec/utils/sync_tools.py +17 -38
  118. sqlspec/utils/text.py +12 -51
  119. sqlspec/utils/type_guards.py +443 -232
  120. {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/METADATA +7 -2
  121. sqlspec-0.16.0.dist-info/RECORD +134 -0
  122. sqlspec/adapters/adbc/transformers.py +0 -108
  123. sqlspec/driver/connection.py +0 -207
  124. sqlspec/driver/mixins/_cache.py +0 -114
  125. sqlspec/driver/mixins/_csv_writer.py +0 -91
  126. sqlspec/driver/mixins/_pipeline.py +0 -508
  127. sqlspec/driver/mixins/_query_tools.py +0 -796
  128. sqlspec/driver/mixins/_result_utils.py +0 -138
  129. sqlspec/driver/mixins/_storage.py +0 -912
  130. sqlspec/driver/mixins/_type_coercion.py +0 -128
  131. sqlspec/driver/parameters.py +0 -138
  132. sqlspec/statement/__init__.py +0 -21
  133. sqlspec/statement/builder/_merge.py +0 -95
  134. sqlspec/statement/cache.py +0 -50
  135. sqlspec/statement/filters.py +0 -625
  136. sqlspec/statement/parameters.py +0 -956
  137. sqlspec/statement/pipelines/__init__.py +0 -210
  138. sqlspec/statement/pipelines/analyzers/__init__.py +0 -9
  139. sqlspec/statement/pipelines/analyzers/_analyzer.py +0 -646
  140. sqlspec/statement/pipelines/context.py +0 -109
  141. sqlspec/statement/pipelines/transformers/__init__.py +0 -7
  142. sqlspec/statement/pipelines/transformers/_expression_simplifier.py +0 -88
  143. sqlspec/statement/pipelines/transformers/_literal_parameterizer.py +0 -1247
  144. sqlspec/statement/pipelines/transformers/_remove_comments_and_hints.py +0 -76
  145. sqlspec/statement/pipelines/validators/__init__.py +0 -23
  146. sqlspec/statement/pipelines/validators/_dml_safety.py +0 -290
  147. sqlspec/statement/pipelines/validators/_parameter_style.py +0 -370
  148. sqlspec/statement/pipelines/validators/_performance.py +0 -714
  149. sqlspec/statement/pipelines/validators/_security.py +0 -967
  150. sqlspec/statement/result.py +0 -435
  151. sqlspec/statement/sql.py +0 -1774
  152. sqlspec/utils/cached_property.py +0 -25
  153. sqlspec/utils/statement_hashing.py +0 -203
  154. sqlspec-0.14.1.dist-info/RECORD +0 -145
  155. /sqlspec/{statement/builder → builder}/mixins/_delete_operations.py +0 -0
  156. {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/WHEEL +0 -0
  157. {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/entry_points.txt +0 -0
  158. {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/licenses/LICENSE +0 -0
  159. {sqlspec-0.14.1.dist-info → sqlspec-0.16.0.dist-info}/licenses/NOTICE +0 -0
@@ -2,8 +2,6 @@
2
2
  """Application dependency providers generators.
3
3
 
4
4
  This module contains functions to create dependency providers for services and filters.
5
-
6
- You should not have modify this module very often and should only be invoked under normal usage.
7
5
  """
8
6
 
9
7
  import datetime
@@ -16,7 +14,7 @@ from litestar.di import Provide
16
14
  from litestar.params import Dependency, Parameter
17
15
  from typing_extensions import NotRequired
18
16
 
19
- from sqlspec.statement.filters import (
17
+ from sqlspec.core.filters import (
20
18
  BeforeAfterFilter,
21
19
  FilterTypes,
22
20
  InCollectionFilter,
@@ -59,69 +57,44 @@ HashableType = Union[HashableValue, tuple[Any, ...], tuple[tuple[str, Any], ...]
59
57
 
60
58
  class DependencyDefaults:
61
59
  FILTERS_DEPENDENCY_KEY: str = "filters"
62
- """Key for the filters dependency."""
63
60
  CREATED_FILTER_DEPENDENCY_KEY: str = "created_filter"
64
- """Key for the created filter dependency."""
65
61
  ID_FILTER_DEPENDENCY_KEY: str = "id_filter"
66
- """Key for the id filter dependency."""
67
62
  LIMIT_OFFSET_FILTER_DEPENDENCY_KEY: str = "limit_offset_filter"
68
- """Key for the limit offset dependency."""
69
63
  UPDATED_FILTER_DEPENDENCY_KEY: str = "updated_filter"
70
- """Key for the updated filter dependency."""
71
64
  ORDER_BY_FILTER_DEPENDENCY_KEY: str = "order_by_filter"
72
- """Key for the order by dependency."""
73
65
  SEARCH_FILTER_DEPENDENCY_KEY: str = "search_filter"
74
- """Key for the search filter dependency."""
75
66
  DEFAULT_PAGINATION_SIZE: int = 20
76
- """Default pagination size."""
77
67
 
78
68
 
79
69
  DEPENDENCY_DEFAULTS = DependencyDefaults()
80
70
 
81
71
 
82
72
  class FieldNameType(NamedTuple):
83
- """Type for field name and associated type information.
84
-
85
- This allows for specifying both the field name and the expected type for filter values.
86
- """
73
+ """Type for field name and associated type information for filter configuration."""
87
74
 
88
75
  name: str
89
- """Name of the field to filter on."""
90
76
  type_hint: type[Any] = str
91
- """Type of the filter value. Defaults to str."""
92
77
 
93
78
 
94
79
  class FilterConfig(TypedDict):
95
80
  """Configuration for generating dynamic filters."""
96
81
 
97
82
  id_filter: NotRequired[type[Union[UUID, int, str]]]
98
- """Indicates that the id filter should be enabled. When set, the type specified will be used for the :class:`CollectionFilter`."""
99
83
  id_field: NotRequired[str]
100
- """The field on the model that stored the primary key or identifier."""
101
84
  sort_field: NotRequired[str]
102
- """The default field to use for the sort filter."""
103
85
  sort_order: NotRequired[SortOrder]
104
- """The default order to use for the sort filter."""
105
86
  pagination_type: NotRequired[Literal["limit_offset"]]
106
- """When set, pagination is enabled based on the type specified."""
107
87
  pagination_size: NotRequired[int]
108
- """The size of the pagination. Defaults to `DEFAULT_PAGINATION_SIZE`."""
109
88
  search: NotRequired[Union[str, set[str], list[str]]]
110
- """Fields to enable search on. Can be a comma-separated string or a set of field names."""
111
89
  search_ignore_case: NotRequired[bool]
112
- """When set, search is case insensitive by default."""
113
90
  created_at: NotRequired[bool]
114
- """When set, created_at filter is enabled."""
115
91
  updated_at: NotRequired[bool]
116
- """When set, updated_at filter is enabled."""
117
92
  not_in_fields: NotRequired[Union[FieldNameType, set[FieldNameType], list[Union[str, FieldNameType]]]]
118
- """Fields that support not-in collection filters. Can be a single field or a set of fields with type information."""
119
93
  in_fields: NotRequired[Union[FieldNameType, set[FieldNameType], list[Union[str, FieldNameType]]]]
120
- """Fields that support in-collection filters. Can be a single field or a set of fields with type information."""
121
94
 
122
95
 
123
96
  class DependencyCache(metaclass=SingletonMeta):
124
- """Simple dependency cache for the application. This is used to help memoize dependencies that are generated dynamically."""
97
+ """Dependency cache for memoizing dynamically generated dependencies."""
125
98
 
126
99
  def __init__(self) -> None:
127
100
  self.dependencies: dict[Union[int, str], dict[str, Provide]] = {}
@@ -148,9 +121,7 @@ def create_filter_dependencies(
148
121
  Returns:
149
122
  A dependency provider function for the combined filter function.
150
123
  """
151
- cache_key = hash(_make_hashable(config))
152
- deps = dep_cache.get_dependencies(cache_key)
153
- if deps is not None:
124
+ if (deps := dep_cache.get_dependencies(cache_key := hash(_make_hashable(config)))) is not None:
154
125
  return deps
155
126
  deps = _create_statement_filters(config, dep_defaults)
156
127
  dep_cache.add_dependencies(cache_key, deps)
@@ -158,13 +129,7 @@ def create_filter_dependencies(
158
129
 
159
130
 
160
131
  def _make_hashable(value: Any) -> HashableType:
161
- """Convert a value into a hashable type.
162
-
163
- This function converts any value into a hashable type by:
164
- - Converting dictionaries to sorted tuples of (key, value) pairs
165
- - Converting lists and sets to sorted tuples
166
- - Preserving primitive types (str, int, float, bool, None)
167
- - Converting any other type to its string representation
132
+ """Convert a value into a hashable type for caching purposes.
168
133
 
169
134
  Args:
170
135
  value: Any value that needs to be made hashable.
@@ -175,12 +140,12 @@ def _make_hashable(value: Any) -> HashableType:
175
140
  if isinstance(value, dict):
176
141
  items = []
177
142
  for k in sorted(value.keys()): # pyright: ignore
178
- v = value[k] # pyright: ignore
179
- items.append((str(k), _make_hashable(v))) # pyright: ignore
180
- return tuple(items) # pyright: ignore
143
+ v = value[k]
144
+ items.append((str(k), _make_hashable(v)))
145
+ return tuple(items)
181
146
  if isinstance(value, (list, set)):
182
- hashable_items = [_make_hashable(item) for item in value] # pyright: ignore
183
- filtered_items = [item for item in hashable_items if item is not None] # pyright: ignore
147
+ hashable_items = [_make_hashable(item) for item in value]
148
+ filtered_items = [item for item in hashable_items if item is not None]
184
149
  return tuple(sorted(filtered_items, key=str))
185
150
  if isinstance(value, (str, int, float, bool, type(None))):
186
151
  return value
@@ -193,11 +158,11 @@ def _create_statement_filters(
193
158
  """Create filter dependencies based on configuration.
194
159
 
195
160
  Args:
196
- config (FilterConfig): Configuration dictionary specifying which filters to enable
197
- dep_defaults (DependencyDefaults): Dependency defaults to use for the filter dependencies
161
+ config: Configuration dictionary specifying which filters to enable
162
+ dep_defaults: Dependency defaults to use for the filter dependencies
198
163
 
199
164
  Returns:
200
- dict[str, Provide]: Dictionary of filter provider functions
165
+ Dictionary of filter provider functions
201
166
  """
202
167
  filters: dict[str, Provide] = {}
203
168
 
@@ -343,13 +308,13 @@ def _create_statement_filters(
343
308
 
344
309
 
345
310
  def _create_filter_aggregate_function(config: FilterConfig) -> Callable[..., list[FilterTypes]]:
346
- """Create a filter function based on the provided configuration.
311
+ """Create filter aggregation function based on configuration.
347
312
 
348
313
  Args:
349
314
  config: The filter configuration.
350
315
 
351
316
  Returns:
352
- A function that returns a list of filters based on the configuration.
317
+ Function that returns list of configured filters.
353
318
  """
354
319
 
355
320
  parameters: dict[str, inspect.Parameter] = {}
@@ -432,13 +397,13 @@ def _create_filter_aggregate_function(config: FilterConfig) -> Callable[..., lis
432
397
  annotations[f"{field_def.name}_in_filter"] = InCollectionFilter[field_def.type_hint] # type: ignore
433
398
 
434
399
  def provide_filters(**kwargs: FilterTypes) -> list[FilterTypes]:
435
- """Provide filter dependencies based on configuration.
400
+ """Aggregate filter dependencies based on configuration.
436
401
 
437
402
  Args:
438
403
  **kwargs: Filter parameters dynamically provided based on configuration.
439
404
 
440
405
  Returns:
441
- list[FilterTypes]: List of configured filters.
406
+ List of configured filters.
442
407
  """
443
408
  filters: list[FilterTypes] = []
444
409
  if id_filter := kwargs.get("id_filter"):