ormlambda 3.12.2__py3-none-any.whl → 3.34.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.
- ormlambda/__init__.py +2 -0
- ormlambda/caster/__init__.py +1 -1
- ormlambda/caster/caster.py +29 -12
- ormlambda/common/abstract_classes/clause_info_converter.py +4 -12
- ormlambda/common/abstract_classes/decomposition_query.py +17 -2
- ormlambda/common/abstract_classes/non_query_base.py +9 -7
- ormlambda/common/abstract_classes/query_base.py +3 -1
- ormlambda/common/errors/__init__.py +29 -0
- ormlambda/common/interfaces/IQueryCommand.py +6 -2
- ormlambda/dialects/__init__.py +39 -0
- ormlambda/dialects/default/__init__.py +1 -0
- ormlambda/dialects/default/base.py +39 -0
- ormlambda/dialects/interface/__init__.py +1 -0
- ormlambda/dialects/interface/dialect.py +78 -0
- ormlambda/dialects/mysql/__init__.py +38 -0
- ormlambda/dialects/mysql/base.py +388 -0
- ormlambda/dialects/mysql/caster/caster.py +39 -0
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/__init__.py +1 -0
- ormlambda/dialects/mysql/caster/types/boolean.py +35 -0
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/bytes.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/datetime.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/float.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/int.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/iterable.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/none.py +8 -7
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/point.py +4 -4
- ormlambda/{databases/my_sql → dialects/mysql}/caster/types/string.py +7 -7
- ormlambda/{databases/my_sql → dialects/mysql}/clauses/ST_AsText.py +8 -7
- ormlambda/{databases/my_sql → dialects/mysql}/clauses/ST_Contains.py +10 -5
- ormlambda/dialects/mysql/clauses/__init__.py +13 -0
- ormlambda/dialects/mysql/clauses/count.py +33 -0
- ormlambda/dialects/mysql/clauses/delete.py +9 -0
- ormlambda/dialects/mysql/clauses/group_by.py +17 -0
- ormlambda/dialects/mysql/clauses/having.py +12 -0
- ormlambda/dialects/mysql/clauses/insert.py +9 -0
- ormlambda/dialects/mysql/clauses/joins.py +14 -0
- ormlambda/dialects/mysql/clauses/limit.py +6 -0
- ormlambda/dialects/mysql/clauses/offset.py +6 -0
- ormlambda/dialects/mysql/clauses/order.py +8 -0
- ormlambda/dialects/mysql/clauses/update.py +8 -0
- ormlambda/dialects/mysql/clauses/upsert.py +9 -0
- ormlambda/dialects/mysql/clauses/where.py +7 -0
- ormlambda/dialects/mysql/mysqlconnector.py +46 -0
- ormlambda/dialects/mysql/repository/__init__.py +1 -0
- ormlambda/dialects/mysql/repository/repository.py +212 -0
- ormlambda/dialects/mysql/types.py +732 -0
- ormlambda/dialects/sqlite/__init__.py +5 -0
- ormlambda/dialects/sqlite/base.py +47 -0
- ormlambda/dialects/sqlite/pysqlite.py +32 -0
- ormlambda/engine/__init__.py +1 -0
- ormlambda/engine/base.py +77 -0
- ormlambda/engine/create.py +9 -23
- ormlambda/engine/url.py +31 -19
- ormlambda/env.py +30 -0
- ormlambda/errors.py +17 -0
- ormlambda/model/base_model.py +7 -9
- ormlambda/repository/base_repository.py +36 -5
- ormlambda/repository/interfaces/IRepositoryBase.py +119 -12
- ormlambda/repository/response.py +134 -0
- ormlambda/sql/clause_info/aggregate_function_base.py +19 -9
- ormlambda/sql/clause_info/clause_info.py +34 -17
- ormlambda/sql/clauses/__init__.py +14 -0
- ormlambda/{databases/my_sql → sql}/clauses/alias.py +23 -6
- ormlambda/{databases/my_sql → sql}/clauses/count.py +15 -1
- ormlambda/{databases/my_sql → sql}/clauses/delete.py +22 -7
- ormlambda/sql/clauses/group_by.py +30 -0
- ormlambda/{databases/my_sql → sql}/clauses/having.py +7 -2
- ormlambda/{databases/my_sql → sql}/clauses/insert.py +16 -9
- ormlambda/sql/clauses/interfaces/__init__.py +5 -0
- ormlambda/{components → sql/clauses}/join/join_context.py +15 -7
- ormlambda/{databases/my_sql → sql}/clauses/joins.py +29 -19
- ormlambda/sql/clauses/limit.py +15 -0
- ormlambda/sql/clauses/offset.py +15 -0
- ormlambda/{databases/my_sql → sql}/clauses/order.py +14 -24
- ormlambda/{databases/my_sql → sql}/clauses/select.py +12 -13
- ormlambda/{databases/my_sql → sql}/clauses/update.py +24 -11
- ormlambda/{databases/my_sql → sql}/clauses/upsert.py +17 -12
- ormlambda/{databases/my_sql → sql}/clauses/where.py +28 -8
- ormlambda/sql/column/__init__.py +1 -0
- ormlambda/sql/{column.py → column/column.py} +82 -22
- ormlambda/sql/comparer.py +51 -37
- ormlambda/sql/compiler.py +668 -0
- ormlambda/sql/ddl.py +82 -0
- ormlambda/sql/elements.py +36 -0
- ormlambda/sql/foreign_key.py +61 -39
- ormlambda/{databases/my_sql → sql}/functions/concat.py +13 -5
- ormlambda/{databases/my_sql → sql}/functions/max.py +9 -4
- ormlambda/{databases/my_sql → sql}/functions/min.py +9 -13
- ormlambda/{databases/my_sql → sql}/functions/sum.py +8 -10
- ormlambda/sql/sqltypes.py +647 -0
- ormlambda/sql/table/__init__.py +1 -1
- ormlambda/sql/table/table.py +175 -0
- ormlambda/sql/table/table_constructor.py +1 -208
- ormlambda/sql/type_api.py +35 -0
- ormlambda/sql/types.py +3 -1
- ormlambda/sql/visitors.py +74 -0
- ormlambda/statements/__init__.py +1 -0
- ormlambda/statements/base_statement.py +28 -38
- ormlambda/statements/interfaces/IStatements.py +8 -4
- ormlambda/{databases/my_sql → statements}/query_builder.py +35 -30
- ormlambda/{databases/my_sql → statements}/statements.py +57 -61
- ormlambda/statements/types.py +2 -2
- ormlambda/types/__init__.py +24 -0
- ormlambda/types/metadata.py +42 -0
- ormlambda/util/__init__.py +87 -0
- ormlambda/{utils → util}/module_tree/dynamic_module.py +1 -1
- ormlambda/util/plugin_loader.py +32 -0
- ormlambda/util/typing.py +6 -0
- ormlambda-3.34.0.dist-info/AUTHORS +32 -0
- {ormlambda-3.12.2.dist-info → ormlambda-3.34.0.dist-info}/METADATA +1 -1
- ormlambda-3.34.0.dist-info/RECORD +152 -0
- ormlambda/components/__init__.py +0 -4
- ormlambda/components/delete/__init__.py +0 -2
- ormlambda/components/delete/abstract_delete.py +0 -17
- ormlambda/components/insert/__init__.py +0 -2
- ormlambda/components/insert/abstract_insert.py +0 -25
- ormlambda/components/select/__init__.py +0 -1
- ormlambda/components/update/__init__.py +0 -2
- ormlambda/components/update/abstract_update.py +0 -29
- ormlambda/components/upsert/__init__.py +0 -2
- ormlambda/components/upsert/abstract_upsert.py +0 -25
- ormlambda/databases/__init__.py +0 -5
- ormlambda/databases/my_sql/__init__.py +0 -4
- ormlambda/databases/my_sql/caster/caster.py +0 -39
- ormlambda/databases/my_sql/clauses/__init__.py +0 -20
- ormlambda/databases/my_sql/clauses/create_database.py +0 -35
- ormlambda/databases/my_sql/clauses/drop_database.py +0 -17
- ormlambda/databases/my_sql/clauses/drop_table.py +0 -26
- ormlambda/databases/my_sql/clauses/group_by.py +0 -30
- ormlambda/databases/my_sql/clauses/limit.py +0 -17
- ormlambda/databases/my_sql/clauses/offset.py +0 -17
- ormlambda/databases/my_sql/repository/__init__.py +0 -1
- ormlambda/databases/my_sql/repository/repository.py +0 -351
- ormlambda/engine/template.py +0 -47
- ormlambda/sql/dtypes.py +0 -94
- ormlambda/utils/__init__.py +0 -1
- ormlambda-3.12.2.dist-info/RECORD +0 -125
- /ormlambda/{databases/my_sql → dialects/mysql}/caster/__init__.py +0 -0
- /ormlambda/{databases/my_sql/types.py → dialects/mysql/repository/pool_types.py} +0 -0
- /ormlambda/{components/delete → sql/clauses/interfaces}/IDelete.py +0 -0
- /ormlambda/{components/insert → sql/clauses/interfaces}/IInsert.py +0 -0
- /ormlambda/{components/select → sql/clauses/interfaces}/ISelect.py +0 -0
- /ormlambda/{components/update → sql/clauses/interfaces}/IUpdate.py +0 -0
- /ormlambda/{components/upsert → sql/clauses/interfaces}/IUpsert.py +0 -0
- /ormlambda/{components → sql/clauses}/join/__init__.py +0 -0
- /ormlambda/{databases/my_sql → sql}/functions/__init__.py +0 -0
- /ormlambda/{utils → util}/module_tree/__init__.py +0 -0
- /ormlambda/{utils → util}/module_tree/dfs_traversal.py +0 -0
- {ormlambda-3.12.2.dist-info → ormlambda-3.34.0.dist-info}/LICENSE +0 -0
- {ormlambda-3.12.2.dist-info → ormlambda-3.34.0.dist-info}/WHEEL +0 -0
ormlambda/sql/ddl.py
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import TYPE_CHECKING
|
3
|
+
from .elements import ClauseElement
|
4
|
+
|
5
|
+
if TYPE_CHECKING:
|
6
|
+
from ormlambda import URL
|
7
|
+
from ormlambda.dialects.interface.dialect import Dialect
|
8
|
+
from ormlambda import Column
|
9
|
+
from ormlambda import Table
|
10
|
+
|
11
|
+
|
12
|
+
class BaseDDLElement(ClauseElement):
|
13
|
+
"""
|
14
|
+
Base class for all DDL elements.
|
15
|
+
"""
|
16
|
+
|
17
|
+
__visit_name__ = "ddl_element"
|
18
|
+
|
19
|
+
def _compiler(self, dialect: Dialect, **kw) -> str:
|
20
|
+
"""
|
21
|
+
Compile the DDL element into a SQL string.
|
22
|
+
"""
|
23
|
+
return dialect.ddl_compiler(dialect, self, **kw)
|
24
|
+
|
25
|
+
|
26
|
+
class CreateDropTable:
|
27
|
+
def __init__(self, element: Table):
|
28
|
+
self.element = element
|
29
|
+
self.columns = [CreateColumn(c) for c in element.get_columns()]
|
30
|
+
|
31
|
+
|
32
|
+
class CreateTable(CreateDropTable, BaseDDLElement):
|
33
|
+
"""
|
34
|
+
Class representing a CREATE TABLE statement.
|
35
|
+
"""
|
36
|
+
|
37
|
+
__visit_name__ = "create_table"
|
38
|
+
|
39
|
+
|
40
|
+
class DropTable(CreateDropTable, BaseDDLElement):
|
41
|
+
__visit_name__ = "drop_table"
|
42
|
+
|
43
|
+
|
44
|
+
class CreateColumn[T](BaseDDLElement):
|
45
|
+
"""
|
46
|
+
Class representing a column in a CREATE TABLE statement.
|
47
|
+
"""
|
48
|
+
|
49
|
+
__visit_name__ = "create_column"
|
50
|
+
|
51
|
+
def __init__(self, element: Column[T]):
|
52
|
+
self.element = element
|
53
|
+
|
54
|
+
|
55
|
+
class CreateSchema(BaseDDLElement):
|
56
|
+
__visit_name__ = "create_schema"
|
57
|
+
|
58
|
+
def __init__(self, schema: str, if_not_exists: bool = True):
|
59
|
+
self.schema: str = schema
|
60
|
+
self.if_not_exists: bool = if_not_exists
|
61
|
+
|
62
|
+
|
63
|
+
class DropSchema(BaseDDLElement):
|
64
|
+
__visit_name__ = "drop_schema"
|
65
|
+
|
66
|
+
def __init__(self, schema: str, if_exists: bool = True):
|
67
|
+
self.schema = schema
|
68
|
+
self.if_exists = if_exists
|
69
|
+
|
70
|
+
|
71
|
+
class SchemaExists(BaseDDLElement):
|
72
|
+
__visit_name__ = "schema_exists"
|
73
|
+
|
74
|
+
def __init__(self, schema: str):
|
75
|
+
self.schema = schema
|
76
|
+
|
77
|
+
|
78
|
+
class CreateBackup(BaseDDLElement):
|
79
|
+
__visit_name__ = "create_backup"
|
80
|
+
|
81
|
+
def __init__(self, url: URL):
|
82
|
+
self.url = url
|
@@ -0,0 +1,36 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import Optional, Any, TYPE_CHECKING
|
3
|
+
|
4
|
+
from .visitors import Element
|
5
|
+
|
6
|
+
if TYPE_CHECKING:
|
7
|
+
from ormlambda.dialects import Dialect
|
8
|
+
from .compiler import Compiled
|
9
|
+
|
10
|
+
|
11
|
+
class CompilerElement(Element):
|
12
|
+
"""
|
13
|
+
Base class for all compiler elements
|
14
|
+
"""
|
15
|
+
|
16
|
+
__slots__ = ()
|
17
|
+
__visit_name__ = "compiler_element"
|
18
|
+
|
19
|
+
def compile(self, dialect: Optional[Dialect] = None, **kw: Any) -> Compiled:
|
20
|
+
if dialect is None:
|
21
|
+
raise TypeError("Either bind or dialect must be provided.")
|
22
|
+
return self._compiler(dialect, **kw)
|
23
|
+
|
24
|
+
def _compiler(self, dialect: Dialect, **kw: Any) -> Compiled:
|
25
|
+
"""
|
26
|
+
Compile the element into a SQL string.
|
27
|
+
"""
|
28
|
+
return dialect.statement_compiler(dialect, self, **kw)
|
29
|
+
|
30
|
+
|
31
|
+
class ClauseElement(CompilerElement):
|
32
|
+
"""
|
33
|
+
Base class for all clause elements.
|
34
|
+
"""
|
35
|
+
|
36
|
+
__visit_name__ = "clause_element"
|
ormlambda/sql/foreign_key.py
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
-
from typing import Callable, TYPE_CHECKING, Optional, Any, Type, cast, overload
|
2
|
+
from typing import Callable, TYPE_CHECKING, Optional, Any, Type, cast, overload, ClassVar
|
3
3
|
|
4
4
|
from ormlambda.common.interfaces.IQueryCommand import IQuery
|
5
|
-
|
5
|
+
from ormlambda.sql.elements import Element
|
6
6
|
|
7
7
|
if TYPE_CHECKING:
|
8
8
|
from ormlambda.sql.comparer import Comparer
|
9
9
|
from ormlambda import Table
|
10
10
|
from ormlambda.sql.clause_info.clause_info_context import ClauseContextType
|
11
|
+
from ormlambda.dialects import Dialect
|
11
12
|
|
12
13
|
|
13
14
|
class ForeignKeyContext(set["ForeignKey"]):
|
@@ -32,49 +33,59 @@ class ForeignKeyContext(set["ForeignKey"]):
|
|
32
33
|
return super().add(element)
|
33
34
|
|
34
35
|
|
35
|
-
class ForeignKey[TLeft: Table, TRight: Table](IQuery):
|
36
|
-
|
36
|
+
class ForeignKey[TLeft: Table, TRight: Table](Element, IQuery):
|
37
|
+
__visit_name__ = "foreign_key"
|
38
|
+
|
39
|
+
__slots__ = (
|
40
|
+
"_tright",
|
41
|
+
"_relationship",
|
42
|
+
"_comparer",
|
43
|
+
"_clause_name",
|
44
|
+
"_keep_alive",
|
45
|
+
)
|
46
|
+
|
47
|
+
stored_calls: ClassVar[ForeignKeyContext] = ForeignKeyContext()
|
37
48
|
|
38
49
|
@overload
|
39
|
-
def __new__
|
50
|
+
def __new__(self, comparer: Comparer, clause_name: str) -> None: ...
|
40
51
|
@overload
|
41
|
-
def __new__[
|
42
|
-
|
43
|
-
def __new__[LProp, TRight, RProp](
|
52
|
+
def __new__[TRight](
|
44
53
|
cls,
|
45
|
-
tright:
|
46
|
-
relationship:
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
) -> TRight:
|
54
|
+
tright: Type[TRight],
|
55
|
+
relationship: Callable[[TLeft, TRight], Any | Comparer],
|
56
|
+
keep_alive: bool = ...,
|
57
|
+
dialect: Dialect = ...,
|
58
|
+
) -> TRight: ...
|
59
|
+
|
60
|
+
def __new__[TRight](cls, *args, **kwargs) -> TRight:
|
52
61
|
return super().__new__(cls)
|
53
62
|
|
54
|
-
def __init__
|
63
|
+
def __init__(
|
55
64
|
self,
|
56
65
|
tright: Optional[TRight] = None,
|
57
|
-
relationship: Optional[Callable[[TLeft, TRight], Any | Comparer
|
66
|
+
relationship: Optional[Callable[[TLeft, TRight], Any | Comparer]] = None,
|
58
67
|
*,
|
59
68
|
comparer: Optional[Comparer] = None,
|
60
69
|
clause_name: Optional[str] = None,
|
61
70
|
keep_alive: bool = False,
|
71
|
+
**kwargs: Any,
|
62
72
|
) -> None:
|
73
|
+
self.kwargs = kwargs
|
63
74
|
self._keep_alive = keep_alive
|
64
75
|
if comparer is not None and clause_name is not None:
|
65
|
-
self.__init__with_comparer(comparer, clause_name)
|
76
|
+
self.__init__with_comparer(comparer, clause_name, **kwargs)
|
66
77
|
else:
|
67
78
|
self.__init_with_callable(tright, relationship)
|
68
79
|
|
69
|
-
def __init__with_comparer
|
80
|
+
def __init__with_comparer(self, comparer: Comparer, clause_name: str, **kwargs) -> None:
|
70
81
|
self._relationship = None
|
71
|
-
self._tleft: TLeft = comparer.left_condition.table
|
72
|
-
self._tright: TRight = comparer.right_condition.table
|
82
|
+
self._tleft: TLeft = comparer.left_condition(**kwargs).table
|
83
|
+
self._tright: TRight = comparer.right_condition(**kwargs).table
|
73
84
|
self._clause_name: str = clause_name
|
74
|
-
self._comparer: Comparer
|
85
|
+
self._comparer: Comparer = comparer
|
75
86
|
|
76
|
-
def __init_with_callable
|
77
|
-
self._relationship: Callable[[TLeft, TRight], Comparer
|
87
|
+
def __init_with_callable(self, tright: Optional[TRight], relationship: Optional[Callable[[TLeft, TRight], Comparer]]) -> None:
|
88
|
+
self._relationship: Callable[[TLeft, TRight], Comparer] = relationship
|
78
89
|
self._tleft: TLeft = None
|
79
90
|
self._tright: TRight = tright
|
80
91
|
self._clause_name: str = None
|
@@ -113,29 +124,29 @@ class ForeignKey[TLeft: Table, TRight: Table](IQuery):
|
|
113
124
|
def clause_name(self) -> str:
|
114
125
|
return self._clause_name
|
115
126
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
rcon = alias if (alias := compare.right_condition.alias_table) else compare.right_condition.table.__table_name__
|
120
|
-
return f"FOREIGN KEY ({
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
self._comparer =
|
125
|
-
lcol = self._comparer.left_condition._column.column_name
|
126
|
-
rcol = self._comparer.right_condition._column.column_name
|
127
|
+
def query(self, dialect: Dialect, **kwargs) -> str:
|
128
|
+
compare = self.resolved_function(dialect)
|
129
|
+
left_col = compare.left_condition(dialect).column
|
130
|
+
rcon = alias if (alias := compare.right_condition(dialect).alias_table) else compare.right_condition(dialect).table.__table_name__
|
131
|
+
return f"FOREIGN KEY ({left_col}) REFERENCES {rcon}({compare.right_condition(dialect).column})"
|
132
|
+
|
133
|
+
def get_alias(self, dialect: Dialect) -> str:
|
134
|
+
self._comparer = self.resolved_function(dialect)
|
135
|
+
self._comparer._dialect = dialect
|
136
|
+
lcol = self._comparer.left_condition(dialect)._column.column_name
|
137
|
+
rcol = self._comparer.right_condition(dialect)._column.column_name
|
127
138
|
return f"{self.tleft.__table_name__}_{lcol}_{rcol}"
|
128
139
|
|
129
140
|
@classmethod
|
130
|
-
def create_query(cls, orig_table: Table) -> list[str]:
|
141
|
+
def create_query(cls, orig_table: Table, dialect: Dialect) -> list[str]:
|
131
142
|
clauses: list[str] = []
|
132
143
|
|
133
|
-
for attr in
|
144
|
+
for attr in orig_table.__dict__.values():
|
134
145
|
if isinstance(attr, ForeignKey):
|
135
|
-
clauses.append(attr.query)
|
146
|
+
clauses.append(attr.query(dialect))
|
136
147
|
return clauses
|
137
148
|
|
138
|
-
def resolved_function[LProp: Any, RProp: Any](self, context: ClauseContextType = None) -> Comparer
|
149
|
+
def resolved_function[LProp: Any, RProp: Any](self, dialect: Dialect, context: Optional[ClauseContextType] = None) -> Comparer:
|
139
150
|
""" """
|
140
151
|
if self._comparer is not None:
|
141
152
|
return self._comparer
|
@@ -144,4 +155,15 @@ class ForeignKey[TLeft: Table, TRight: Table](IQuery):
|
|
144
155
|
right = self._tright
|
145
156
|
comparer = self._relationship(left, right)
|
146
157
|
comparer.set_context(context)
|
158
|
+
comparer._dialect = dialect
|
147
159
|
return comparer
|
160
|
+
|
161
|
+
def __hash__(self):
|
162
|
+
return hash((
|
163
|
+
self._tleft,
|
164
|
+
self._tright,
|
165
|
+
self._clause_name,
|
166
|
+
))
|
167
|
+
|
168
|
+
def __eq__(self, other: ForeignKey):
|
169
|
+
return hash(other) == hash(self)
|
@@ -1,3 +1,4 @@
|
|
1
|
+
from __future__ import annotations
|
1
2
|
import typing as tp
|
2
3
|
|
3
4
|
from ormlambda.sql.clause_info import AggregateFunctionBase
|
@@ -9,7 +10,11 @@ from ormlambda.sql.clause_info import ClauseInfo
|
|
9
10
|
type ConcatResponse[TProp] = tuple[str | ColumnType[TProp]]
|
10
11
|
|
11
12
|
|
12
|
-
|
13
|
+
if tp.TYPE_CHECKING:
|
14
|
+
from ormlambda.dialects import Dialect
|
15
|
+
|
16
|
+
|
17
|
+
class Concat[T](AggregateFunctionBase[T]):
|
13
18
|
@staticmethod
|
14
19
|
def FUNCTION_NAME() -> str:
|
15
20
|
return "CONCAT"
|
@@ -19,22 +24,25 @@ class Concat[T](AggregateFunctionBase):
|
|
19
24
|
values: ConcatResponse[TProp],
|
20
25
|
alias_clause: AliasType[ColumnType[TProp]] = "concat",
|
21
26
|
context: ClauseContextType = None,
|
27
|
+
*,
|
28
|
+
dialect: Dialect,
|
22
29
|
) -> None:
|
23
30
|
super().__init__(
|
24
31
|
table=None,
|
25
32
|
column=values,
|
26
33
|
alias_clause=alias_clause,
|
27
34
|
context=context,
|
35
|
+
dtype=str,
|
36
|
+
dialect=dialect,
|
28
37
|
)
|
29
38
|
|
30
39
|
@tp.override
|
31
|
-
|
32
|
-
def query(self) -> str:
|
40
|
+
def query(self, dialect: Dialect, **kwargs) -> str:
|
33
41
|
columns: list[str] = []
|
34
42
|
|
35
43
|
context = ClauseInfoContext(table_context=self._context._table_context, clause_context=None) if self._context else None
|
36
44
|
|
37
|
-
for clause in self._convert_into_clauseInfo(self.unresolved_column, context=context):
|
45
|
+
for clause in self._convert_into_clauseInfo(self.unresolved_column, context=context, dialect=self._dialect):
|
38
46
|
clause.alias_clause = self.alias_clause
|
39
47
|
columns.append(clause)
|
40
|
-
return self._concat_alias_and_column(f"{self.FUNCTION_NAME()}({ClauseInfo.join_clauses(columns)})", self._alias_aggregate)
|
48
|
+
return self._concat_alias_and_column(f"{self.FUNCTION_NAME()}({ClauseInfo.join_clauses(columns,dialect=self._dialect)})", self._alias_aggregate)
|
@@ -6,6 +6,9 @@ from ormlambda.sql.clause_info import ClauseInfo
|
|
6
6
|
from ormlambda.sql.types import ColumnType, AliasType
|
7
7
|
from ormlambda.sql.clause_info import AggregateFunctionBase
|
8
8
|
|
9
|
+
if tp.TYPE_CHECKING:
|
10
|
+
from ormlambda.dialects import Dialect
|
11
|
+
|
9
12
|
|
10
13
|
class Max(AggregateFunctionBase[None]):
|
11
14
|
@staticmethod
|
@@ -17,6 +20,8 @@ class Max(AggregateFunctionBase[None]):
|
|
17
20
|
elements: ColumnType[TProp],
|
18
21
|
alias_clause: AliasType[ColumnType[TProp]] = "max",
|
19
22
|
context: ClauseContextType = None,
|
23
|
+
*,
|
24
|
+
dialect: Dialect,
|
20
25
|
):
|
21
26
|
super().__init__(
|
22
27
|
table=None,
|
@@ -26,18 +31,18 @@ class Max(AggregateFunctionBase[None]):
|
|
26
31
|
context=context,
|
27
32
|
keep_asterisk=False,
|
28
33
|
preserve_context=False,
|
34
|
+
dialect=dialect,
|
29
35
|
)
|
30
36
|
|
31
37
|
@tp.override
|
32
|
-
|
33
|
-
def query(self) -> str:
|
38
|
+
def query(self, dialect: Dialect, **kwargs) -> str:
|
34
39
|
columns: list[str] = []
|
35
40
|
|
36
41
|
context = ClauseInfoContext(table_context=self._context._table_context, clause_context=None) if self._context else None
|
37
|
-
for clause in self._convert_into_clauseInfo(self.unresolved_column, context):
|
42
|
+
for clause in self._convert_into_clauseInfo(self.unresolved_column, context, dialect=self._dialect):
|
38
43
|
new_clause = clause
|
39
44
|
new_clause.alias_clause = None
|
40
45
|
columns.append(new_clause)
|
41
46
|
|
42
|
-
method_string = f"{self.FUNCTION_NAME()}({ClauseInfo.join_clauses(columns)})"
|
47
|
+
method_string = f"{self.FUNCTION_NAME()}({ClauseInfo.join_clauses(columns,dialect=self._dialect)})"
|
43
48
|
return self._concat_alias_and_column(method_string, self._alias_aggregate)
|
@@ -6,6 +6,9 @@ from ormlambda.sql.clause_info import ClauseInfo
|
|
6
6
|
from ormlambda.sql.types import ColumnType, AliasType
|
7
7
|
from ormlambda.sql.clause_info import AggregateFunctionBase
|
8
8
|
|
9
|
+
if tp.TYPE_CHECKING:
|
10
|
+
from ormlambda.dialects import Dialect
|
11
|
+
|
9
12
|
|
10
13
|
class Min(AggregateFunctionBase):
|
11
14
|
@staticmethod
|
@@ -17,27 +20,20 @@ class Min(AggregateFunctionBase):
|
|
17
20
|
elements: tuple[ColumnType[TProp], ...] | ColumnType[TProp],
|
18
21
|
alias_clause: AliasType[ColumnType[TProp]] = "min",
|
19
22
|
context: ClauseContextType = None,
|
23
|
+
*,
|
24
|
+
dialect: Dialect,
|
20
25
|
):
|
21
|
-
super().__init__(
|
22
|
-
table=None,
|
23
|
-
column=elements,
|
24
|
-
alias_table=None,
|
25
|
-
alias_clause=alias_clause,
|
26
|
-
context=context,
|
27
|
-
keep_asterisk=False,
|
28
|
-
preserve_context=False,
|
29
|
-
)
|
26
|
+
super().__init__(table=None, column=elements, alias_table=None, alias_clause=alias_clause, context=context, keep_asterisk=False, preserve_context=False, dialect=dialect)
|
30
27
|
|
31
28
|
@tp.override
|
32
|
-
|
33
|
-
def query(self) -> str:
|
29
|
+
def query(self, dialect: Dialect, **kwargs) -> str:
|
34
30
|
columns: list[str] = []
|
35
31
|
|
36
32
|
context = ClauseInfoContext(table_context=self._context._table_context, clause_context=None) if self._context else None
|
37
|
-
for clause in self._convert_into_clauseInfo(self.unresolved_column, context):
|
33
|
+
for clause in self._convert_into_clauseInfo(self.unresolved_column, context, dialect=self._dialect):
|
38
34
|
new_clause = clause
|
39
35
|
new_clause.alias_clause = None
|
40
36
|
columns.append(new_clause)
|
41
37
|
|
42
|
-
method_string = f"{self.FUNCTION_NAME()}({ClauseInfo.join_clauses(columns)})"
|
38
|
+
method_string = f"{self.FUNCTION_NAME()}({ClauseInfo.join_clauses(columns,dialect=self._dialect)})"
|
43
39
|
return self._concat_alias_and_column(method_string, self._alias_aggregate)
|
@@ -6,18 +6,16 @@ from ormlambda.sql.clause_info import ClauseInfo
|
|
6
6
|
from ormlambda.sql.types import ColumnType, AliasType
|
7
7
|
from ormlambda.sql.clause_info import AggregateFunctionBase
|
8
8
|
|
9
|
+
if tp.TYPE_CHECKING:
|
10
|
+
from ormlambda.dialects import Dialect
|
11
|
+
|
9
12
|
|
10
13
|
class Sum(AggregateFunctionBase):
|
11
14
|
@staticmethod
|
12
15
|
def FUNCTION_NAME() -> str:
|
13
16
|
return "SUM"
|
14
17
|
|
15
|
-
def __init__[TProp](
|
16
|
-
self,
|
17
|
-
elements: tuple[ColumnType[TProp], ...] | ColumnType[TProp],
|
18
|
-
alias_clause: AliasType[ColumnType[TProp]] = "sum",
|
19
|
-
context: ClauseContextType = None,
|
20
|
-
):
|
18
|
+
def __init__[TProp](self, elements: tuple[ColumnType[TProp], ...] | ColumnType[TProp], alias_clause: AliasType[ColumnType[TProp]] = "sum", context: ClauseContextType = None, *, dialect: Dialect):
|
21
19
|
super().__init__(
|
22
20
|
table=None,
|
23
21
|
column=elements,
|
@@ -26,18 +24,18 @@ class Sum(AggregateFunctionBase):
|
|
26
24
|
context=context,
|
27
25
|
keep_asterisk=False,
|
28
26
|
preserve_context=False,
|
27
|
+
dialect=dialect,
|
29
28
|
)
|
30
29
|
|
31
30
|
@tp.override
|
32
|
-
|
33
|
-
def query(self) -> str:
|
31
|
+
def query(self, dialect: Dialect, **kwargs) -> str:
|
34
32
|
columns: list[str] = []
|
35
33
|
|
36
34
|
context = ClauseInfoContext(table_context=self._context._table_context, clause_context=None) if self._context else None
|
37
|
-
for clause in self._convert_into_clauseInfo(self.unresolved_column, context):
|
35
|
+
for clause in self._convert_into_clauseInfo(self.unresolved_column, context, self._dialect):
|
38
36
|
new_clause = clause
|
39
37
|
new_clause.alias_clause = None
|
40
38
|
columns.append(new_clause)
|
41
39
|
|
42
|
-
method_string = f"{self.FUNCTION_NAME()}({ClauseInfo.join_clauses(columns)})"
|
40
|
+
method_string = f"{self.FUNCTION_NAME()}({ClauseInfo.join_clauses(columns,dialect=self._dialect)})"
|
43
41
|
return self._concat_alias_and_column(method_string, self._alias_aggregate)
|