sqlobjects 2.1.1__tar.gz → 2.2.0__tar.gz
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.
- {sqlobjects-2.1.1/sqlobjects.egg-info → sqlobjects-2.2.0}/PKG-INFO +2 -2
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/pyproject.toml +8 -2
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/__init__.py +1 -1
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/_compat.py +49 -2
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/aggregate.py +6 -3
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/subquery.py +5 -23
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/metadata.py +2 -14
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/queries/builder.py +5 -1
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/queries/dialect.py +7 -2
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/queries/executor.py +5 -17
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/session.py +2 -1
- {sqlobjects-2.1.1 → sqlobjects-2.2.0/sqlobjects.egg-info}/PKG-INFO +2 -2
- sqlobjects-2.2.0/sqlobjects.egg-info/requires.txt +4 -0
- sqlobjects-2.1.1/sqlobjects.egg-info/requires.txt +0 -4
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/LICENSE +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/README.md +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/docs/rules/01-database-session-guide.md +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/docs/rules/02-model-definition-guide.md +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/docs/rules/03-query-operations-guide.md +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/docs/rules/04-crud-operations-guide.md +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/docs/rules/05-relationships-guide.md +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/docs/rules/06-validation-signals-guide.md +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/docs/rules/07-performance-guide.md +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/docs/rules/README.md +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/setup.cfg +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/_install_rules.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/cascade.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/contrib/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/contrib/asgi.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/contrib/fastapi.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/database/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/database/config.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/database/manager.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/exceptions.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/base.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/cte.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/explain.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/function.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/mixins.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/scalar.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/terminal.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/expressions/window.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/core.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/functions.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/proxies.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/relations/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/relations/descriptors.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/relations/managers.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/relations/prefetch.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/relations/strategies.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/relations/utils.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/shortcuts.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/types/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/types/base.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/types/comparators.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/types/registry.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/fields/utils.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/internal/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/internal/operations.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/internal/results.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/mixins.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/model.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/objects/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/objects/bulk.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/objects/core.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/objects/upsert.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/py.typed +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/queries/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/queryset.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/signals.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/sql_logging.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/utils/__init__.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/utils/inspect.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/utils/naming.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/utils/pattern.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects/validators.py +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects.egg-info/SOURCES.txt +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects.egg-info/dependency_links.txt +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects.egg-info/entry_points.txt +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/sqlobjects.egg-info/top_level.txt +0 -0
- {sqlobjects-2.1.1 → sqlobjects-2.2.0}/tests/test_config.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqlobjects
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Django-style async ORM library based on SQLAlchemy with chainable queries, Q objects, and relationship loading
|
|
5
5
|
Author-email: XtraVisions <gitadmin@xtravisions.com>, Chen Hao <chenhao@xtravisions.com>
|
|
6
6
|
Maintainer-email: XtraVisions <gitadmin@xtravisions.com>, Chen Hao <chenhao@xtravisions.com>
|
|
@@ -24,7 +24,7 @@ Classifier: Typing :: Typed
|
|
|
24
24
|
Requires-Python: >=3.12
|
|
25
25
|
Description-Content-Type: text/markdown
|
|
26
26
|
License-File: LICENSE
|
|
27
|
-
Requires-Dist: sqlalchemy[asyncio]<2.2,>=2.0.
|
|
27
|
+
Requires-Dist: sqlalchemy[asyncio]<2.2,>=2.0.45
|
|
28
28
|
Provides-Extra: migrations
|
|
29
29
|
Requires-Dist: alembic>=1.16.5; extra == "migrations"
|
|
30
30
|
Dynamic: license-file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sqlobjects"
|
|
3
|
-
version = "2.
|
|
3
|
+
version = "2.2.0"
|
|
4
4
|
description = "Django-style async ORM library based on SQLAlchemy with chainable queries, Q objects, and relationship loading"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -34,7 +34,9 @@ classifiers = [
|
|
|
34
34
|
]
|
|
35
35
|
requires-python = ">=3.12"
|
|
36
36
|
dependencies = [
|
|
37
|
-
|
|
37
|
+
# 2.0.45 is the first release that emits FOR SHARE on MySQL 8; before it,
|
|
38
|
+
# select_for_share(nowait/skip_locked) is a syntax error there.
|
|
39
|
+
"sqlalchemy[asyncio]>=2.0.45,<2.2",
|
|
38
40
|
]
|
|
39
41
|
|
|
40
42
|
[project.optional-dependencies]
|
|
@@ -149,3 +151,7 @@ addopts = [
|
|
|
149
151
|
"--strict-markers",
|
|
150
152
|
"-v"
|
|
151
153
|
]
|
|
154
|
+
# A SQLAlchemy deprecation is the early warning for the next release series.
|
|
155
|
+
filterwarnings = [
|
|
156
|
+
"error::sqlalchemy.exc.SADeprecationWarning",
|
|
157
|
+
]
|
|
@@ -9,10 +9,24 @@ Supported series: 2.0 (>= 2.0.44) and 2.1.
|
|
|
9
9
|
|
|
10
10
|
from typing import Any
|
|
11
11
|
|
|
12
|
-
from sqlalchemy import ForeignKey
|
|
12
|
+
from sqlalchemy import ForeignKey, Index
|
|
13
|
+
from sqlalchemy.dialects.postgresql import ext as _postgresql_ext
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
# Added in 2.1 as the replacement for ``select.distinct(*columns)``; absent on 2.0.
|
|
17
|
+
_distinct_on: Any = getattr(_postgresql_ext, "distinct_on", None)
|
|
18
|
+
_DistinctOnClause: Any = getattr(_postgresql_ext, "DistinctOnClause", None)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
__all__ = [
|
|
22
|
+
"apply_distinct_on",
|
|
23
|
+
"foreign_key_copy_target",
|
|
24
|
+
"foreign_key_target_tokens",
|
|
25
|
+
"has_distinct_on",
|
|
26
|
+
"index_has_ddl_if",
|
|
27
|
+
"retarget_foreign_key",
|
|
28
|
+
"select_has_for_update",
|
|
29
|
+
]
|
|
16
30
|
|
|
17
31
|
# SQLAlchemy 2.1 stores a name-based foreign key target as a
|
|
18
32
|
# ``ForeignKeyTarget(schema, table_name, column_name)`` tuple exposed through
|
|
@@ -59,3 +73,36 @@ def retarget_foreign_key(fk: ForeignKey, table_name: str) -> None:
|
|
|
59
73
|
raw._colspec = f"{prefix}{table_name}.{column_name}" # noqa: SLF001
|
|
60
74
|
# Memoized on 2.0; drop it so the new target is parsed again.
|
|
61
75
|
raw.__dict__.pop("_column_tokens", None)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def apply_distinct_on(query: Any, columns: list[Any]) -> Any:
|
|
79
|
+
"""Apply PostgreSQL ``DISTINCT ON (columns)`` to a SELECT.
|
|
80
|
+
|
|
81
|
+
2.1 deprecates ``select.distinct(*columns)`` in favour of the
|
|
82
|
+
``postgresql.distinct_on`` extension; 2.0 only has the former.
|
|
83
|
+
"""
|
|
84
|
+
if _distinct_on is not None:
|
|
85
|
+
return query.ext(_distinct_on(*columns))
|
|
86
|
+
return query.distinct(*columns)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def has_distinct_on(element: Any) -> bool:
|
|
90
|
+
"""Whether a statement element is, or directly carries, a ``DISTINCT ON`` clause.
|
|
91
|
+
|
|
92
|
+
Covers both spellings: ``select.distinct(*columns)`` stores the columns on
|
|
93
|
+
the SELECT, the 2.1 extension is a separate element inside the statement.
|
|
94
|
+
Call it for every element of ``visitors.iterate(statement)``.
|
|
95
|
+
"""
|
|
96
|
+
if _DistinctOnClause is not None and isinstance(element, _DistinctOnClause):
|
|
97
|
+
return True
|
|
98
|
+
return bool(getattr(element, "_distinct_on", ()))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def select_has_for_update(query: Any) -> bool:
|
|
102
|
+
"""Whether a SELECT was built with ``with_for_update()``; there is no public accessor."""
|
|
103
|
+
return getattr(query, "_for_update_arg", None) is not None
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def index_has_ddl_if(index: Index) -> bool:
|
|
107
|
+
"""Whether an index has conditional DDL set through ``Index.ddl_if()``; there is no public accessor."""
|
|
108
|
+
return getattr(index, "_ddl_if", None) is not None
|
|
@@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Any
|
|
|
4
4
|
|
|
5
5
|
from sqlalchemy import false, select
|
|
6
6
|
from sqlalchemy.sql import visitors
|
|
7
|
-
from sqlalchemy.sql.elements import BindParameter, ColumnClause, ColumnElement
|
|
7
|
+
from sqlalchemy.sql.elements import BindParameter, ColumnClause, ColumnElement, False_, Null, True_
|
|
8
8
|
from sqlalchemy.sql.selectable import ScalarSelect
|
|
9
9
|
|
|
10
10
|
from ..exceptions import QueryError
|
|
@@ -14,6 +14,9 @@ from .base import QueryExpression
|
|
|
14
14
|
if TYPE_CHECKING:
|
|
15
15
|
from ..queries import QueryBuilder
|
|
16
16
|
|
|
17
|
+
# NULL, TRUE and FALSE: constants that are not bind parameters.
|
|
18
|
+
_SINGLETON_CONSTANTS = (Null, True_, False_)
|
|
19
|
+
|
|
17
20
|
|
|
18
21
|
class AggregateExpression(QueryExpression[dict[str, Any]]):
|
|
19
22
|
"""Aggregate matching rows, with one statement shared by all evaluation paths."""
|
|
@@ -64,7 +67,7 @@ class AggregateExpression(QueryExpression[dict[str, Any]]):
|
|
|
64
67
|
grouped
|
|
65
68
|
and isinstance(element, ColumnElement)
|
|
66
69
|
and not isinstance(element, BindParameter)
|
|
67
|
-
and not element
|
|
70
|
+
and not isinstance(element, _SINGLETON_CONSTANTS)
|
|
68
71
|
):
|
|
69
72
|
for key, alias in grouping_keys:
|
|
70
73
|
if element.compare(key):
|
|
@@ -147,7 +150,7 @@ class AggregateExpression(QueryExpression[dict[str, Any]]):
|
|
|
147
150
|
builder.annotations[alias] = expression
|
|
148
151
|
fields.append(alias)
|
|
149
152
|
grouping_keys.append((expression, alias))
|
|
150
|
-
if isinstance(expression, BindParameter)
|
|
153
|
+
if isinstance(expression, (BindParameter, *_SINGLETON_CONSTANTS)):
|
|
151
154
|
# MySQL interprets GROUP BY 1 as a select-list ordinal. Refer to
|
|
152
155
|
# the projected constant by alias to preserve one constant group.
|
|
153
156
|
builder.group_clauses[index] = alias
|
|
@@ -59,8 +59,8 @@ class SubqueryExpression(ColumnElement):
|
|
|
59
59
|
def _infer_type(self) -> str:
|
|
60
60
|
"""Automatically infer the appropriate subquery type based on query structure.
|
|
61
61
|
|
|
62
|
-
Analyzes query characteristics including column count
|
|
63
|
-
|
|
62
|
+
Analyzes query characteristics including column count and aggregate
|
|
63
|
+
functions to determine the most suitable subquery type.
|
|
64
64
|
|
|
65
65
|
Returns:
|
|
66
66
|
Inferred subquery type ('scalar', 'table', or 'exists')
|
|
@@ -68,23 +68,15 @@ class SubqueryExpression(ColumnElement):
|
|
|
68
68
|
try:
|
|
69
69
|
structure = self._analyze_query_structure()
|
|
70
70
|
|
|
71
|
-
# Rule 1:
|
|
72
|
-
if (
|
|
73
|
-
structure["has_single_column"]
|
|
74
|
-
and structure["has_aggregates"]
|
|
75
|
-
and (structure["has_limit_one"] or structure["is_count_query"])
|
|
76
|
-
):
|
|
77
|
-
return "scalar"
|
|
78
|
-
|
|
79
|
-
# Rule 2: Single column aggregate query (commonly used for comparisons)
|
|
71
|
+
# Rule 1: Single column aggregate query (commonly used for comparisons)
|
|
80
72
|
if structure["has_single_column"] and structure["has_aggregates"]:
|
|
81
73
|
return "scalar"
|
|
82
74
|
|
|
83
|
-
# Rule
|
|
75
|
+
# Rule 2: Multi-column queries default to table subquery
|
|
84
76
|
if structure["column_count"] > 1:
|
|
85
77
|
return "table"
|
|
86
78
|
|
|
87
|
-
# Rule
|
|
79
|
+
# Rule 3: Single column non-aggregate query (e.g., ID lists)
|
|
88
80
|
if structure["has_single_column"] and not structure["has_aggregates"]:
|
|
89
81
|
return "table" # For IN conditions
|
|
90
82
|
|
|
@@ -109,10 +101,8 @@ class SubqueryExpression(ColumnElement):
|
|
|
109
101
|
"select_columns": [],
|
|
110
102
|
"has_aggregates": False,
|
|
111
103
|
"has_single_column": False,
|
|
112
|
-
"has_limit_one": False,
|
|
113
104
|
"has_annotations": False,
|
|
114
105
|
"column_count": 0,
|
|
115
|
-
"is_count_query": False,
|
|
116
106
|
}
|
|
117
107
|
|
|
118
108
|
try:
|
|
@@ -127,14 +117,6 @@ class SubqueryExpression(ColumnElement):
|
|
|
127
117
|
aggregate_keywords = ["count(", "sum(", "avg(", "max(", "min("]
|
|
128
118
|
analysis["has_aggregates"] = any(keyword in query_str for keyword in aggregate_keywords)
|
|
129
119
|
|
|
130
|
-
# Analyze LIMIT clause
|
|
131
|
-
analysis["has_limit_one"] = (
|
|
132
|
-
hasattr(self.query, "_limit") and self.query._limit is not None and self.query._limit == 1 # noqa
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
# Detect count queries
|
|
136
|
-
analysis["is_count_query"] = "count(" in query_str
|
|
137
|
-
|
|
138
120
|
except Exception: # noqa
|
|
139
121
|
# Return safe defaults when analysis fails
|
|
140
122
|
pass
|
|
@@ -8,7 +8,7 @@ from sqlalchemy import MetaData as SqlAlchemyMetaData
|
|
|
8
8
|
from sqlalchemy.exc import CompileError
|
|
9
9
|
from sqlalchemy.sql.elements import conv
|
|
10
10
|
|
|
11
|
-
from ._compat import foreign_key_target_tokens, retarget_foreign_key
|
|
11
|
+
from ._compat import foreign_key_target_tokens, index_has_ddl_if, retarget_foreign_key
|
|
12
12
|
from .fields import ColumnAttribute
|
|
13
13
|
from .fields.relations import M2MTable, RelationshipDescriptor, RelationshipResolver
|
|
14
14
|
from .fields.utils import get_column_from_field, is_field_definition
|
|
@@ -552,14 +552,6 @@ class ModelProcessor(type):
|
|
|
552
552
|
"""
|
|
553
553
|
from sqlalchemy import Table
|
|
554
554
|
|
|
555
|
-
# Collect fields with explicit indexes to avoid duplicates
|
|
556
|
-
indexed_fields = set()
|
|
557
|
-
for idx in config.indexes:
|
|
558
|
-
if hasattr(idx, "_columns"):
|
|
559
|
-
for col in idx._columns:
|
|
560
|
-
if isinstance(col, str):
|
|
561
|
-
indexed_fields.add(col.split(".")[-1])
|
|
562
|
-
|
|
563
555
|
# Collect column definitions and relationship fields
|
|
564
556
|
columns = []
|
|
565
557
|
relationships = {}
|
|
@@ -577,10 +569,6 @@ class ModelProcessor(type):
|
|
|
577
569
|
# Use create_table_column method to get independent Column instance
|
|
578
570
|
if hasattr(column_attr, "create_table_column"):
|
|
579
571
|
column = column_attr.create_table_column(name)
|
|
580
|
-
# Clear index attributes if field has explicit index
|
|
581
|
-
if name in indexed_fields:
|
|
582
|
-
column.index = False
|
|
583
|
-
column.unique = False
|
|
584
572
|
else:
|
|
585
573
|
# Fallback for non-ColumnAttribute fields
|
|
586
574
|
column = column_attr
|
|
@@ -657,7 +645,7 @@ class ModelProcessor(type):
|
|
|
657
645
|
for idx in list(table.indexes):
|
|
658
646
|
# Conditional DDL can produce different schemas per dialect or
|
|
659
647
|
# callback result. Keep it intact instead of evaluating callbacks.
|
|
660
|
-
if
|
|
648
|
+
if index_has_ddl_if(idx):
|
|
661
649
|
continue
|
|
662
650
|
try:
|
|
663
651
|
expressions, options = expression_sig(idx), dialect_sig(idx)
|
|
@@ -11,6 +11,7 @@ from sqlalchemy import (
|
|
|
11
11
|
)
|
|
12
12
|
from sqlalchemy.sql.selectable import Subquery
|
|
13
13
|
|
|
14
|
+
from .._compat import apply_distinct_on
|
|
14
15
|
from ..exceptions import QueryError
|
|
15
16
|
|
|
16
17
|
|
|
@@ -517,7 +518,10 @@ class QueryBuilder:
|
|
|
517
518
|
unknown = [field for field in self.distinct_fields if field not in table.c]
|
|
518
519
|
if unknown:
|
|
519
520
|
raise QueryError(f"Unknown DISTINCT field(s): {unknown}")
|
|
520
|
-
|
|
521
|
+
if self.distinct_fields:
|
|
522
|
+
query = apply_distinct_on(query, [table.c[field] for field in self.distinct_fields])
|
|
523
|
+
else:
|
|
524
|
+
query = query.distinct()
|
|
521
525
|
|
|
522
526
|
# Apply annotations (values mode already selected the requested ones)
|
|
523
527
|
if self.annotations and values_fields is None:
|
|
@@ -153,8 +153,13 @@ class MySQLDialect(BaseDialect):
|
|
|
153
153
|
return f"EXPLAIN {sql}"
|
|
154
154
|
|
|
155
155
|
def parse_explain_result(self, rows: Sequence) -> str:
|
|
156
|
-
"""Parse MySQL EXPLAIN result.
|
|
157
|
-
|
|
156
|
+
"""Parse MySQL EXPLAIN result.
|
|
157
|
+
|
|
158
|
+
Plain EXPLAIN returns one row per table with the plan spread over
|
|
159
|
+
several columns (id, select_type, table, type, ...); EXPLAIN ANALYZE
|
|
160
|
+
returns the whole plan in a single column.
|
|
161
|
+
"""
|
|
162
|
+
return "\n".join(" | ".join(str(value) for value in row) for row in rows)
|
|
158
163
|
|
|
159
164
|
|
|
160
165
|
class SQLiteDialect(BaseDialect):
|
|
@@ -10,6 +10,8 @@ from sqlalchemy import (
|
|
|
10
10
|
update,
|
|
11
11
|
)
|
|
12
12
|
|
|
13
|
+
from .._compat import select_has_for_update
|
|
14
|
+
|
|
13
15
|
|
|
14
16
|
_T = TypeVar("_T")
|
|
15
17
|
|
|
@@ -112,7 +114,7 @@ class QueryExecutor:
|
|
|
112
114
|
raise ValueError("chunk_size must be positive")
|
|
113
115
|
session = self._get_session("all")
|
|
114
116
|
owned = session.readonly or session.auto_commit
|
|
115
|
-
if owned and
|
|
117
|
+
if owned and select_has_for_update(query) and session.bind.dialect.name != "sqlite":
|
|
116
118
|
from ..exceptions import TransactionError
|
|
117
119
|
|
|
118
120
|
raise TransactionError("select_for_update/select_for_share requires an explicit transaction")
|
|
@@ -195,7 +197,7 @@ class QueryExecutor:
|
|
|
195
197
|
return select(func.count()).select_from(query.order_by(None).subquery())
|
|
196
198
|
elif query_type == "exists":
|
|
197
199
|
return select(exists(query))
|
|
198
|
-
if query_type not in {"update", "delete"
|
|
200
|
+
if query_type not in {"update", "delete"} or kwargs.get("prebuilt"):
|
|
199
201
|
return query
|
|
200
202
|
|
|
201
203
|
froms = query.get_final_froms()
|
|
@@ -212,20 +214,6 @@ class QueryExecutor:
|
|
|
212
214
|
if query.whereclause is not None:
|
|
213
215
|
delete_query = delete_query.where(query.whereclause)
|
|
214
216
|
return delete_query
|
|
215
|
-
elif query_type in ("values", "values_list"):
|
|
216
|
-
fields = kwargs.get("fields", [])
|
|
217
|
-
if fields:
|
|
218
|
-
table = from_table
|
|
219
|
-
columns = [table.c[field] for field in fields if field in table.c]
|
|
220
|
-
new_query = select(*columns)
|
|
221
|
-
if query.whereclause is not None:
|
|
222
|
-
new_query = new_query.where(query.whereclause)
|
|
223
|
-
if hasattr(query, "_order_by") and query._order_by: # noqa
|
|
224
|
-
new_query = new_query.order_by(*query._order_by) # noqa
|
|
225
|
-
return new_query
|
|
226
|
-
return query
|
|
227
|
-
else: # "all"
|
|
228
|
-
return query
|
|
229
217
|
|
|
230
218
|
async def _execute_query(
|
|
231
219
|
self,
|
|
@@ -249,7 +237,7 @@ class QueryExecutor:
|
|
|
249
237
|
else: # exists
|
|
250
238
|
return False
|
|
251
239
|
|
|
252
|
-
if
|
|
240
|
+
if select_has_for_update(query) and session.bind.dialect.name != "sqlite":
|
|
253
241
|
if session.readonly or session.auto_commit:
|
|
254
242
|
from ..exceptions import TransactionError
|
|
255
243
|
|
|
@@ -14,6 +14,7 @@ from sqlalchemy.exc import SQLAlchemyError
|
|
|
14
14
|
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncResult, AsyncTransaction
|
|
15
15
|
from sqlalchemy.sql import ClauseElement, visitors
|
|
16
16
|
|
|
17
|
+
from ._compat import has_distinct_on
|
|
17
18
|
from .database.manager import get_database, get_default
|
|
18
19
|
from .exceptions import QueryError, TransactionError, convert_sqlalchemy_error
|
|
19
20
|
|
|
@@ -120,7 +121,7 @@ class AsyncSession:
|
|
|
120
121
|
return
|
|
121
122
|
# Check nested SELECTs too: counts, scalar subqueries and CTEs must not
|
|
122
123
|
# silently lose DISTINCT ON when SQLAlchemy compiles another dialect.
|
|
123
|
-
if any(
|
|
124
|
+
if any(has_distinct_on(part) for part in visitors.iterate(statement)):
|
|
124
125
|
raise QueryError(
|
|
125
126
|
"distinct(*fields) requires PostgreSQL; use distinct() with values()/values_list() instead"
|
|
126
127
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sqlobjects
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: Django-style async ORM library based on SQLAlchemy with chainable queries, Q objects, and relationship loading
|
|
5
5
|
Author-email: XtraVisions <gitadmin@xtravisions.com>, Chen Hao <chenhao@xtravisions.com>
|
|
6
6
|
Maintainer-email: XtraVisions <gitadmin@xtravisions.com>, Chen Hao <chenhao@xtravisions.com>
|
|
@@ -24,7 +24,7 @@ Classifier: Typing :: Typed
|
|
|
24
24
|
Requires-Python: >=3.12
|
|
25
25
|
Description-Content-Type: text/markdown
|
|
26
26
|
License-File: LICENSE
|
|
27
|
-
Requires-Dist: sqlalchemy[asyncio]<2.2,>=2.0.
|
|
27
|
+
Requires-Dist: sqlalchemy[asyncio]<2.2,>=2.0.45
|
|
28
28
|
Provides-Extra: migrations
|
|
29
29
|
Requires-Dist: alembic>=1.16.5; extra == "migrations"
|
|
30
30
|
Dynamic: license-file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|