ormlambda 3.34.5__py3-none-any.whl → 3.34.7__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/dialects/mysql/__init__.py +79 -3
- ormlambda/dialects/mysql/base.py +1 -0
- ormlambda/sql/clauses/new_join.py +119 -0
- ormlambda/sql/sqltypes.py +6 -0
- ormlambda/sql/table/table.py +4 -8
- {ormlambda-3.34.5.dist-info → ormlambda-3.34.7.dist-info}/METADATA +1 -1
- {ormlambda-3.34.5.dist-info → ormlambda-3.34.7.dist-info}/RECORD +10 -9
- {ormlambda-3.34.5.dist-info → ormlambda-3.34.7.dist-info}/AUTHORS +0 -0
- {ormlambda-3.34.5.dist-info → ormlambda-3.34.7.dist-info}/LICENSE +0 -0
- {ormlambda-3.34.5.dist-info → ormlambda-3.34.7.dist-info}/WHEEL +0 -0
@@ -1,8 +1,84 @@
|
|
1
1
|
from . import base
|
2
2
|
from . import mysqlconnector
|
3
3
|
|
4
|
-
|
5
|
-
base
|
4
|
+
from .base import BIGINT
|
5
|
+
from .base import BINARY
|
6
|
+
from .base import BIT
|
7
|
+
from .base import BLOB
|
8
|
+
from .base import BOOLEAN
|
9
|
+
from .base import CHAR
|
10
|
+
from .base import DATE
|
11
|
+
from .base import DATETIME
|
12
|
+
from .base import DECIMAL
|
13
|
+
from .base import DOUBLE
|
14
|
+
from .base import FLOAT
|
15
|
+
from .base import INTEGER
|
16
|
+
from .base import LONGBLOB
|
17
|
+
from .base import LONGTEXT
|
18
|
+
from .base import MEDIUMBLOB
|
19
|
+
from .base import MEDIUMINT
|
20
|
+
from .base import MEDIUMTEXT
|
21
|
+
from .base import NCHAR
|
22
|
+
from .base import NUMERIC
|
23
|
+
from .base import NVARCHAR
|
24
|
+
from .base import REAL
|
25
|
+
from .base import SMALLINT
|
26
|
+
from .base import TEXT
|
27
|
+
from .base import TIME
|
28
|
+
from .base import TIMESTAMP
|
29
|
+
from .base import TINYBLOB
|
30
|
+
from .base import TINYINT
|
31
|
+
from .base import TINYTEXT
|
32
|
+
from .base import VARBINARY
|
33
|
+
from .base import VARCHAR
|
34
|
+
from .base import YEAR
|
35
|
+
|
36
|
+
|
6
37
|
|
38
|
+
__all__ = (
|
39
|
+
"BIGINT",
|
40
|
+
"BINARY",
|
41
|
+
"BIT",
|
42
|
+
"BLOB",
|
43
|
+
"BOOLEAN",
|
44
|
+
"CHAR",
|
45
|
+
"DATE",
|
46
|
+
"DATETIME",
|
47
|
+
"DECIMAL",
|
48
|
+
"DOUBLE",
|
49
|
+
"ENUM",
|
50
|
+
"FLOAT",
|
51
|
+
"INET4",
|
52
|
+
"INET6",
|
53
|
+
"INTEGER",
|
54
|
+
"INTEGER",
|
55
|
+
"JSON",
|
56
|
+
"LONGBLOB",
|
57
|
+
"LONGTEXT",
|
58
|
+
"MEDIUMBLOB",
|
59
|
+
"MEDIUMINT",
|
60
|
+
"MEDIUMTEXT",
|
61
|
+
"NCHAR",
|
62
|
+
"NVARCHAR",
|
63
|
+
"NUMERIC",
|
64
|
+
"SET",
|
65
|
+
"SMALLINT",
|
66
|
+
"REAL",
|
67
|
+
"TEXT",
|
68
|
+
"TIME",
|
69
|
+
"TIMESTAMP",
|
70
|
+
"TINYBLOB",
|
71
|
+
"TINYINT",
|
72
|
+
"TINYTEXT",
|
73
|
+
"VARBINARY",
|
74
|
+
"VARCHAR",
|
75
|
+
"YEAR",
|
76
|
+
"dialect",
|
77
|
+
"insert",
|
78
|
+
"Insert",
|
79
|
+
"match",
|
80
|
+
)
|
7
81
|
|
8
|
-
|
82
|
+
|
83
|
+
# default dialect
|
84
|
+
base.dialect = dialect = mysqlconnector.dialect
|
ormlambda/dialects/mysql/base.py
CHANGED
@@ -0,0 +1,119 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from collections import defaultdict
|
3
|
+
from typing import override, Optional, TYPE_CHECKING, Type
|
4
|
+
|
5
|
+
|
6
|
+
from ormlambda.util.module_tree.dfs_traversal import DFSTraversal
|
7
|
+
from ormlambda.common.interfaces.IQueryCommand import IQuery
|
8
|
+
from ormlambda import JoinType
|
9
|
+
from ormlambda.sql.clause_info import ClauseInfo
|
10
|
+
from ormlambda.sql.comparer import Comparer
|
11
|
+
from ormlambda.sql.elements import ClauseElement
|
12
|
+
|
13
|
+
|
14
|
+
# TODOL [x]: Try to import Table module without circular import Error
|
15
|
+
if TYPE_CHECKING:
|
16
|
+
from ormlambda.dialects import Dialect
|
17
|
+
|
18
|
+
|
19
|
+
class Join(ClauseElement):
|
20
|
+
__visit_name__ = "join"
|
21
|
+
__slots__: tuple = (
|
22
|
+
"comparer",
|
23
|
+
"alias",
|
24
|
+
"from_clause",
|
25
|
+
"left_clause",
|
26
|
+
"right_clause",
|
27
|
+
"by",
|
28
|
+
"_dialect",
|
29
|
+
)
|
30
|
+
|
31
|
+
DEFAULT_TABLE: str = "{table}"
|
32
|
+
|
33
|
+
@override
|
34
|
+
def __repr__(self) -> str:
|
35
|
+
return f"{IQuery.__name__}: {self.query(self._dialect)}"
|
36
|
+
|
37
|
+
def __init__(
|
38
|
+
self,
|
39
|
+
comparer: Comparer,
|
40
|
+
right_alias: Optional[str] = DEFAULT_TABLE,
|
41
|
+
left_alias: Optional[str] = DEFAULT_TABLE,
|
42
|
+
by: JoinType = JoinType.LEFT_EXCLUSIVE,
|
43
|
+
*,
|
44
|
+
dialect: Dialect,
|
45
|
+
**kw,
|
46
|
+
) -> None:
|
47
|
+
self.comparer = comparer
|
48
|
+
self._dialect = dialect
|
49
|
+
self.by = by
|
50
|
+
|
51
|
+
# COMMENT: When multiple columns reference the same table, we need to create an alias to maintain clear references.
|
52
|
+
self.alias: Optional[str] = right_alias
|
53
|
+
self.left_clause: ClauseInfo = comparer.left_condition(dialect)
|
54
|
+
self.left_clause.alias_table = left_alias if left_alias is not None else self.DEFAULT_TABLE
|
55
|
+
|
56
|
+
self.right_clause: ClauseInfo = comparer.right_condition(dialect)
|
57
|
+
self.right_clause.alias_table = right_alias if right_alias is not None else self.DEFAULT_TABLE
|
58
|
+
self.from_clause = ClauseInfo(self.right_clause.table, None, alias_table=self.alias, dialect=dialect)
|
59
|
+
|
60
|
+
def __eq__(self, __value: Join) -> bool:
|
61
|
+
return isinstance(__value, Join) and self.__hash__() == __value.__hash__()
|
62
|
+
|
63
|
+
def __hash__(self) -> int:
|
64
|
+
return hash(
|
65
|
+
(
|
66
|
+
self.by,
|
67
|
+
self.left_clause.query(self._dialect),
|
68
|
+
self.right_clause.query(self._dialect),
|
69
|
+
self.from_clause.query(self._dialect),
|
70
|
+
)
|
71
|
+
)
|
72
|
+
|
73
|
+
@classmethod
|
74
|
+
def join_selectors(cls, dialect: Dialect, *args: Join) -> str:
|
75
|
+
return "\n".join([x.query(dialect) for x in args])
|
76
|
+
|
77
|
+
def query(self, dialect: Dialect) -> str:
|
78
|
+
list_ = [
|
79
|
+
self.by.value, # inner join
|
80
|
+
self.from_clause.query(dialect),
|
81
|
+
"ON",
|
82
|
+
self.left_clause.query(dialect),
|
83
|
+
"=",
|
84
|
+
self.right_clause.query(dialect),
|
85
|
+
]
|
86
|
+
return " ".join([x for x in list_ if x is not None])
|
87
|
+
|
88
|
+
@classmethod
|
89
|
+
def sort_join_selectors(cls, joins: set[Join]) -> tuple[Join]:
|
90
|
+
# FIXME [x]: How to sort when needed because it's not necessary at this point. It is for testing purpouse
|
91
|
+
if len(joins) == 1:
|
92
|
+
return tuple(joins)
|
93
|
+
|
94
|
+
# create graph and sort it using 'Depth First Search' algorithm
|
95
|
+
graph: dict[str, list[str]] = defaultdict(list)
|
96
|
+
for join in joins:
|
97
|
+
graph[join.left_clause.alias_table].append(join.right_clause.alias_table)
|
98
|
+
|
99
|
+
sorted_graph = DFSTraversal.sort(graph)[::-1]
|
100
|
+
|
101
|
+
if not sorted_graph:
|
102
|
+
return tuple(joins)
|
103
|
+
|
104
|
+
# Mapped Join class using his unique alias
|
105
|
+
join_object_map: dict[str, Join] = {}
|
106
|
+
for obj in joins:
|
107
|
+
join_object_map[obj.alias] = obj
|
108
|
+
|
109
|
+
res = []
|
110
|
+
for table in sorted_graph:
|
111
|
+
tables = join_object_map.get(table, None)
|
112
|
+
|
113
|
+
if not tables:
|
114
|
+
continue
|
115
|
+
res.append(tables)
|
116
|
+
return res
|
117
|
+
|
118
|
+
|
119
|
+
__all__ = ["Join"]
|
ormlambda/sql/sqltypes.py
CHANGED
ormlambda/sql/table/table.py
CHANGED
@@ -159,14 +159,10 @@ class Table(metaclass=TableMeta):
|
|
159
159
|
return [ForeignKey.MAPPED[x].table_object for x in order_table]
|
160
160
|
|
161
161
|
def __eq__(self, __value: Any) -> bool:
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
tuple(self.to_dict().items()),
|
167
|
-
)
|
168
|
-
)
|
169
|
-
return False
|
162
|
+
return hash(self) == hash(__value)
|
163
|
+
|
164
|
+
def __hash__(self):
|
165
|
+
return hash((self.__table_name__, *list(self.to_dict().items())))
|
170
166
|
|
171
167
|
@classmethod
|
172
168
|
def table_alias(cls, column: Optional[str] = None) -> str:
|
@@ -60,8 +60,8 @@ ormlambda/dialects/default/__init__.py,sha256=N1B0LKEDu7r2-mTF9mBA4ReyhYeDuJDnbQ
|
|
60
60
|
ormlambda/dialects/default/base.py,sha256=rmK-nV5luN2lphSgisM8TBy3s4JXVgvZa79ATHeVOuU,1088
|
61
61
|
ormlambda/dialects/interface/__init__.py,sha256=IbB5o6ae7XNVVfNt4uqZRZcVK9HHG6eLLK_E0J99kwY,43
|
62
62
|
ormlambda/dialects/interface/dialect.py,sha256=z47GXCi-uJ6Oq7Zm64OHM0q61T3xWCss-uGdcuuXng0,2810
|
63
|
-
ormlambda/dialects/mysql/__init__.py,sha256=
|
64
|
-
ormlambda/dialects/mysql/base.py,sha256=
|
63
|
+
ormlambda/dialects/mysql/__init__.py,sha256=1yAEM2MDcp56eSv1MrbtuDVQ5d_EzQ0S7ztSXKVS-eo,1511
|
64
|
+
ormlambda/dialects/mysql/base.py,sha256=drHxKpFVVJPWy82rWSD2rFKvQ-GN8imoDmp3_ou4hcw,14535
|
65
65
|
ormlambda/dialects/mysql/mysqlconnector.py,sha256=DOjK7U7LOhjuVQJULzAV8xaRGX0OlBU8APUeRiTcbDY,1378
|
66
66
|
ormlambda/dialects/mysql/types.py,sha256=ZQ75KyUwmNAt48F48CeIiMHgQjO0JeDXrksrrss2ILg,23537
|
67
67
|
ormlambda/dialects/sqlite/__init__.py,sha256=2EMmxD7ORtGoD18GJ_9aC_tPutAq9ormMZJmaJ5nkYA,103
|
@@ -107,6 +107,7 @@ ormlambda/sql/clauses/join/__init__.py,sha256=7hwAB-nKaMirTT6uNZ1JtYNkkIx5zMSa6j
|
|
107
107
|
ormlambda/sql/clauses/join/join_context.py,sha256=69R_X_RoWO2kXPgJ94Wck6s-sJjTIqFXpOifmLsYC9c,3497
|
108
108
|
ormlambda/sql/clauses/joins.py,sha256=w0c_uHNe3BNqL9-rAdQaAFeM6ExJXTNENG_sO7I2HWI,5505
|
109
109
|
ormlambda/sql/clauses/limit.py,sha256=NX9qUp_8Zd-0myZ80PhD2tbF72N5jsx_SaYakf7lNbU,345
|
110
|
+
ormlambda/sql/clauses/new_join.py,sha256=e-tLvSQJJpTEQURYgLLoKZ6TrVsY8xGphBnqlEGg76A,3859
|
110
111
|
ormlambda/sql/clauses/offset.py,sha256=FibzDho7Bc1UQchrPHjOakW_0BfZVupbuI62lHoha94,350
|
111
112
|
ormlambda/sql/clauses/order.py,sha256=qOcz2T0NQNY0H7vt-jbvBRjTy3X5Lw-kGSuISTGfAPA,1609
|
112
113
|
ormlambda/sql/clauses/select.py,sha256=gJfTqTCi32Knyp-rox_qo-JeoVYr6YWTEPl9FF8FsFg,1670
|
@@ -126,10 +127,10 @@ ormlambda/sql/functions/max.py,sha256=wXNhFmOlMyD1sKcaBO9asQeXcfY0OvMQPkrlARVXgd
|
|
126
127
|
ormlambda/sql/functions/min.py,sha256=MTRGXgwzbLgKk9PJpn6JGK1TU91hZe_VsTszngLOh7Q,1570
|
127
128
|
ormlambda/sql/functions/sum.py,sha256=_TN8SitDDBVD6VlsHZH3RpmiE5hkFrGGgC3tuEctKjk,1614
|
128
129
|
ormlambda/sql/interfaces/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
129
|
-
ormlambda/sql/sqltypes.py,sha256=
|
130
|
+
ormlambda/sql/sqltypes.py,sha256=1Ir_Wxz1VjnNOh2zzIf7P7w4tbY0ljlubZMoAEiUkYU,14333
|
130
131
|
ormlambda/sql/table/__init__.py,sha256=LLZcMLjwFxgBCPhdm5UQYYZDIbtYWCKPO9CbcXsy5zI,50
|
131
132
|
ormlambda/sql/table/fields.py,sha256=ovNR3bJ473aKW-2NhbKr0iJlVpgW06jurHLob2IyZU8,2116
|
132
|
-
ormlambda/sql/table/table.py,sha256=
|
133
|
+
ormlambda/sql/table/table.py,sha256=l_oXhTHid09IaG-eapBxZTdaNrWCVgGHWLDHnIrrEqY,6484
|
133
134
|
ormlambda/sql/table/table_constructor.py,sha256=c3Z-1El0onSClYBmAatoUBYUOT70tITVqtsDJMxZ9QU,1092
|
134
135
|
ormlambda/sql/type_api.py,sha256=vepqMw6hR4zVhhNIYbtX491iVsxAfwHiSiD3uYQUGTE,1067
|
135
136
|
ormlambda/sql/types.py,sha256=lQxC5gbhDPRckGSRJZ4rYSZr-XUvIMMH8WfkN1wtM1g,844
|
@@ -150,8 +151,8 @@ ormlambda/util/module_tree/dfs_traversal.py,sha256=lSF03G63XtJFLp03ueAmsHMBvhUkj
|
|
150
151
|
ormlambda/util/module_tree/dynamic_module.py,sha256=vJOqvm5-WKksudXBK1IcTn4WsuLxt1qXNISq-_21sy4,8705
|
151
152
|
ormlambda/util/plugin_loader.py,sha256=p6WLn-MF1bQd2i2GHy98WQjNKmbQdqIUyTFIcBIHC5M,1034
|
152
153
|
ormlambda/util/typing.py,sha256=Z7irz53ui0hoFnJTe06NX4JPl60_thgdjJIxh5gjGGk,169
|
153
|
-
ormlambda-3.34.
|
154
|
-
ormlambda-3.34.
|
155
|
-
ormlambda-3.34.
|
156
|
-
ormlambda-3.34.
|
157
|
-
ormlambda-3.34.
|
154
|
+
ormlambda-3.34.7.dist-info/AUTHORS,sha256=uWpOHaCPTOLbVkk5x9McoLwbgzSeCg7yILeDRyMGWGM,606
|
155
|
+
ormlambda-3.34.7.dist-info/LICENSE,sha256=xBprFw8GJLdHMOoUqDk0427EvjIcbEREvXXVFULuuXU,1080
|
156
|
+
ormlambda-3.34.7.dist-info/METADATA,sha256=KY00nCr8bLYuTDA0h70RF6PeYZ2Kt-NOcN3Nd5UfR18,13326
|
157
|
+
ormlambda-3.34.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
158
|
+
ormlambda-3.34.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|