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/comparer.py
CHANGED
@@ -8,10 +8,11 @@ from ormlambda.common.interfaces.IQueryCommand import IQuery
|
|
8
8
|
from ormlambda.sql.types import ConditionType, ComparerTypes
|
9
9
|
from ormlambda.sql.clause_info import ClauseInfo
|
10
10
|
from ormlambda import ConditionType as ConditionEnum
|
11
|
+
from ormlambda.sql.elements import Element
|
11
12
|
|
12
13
|
if tp.TYPE_CHECKING:
|
13
14
|
from ormlambda.sql.clause_info.clause_info_context import ClauseContextType
|
14
|
-
from ormlambda.
|
15
|
+
from ormlambda.dialects import Dialect
|
15
16
|
|
16
17
|
|
17
18
|
class ICleaner(abc.ABC):
|
@@ -45,75 +46,88 @@ class CleanValue:
|
|
45
46
|
return temp_name
|
46
47
|
|
47
48
|
|
48
|
-
class Comparer
|
49
|
+
class Comparer(Element, IQuery):
|
50
|
+
__visit_name__ = "comparer"
|
51
|
+
|
49
52
|
def __init__(
|
50
53
|
self,
|
51
|
-
left_condition: ConditionType
|
52
|
-
right_condition: ConditionType
|
54
|
+
left_condition: ConditionType,
|
55
|
+
right_condition: ConditionType,
|
53
56
|
compare: ComparerTypes,
|
54
57
|
context: ClauseContextType = None,
|
55
58
|
flags: tp.Optional[tp.Iterable[re.RegexFlag]] = None,
|
59
|
+
dialect: tp.Optional[Dialect] = None,
|
56
60
|
) -> None:
|
57
61
|
self._context: ClauseContextType = context
|
58
62
|
self._compare: ComparerTypes = compare
|
59
|
-
self._left_condition: Comparer
|
60
|
-
self._right_condition: Comparer
|
63
|
+
self._left_condition: Comparer | ClauseInfo = left_condition
|
64
|
+
self._right_condition: Comparer | ClauseInfo = right_condition
|
61
65
|
self._flags = flags
|
66
|
+
self._dialect = dialect
|
62
67
|
|
63
68
|
def set_context(self, context: ClauseContextType) -> None:
|
64
69
|
self._context = context
|
70
|
+
return None
|
71
|
+
|
72
|
+
def set_dialect(self, dialect: Dialect) -> None:
|
73
|
+
self._dialect = dialect
|
74
|
+
return None
|
65
75
|
|
66
76
|
def __repr__(self) -> str:
|
67
77
|
return f"{Comparer.__name__}: {self.query}"
|
68
78
|
|
69
|
-
def _create_clause_info
|
79
|
+
def _create_clause_info(self, cond: ConditionType, dialect: Dialect, **kw) -> Comparer | ClauseInfo:
|
70
80
|
from ormlambda import Column
|
71
81
|
|
72
82
|
if isinstance(cond, Comparer):
|
73
83
|
return cond
|
74
|
-
if isinstance(cond, Column)
|
75
|
-
|
84
|
+
table = None if not isinstance(cond, Column) else cond.table
|
85
|
+
|
76
86
|
# it a value that's not depend of any Table
|
77
|
-
return ClauseInfo(
|
87
|
+
return ClauseInfo(
|
88
|
+
table,
|
89
|
+
cond,
|
90
|
+
alias_clause=None,
|
91
|
+
context=self._context,
|
92
|
+
dialect=dialect,
|
93
|
+
**kw,
|
94
|
+
)
|
78
95
|
|
79
|
-
|
80
|
-
|
81
|
-
return self._create_clause_info(self._left_condition)
|
96
|
+
def left_condition(self, dialect: Dialect) -> Comparer | ClauseInfo:
|
97
|
+
return self._create_clause_info(self._left_condition, dialect=dialect)
|
82
98
|
|
83
|
-
|
84
|
-
|
85
|
-
return self._create_clause_info(self._right_condition)
|
99
|
+
def right_condition(self, dialect: Dialect) -> Comparer | ClauseInfo:
|
100
|
+
return self._create_clause_info(self._right_condition, dialect=dialect)
|
86
101
|
|
87
102
|
@property
|
88
103
|
def compare(self) -> ComparerTypes:
|
89
104
|
return self._compare
|
90
105
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
rcond = self.right_condition.query
|
106
|
+
def query(self, dialect: Dialect, **kwargs) -> str:
|
107
|
+
lcond = self.left_condition(dialect).query(dialect, **kwargs)
|
108
|
+
rcond = self.right_condition(dialect).query(dialect, **kwargs)
|
95
109
|
|
96
110
|
if self._flags:
|
97
111
|
rcond = CleanValue(rcond, self._flags).clean()
|
98
112
|
|
99
113
|
return f"{lcond} {self._compare} {rcond}"
|
100
114
|
|
101
|
-
def __and__(self, other: Comparer,
|
115
|
+
def __and__(self, other: Comparer, **kwargs) -> Comparer:
|
102
116
|
# Customize the behavior of '&'
|
103
|
-
return Comparer(self, other, "AND",
|
117
|
+
return Comparer(self, other, "AND", **kwargs)
|
104
118
|
|
105
|
-
def __or__(self, other: Comparer,
|
119
|
+
def __or__(self, other: Comparer, **kwargs) -> Comparer:
|
106
120
|
# Customize the behavior of '|'
|
107
|
-
return Comparer(self, other, "OR",
|
121
|
+
return Comparer(self, other, "OR", **kwargs)
|
108
122
|
|
109
123
|
@classmethod
|
110
|
-
def join_comparers(cls, comparers: list[Comparer], restrictive: bool = True, context: ClauseContextType = None) -> str:
|
124
|
+
def join_comparers(cls, comparers: list[Comparer], restrictive: bool = True, context: ClauseContextType = None, *, dialect) -> str:
|
111
125
|
if not isinstance(comparers, tp.Iterable):
|
112
126
|
raise ValueError(f"Excepted '{Comparer.__name__}' iterable not {type(comparers).__name__}")
|
113
127
|
if len(comparers) == 1:
|
114
128
|
comparer = comparers[0]
|
115
|
-
comparer.
|
116
|
-
return comparer.query
|
129
|
+
comparer._context = context
|
130
|
+
return comparer.query(dialect)
|
117
131
|
|
118
132
|
join_method = cls.__or__ if not restrictive else cls.__and__
|
119
133
|
|
@@ -121,19 +135,19 @@ class Comparer[LTable: Table, LProp, RTable: Table, RProp](IQuery):
|
|
121
135
|
for i in range(len(comparers) - 1):
|
122
136
|
if ini_comparer is None:
|
123
137
|
ini_comparer = comparers[i]
|
124
|
-
ini_comparer.
|
138
|
+
ini_comparer._context = context
|
125
139
|
right_comparer = comparers[i + 1]
|
126
|
-
right_comparer.
|
127
|
-
new_comparer = join_method(ini_comparer, right_comparer, context=context)
|
140
|
+
right_comparer._context = context
|
141
|
+
new_comparer = join_method(ini_comparer, right_comparer, context=context, dialect=dialect)
|
128
142
|
ini_comparer = new_comparer
|
129
|
-
return new_comparer.query
|
143
|
+
return new_comparer.query(dialect)
|
130
144
|
|
131
145
|
|
132
|
-
class Regex
|
146
|
+
class Regex(Comparer):
|
133
147
|
def __init__(
|
134
148
|
self,
|
135
|
-
left_condition: ConditionType
|
136
|
-
right_condition: ConditionType
|
149
|
+
left_condition: ConditionType,
|
150
|
+
right_condition: ConditionType,
|
137
151
|
context: ClauseContextType = None,
|
138
152
|
flags: tp.Optional[tp.Iterable[re.RegexFlag]] = None,
|
139
153
|
):
|
@@ -146,11 +160,11 @@ class Regex[LProp, RProp](Comparer[None, LProp, None, RProp]):
|
|
146
160
|
)
|
147
161
|
|
148
162
|
|
149
|
-
class Like
|
163
|
+
class Like(Comparer):
|
150
164
|
def __init__(
|
151
165
|
self,
|
152
|
-
left_condition: ConditionType
|
153
|
-
right_condition: ConditionType
|
166
|
+
left_condition: ConditionType,
|
167
|
+
right_condition: ConditionType,
|
154
168
|
context: ClauseContextType = None,
|
155
169
|
):
|
156
170
|
super().__init__(left_condition, right_condition, ConditionEnum.LIKE.value, context)
|