ormlambda 1.0.0__tar.gz → 1.1.3__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.
- {ormlambda-1.0.0 → ormlambda-1.1.3}/PKG-INFO +9 -9
- {ormlambda-1.0.0 → ormlambda-1.1.3}/README.md +6 -6
- {ormlambda-1.0.0 → ormlambda-1.1.3}/pyproject.toml +3 -3
- ormlambda-1.1.3/src/ormlambda/__init__.py +10 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/__init__.py +0 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/abstract_classes/__init__.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/abstract_classes/abstract_model.py +30 -13
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/abstract_classes/non_query_base.py +7 -5
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/abstract_classes/query_base.py +5 -2
- ormlambda-1.1.3/src/ormlambda/common/enums/__init__.py +2 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/enums/join_type.py +2 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/interfaces/IQueryCommand.py +2 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/interfaces/IStatements.py +25 -14
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/interfaces/__init__.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/delete/abstract_delete.py +6 -3
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/insert/IInsert.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/insert/abstract_insert.py +8 -4
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/select/ISelect.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/select/table_column.py +5 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/update/IUpdate.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/update/__init__.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/update/abstract_update.py +9 -5
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/upsert/__init__.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/upsert/abstract_upsert.py +8 -4
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/where/abstract_where.py +6 -2
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/__init__.py +1 -0
- ormlambda-1.1.3/src/ormlambda/databases/my_sql/clauses/count.py +35 -0
- ormlambda-1.1.3/src/ormlambda/databases/my_sql/clauses/create_database.py +36 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/delete.py +7 -4
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/drop_database.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/drop_table.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/insert.py +4 -3
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/joins.py +8 -7
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/limit.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/offset.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/order.py +3 -3
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/select.py +5 -5
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/update.py +3 -3
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/upsert.py +3 -3
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/clauses/where_condition.py +5 -5
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/repository.py +26 -4
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/statements.py +14 -5
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/model_base.py +0 -2
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/column.py +4 -3
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/dtypes.py +2 -17
- ormlambda-1.1.3/src/ormlambda/utils/foreign_key.py +81 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/lambda_disassembler/__init__.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/lambda_disassembler/dis_types.py +22 -25
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/lambda_disassembler/tree_instruction.py +1 -1
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/module_tree/dynamic_module.py +6 -4
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/table_constructor.py +39 -22
- ormlambda-1.0.0/src/ormlambda/__init__.py +0 -4
- ormlambda-1.0.0/src/ormlambda/common/enums/__init__.py +0 -2
- ormlambda-1.0.0/src/ormlambda/databases/my_sql/clauses/create_database.py +0 -29
- ormlambda-1.0.0/src/ormlambda/utils/foreign_key.py +0 -36
- {ormlambda-1.0.0 → ormlambda-1.1.3}/LICENSE +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/enums/condition_types.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/interfaces/INonQueryCommand.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/common/interfaces/IRepositoryBase.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/__init__.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/delete/IDelete.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/delete/__init__.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/insert/__init__.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/select/__init__.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/upsert/IUpsert.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/components/where/__init__.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/__init__.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/databases/my_sql/__init__.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/__init__.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/lambda_disassembler/disassembler.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/lambda_disassembler/dtypes.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/lambda_disassembler/name_of.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/lambda_disassembler/nested_element.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/module_tree/__init__.py +0 -0
- {ormlambda-1.0.0 → ormlambda-1.1.3}/src/ormlambda/utils/module_tree/dfs_traversal.py +0 -0
@@ -1,14 +1,14 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: ormlambda
|
3
|
-
Version: 1.
|
4
|
-
Summary: ORM designed to interact with the database using lambda functions
|
3
|
+
Version: 1.1.3
|
4
|
+
Summary: ORM designed to interact with the database (currently with MySQL) using lambda functions and nested functions
|
5
5
|
Author: p-hzamora
|
6
6
|
Author-email: p.hzamora@icloud.com
|
7
7
|
Requires-Python: >=3.12,<4.0
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
9
9
|
Classifier: Programming Language :: Python :: 3.12
|
10
|
+
Requires-Dist: fluent-validation (>=3.1.0,<4.0.0)
|
10
11
|
Requires-Dist: mysql-connector (>=2.2.9,<3.0.0)
|
11
|
-
Requires-Dist: ruff (>=0.4.5,<0.5.0)
|
12
12
|
Description-Content-Type: text/markdown
|
13
13
|
|
14
14
|
# ormMySQL
|
@@ -19,7 +19,7 @@ This ORM is designed to connect with a MySQL server, facilitating the management
|
|
19
19
|
## Initialize MySQLRepository
|
20
20
|
```python
|
21
21
|
from decouple import config
|
22
|
-
from
|
22
|
+
from ormlambda.databases.my_sql import MySQLRepository
|
23
23
|
|
24
24
|
USERNAME = config("USERNAME")
|
25
25
|
PASSWORD = config("PASSWORD")
|
@@ -31,7 +31,7 @@ database = MySQLRepository(user=USERNAME, password=PASSWORD, database="sakila",
|
|
31
31
|
|
32
32
|
## Select all columns
|
33
33
|
```python
|
34
|
-
from
|
34
|
+
from models.address import AddressModel
|
35
35
|
|
36
36
|
result = AddressModel(database).select()
|
37
37
|
```
|
@@ -41,8 +41,8 @@ The `result` var will be of type `tuple[Address, ...]`
|
|
41
41
|
Once the `AddressModel` class is created, we will not only be able to access all the information in that table, but also all the information in all the tables that have foreign keys related to it."
|
42
42
|
|
43
43
|
```python
|
44
|
-
from
|
45
|
-
from
|
44
|
+
from ormlambda import ConditionType
|
45
|
+
from models.address import AddressModel
|
46
46
|
|
47
47
|
|
48
48
|
result = AddressModel(database).where(lambda x: (x.City.Country, ConditionType.REGEXP, r"^[aA]")).select(
|
@@ -135,13 +135,13 @@ The easiest way to map your tables is:
|
|
135
135
|
```python
|
136
136
|
from datetime import datetime
|
137
137
|
|
138
|
-
from
|
138
|
+
from ormlambda import (
|
139
139
|
Column,
|
140
140
|
Table,
|
141
141
|
BaseModel,
|
142
142
|
ForeignKey,
|
143
143
|
)
|
144
|
-
from
|
144
|
+
from ormlambda.common.interfaces import IStatements_two_generic, IRepositoryBase
|
145
145
|
|
146
146
|
|
147
147
|
class Country(Table):
|
@@ -6,7 +6,7 @@ This ORM is designed to connect with a MySQL server, facilitating the management
|
|
6
6
|
## Initialize MySQLRepository
|
7
7
|
```python
|
8
8
|
from decouple import config
|
9
|
-
from
|
9
|
+
from ormlambda.databases.my_sql import MySQLRepository
|
10
10
|
|
11
11
|
USERNAME = config("USERNAME")
|
12
12
|
PASSWORD = config("PASSWORD")
|
@@ -18,7 +18,7 @@ database = MySQLRepository(user=USERNAME, password=PASSWORD, database="sakila",
|
|
18
18
|
|
19
19
|
## Select all columns
|
20
20
|
```python
|
21
|
-
from
|
21
|
+
from models.address import AddressModel
|
22
22
|
|
23
23
|
result = AddressModel(database).select()
|
24
24
|
```
|
@@ -28,8 +28,8 @@ The `result` var will be of type `tuple[Address, ...]`
|
|
28
28
|
Once the `AddressModel` class is created, we will not only be able to access all the information in that table, but also all the information in all the tables that have foreign keys related to it."
|
29
29
|
|
30
30
|
```python
|
31
|
-
from
|
32
|
-
from
|
31
|
+
from ormlambda import ConditionType
|
32
|
+
from models.address import AddressModel
|
33
33
|
|
34
34
|
|
35
35
|
result = AddressModel(database).where(lambda x: (x.City.Country, ConditionType.REGEXP, r"^[aA]")).select(
|
@@ -122,13 +122,13 @@ The easiest way to map your tables is:
|
|
122
122
|
```python
|
123
123
|
from datetime import datetime
|
124
124
|
|
125
|
-
from
|
125
|
+
from ormlambda import (
|
126
126
|
Column,
|
127
127
|
Table,
|
128
128
|
BaseModel,
|
129
129
|
ForeignKey,
|
130
130
|
)
|
131
|
-
from
|
131
|
+
from ormlambda.common.interfaces import IStatements_two_generic, IRepositoryBase
|
132
132
|
|
133
133
|
|
134
134
|
class Country(Table):
|
@@ -3,15 +3,15 @@ line-length = 320
|
|
3
3
|
|
4
4
|
[tool.poetry]
|
5
5
|
name = "ormlambda"
|
6
|
-
version = "1.
|
7
|
-
description = "ORM designed to interact with the database using lambda functions"
|
6
|
+
version = "1.1.3"
|
7
|
+
description = "ORM designed to interact with the database (currently with MySQL) using lambda functions and nested functions"
|
8
8
|
authors = ["p-hzamora <p.hzamora@icloud.com>"]
|
9
9
|
readme = "README.md"
|
10
10
|
|
11
11
|
[tool.poetry.dependencies]
|
12
12
|
python = "^3.12"
|
13
13
|
mysql-connector = "^2.2.9"
|
14
|
-
|
14
|
+
fluent-validation = "^3.1.0"
|
15
15
|
|
16
16
|
[tool.poetry.group.test.dependencies]
|
17
17
|
pandas = "^2.2.2"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# enums
|
2
|
+
from .common.enums import ( # noqa: F401
|
3
|
+
JoinType,
|
4
|
+
ConditionType,
|
5
|
+
)
|
6
|
+
|
7
|
+
from .common.interfaces import IRepositoryBase # noqa: F401
|
8
|
+
from .utils import Table, Column, ForeignKey # noqa: F401
|
9
|
+
from .utils.lambda_disassembler import Disassembler, nameof # noqa: F401
|
10
|
+
from .model_base import BaseModel # noqa: F401 # COMMENT: to avoid relative import we need to import BaseModel after import Table,Column, ForeignKey, IRepositoryBase and Disassembler
|
@@ -1,21 +1,27 @@
|
|
1
|
-
from
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import Any, Callable, Optional, Type, override, Iterable, Literal, TYPE_CHECKING
|
2
3
|
from enum import Enum
|
3
4
|
from collections import defaultdict
|
4
5
|
from abc import abstractmethod
|
5
6
|
import inspect
|
6
7
|
|
7
|
-
from
|
8
|
+
from ormlambda.utils import ForeignKey, Table
|
8
9
|
|
9
|
-
from
|
10
|
-
from ..interfaces.IStatements import OrderType
|
10
|
+
from ormlambda.common.interfaces import IQuery, IRepositoryBase, IStatements_two_generic
|
11
11
|
|
12
|
-
|
13
|
-
from
|
14
|
-
|
15
|
-
from
|
16
|
-
from
|
17
|
-
from
|
18
|
-
from
|
12
|
+
if TYPE_CHECKING:
|
13
|
+
from ormlambda.common.interfaces.IStatements import OrderType
|
14
|
+
|
15
|
+
from ormlambda.components.update import UpdateQueryBase
|
16
|
+
from ormlambda.components.select import ISelect
|
17
|
+
from ormlambda.components.delete import DeleteQueryBase
|
18
|
+
from ormlambda.components.upsert import UpsertQueryBase
|
19
|
+
from ormlambda.components.select import TableColumn
|
20
|
+
from ormlambda.components.insert import InsertQueryBase
|
21
|
+
from ormlambda.components.where.abstract_where import AbstractWhere
|
22
|
+
|
23
|
+
from ormlambda.databases.my_sql.clauses.select import SelectQuery
|
24
|
+
from ormlambda.databases.my_sql.clauses.count import CountQuery
|
19
25
|
|
20
26
|
|
21
27
|
class JoinType(Enum):
|
@@ -82,7 +88,11 @@ class AbstractSQLStatements[T: Table, TRepo](IStatements_two_generic[T, TRepo]):
|
|
82
88
|
def ORDER_QUERY(self) -> Type[IQuery]: ...
|
83
89
|
@property
|
84
90
|
@abstractmethod
|
85
|
-
def SELECT_QUERY(self) -> Type[
|
91
|
+
def SELECT_QUERY(self) -> Type[SelectQuery]: ...
|
92
|
+
|
93
|
+
@property
|
94
|
+
@abstractmethod
|
95
|
+
def COUNT(self) -> Type[CountQuery]: ...
|
86
96
|
|
87
97
|
@override
|
88
98
|
def create_table(self) -> None:
|
@@ -151,9 +161,16 @@ class AbstractSQLStatements[T: Table, TRepo](IStatements_two_generic[T, TRepo]):
|
|
151
161
|
self._query_list["offset"].append(offset)
|
152
162
|
return self
|
153
163
|
|
164
|
+
@override
|
165
|
+
def count(self) -> int:
|
166
|
+
count_select: IQuery = self.COUNT(self._model)
|
167
|
+
self._query_list["select"].append(count_select)
|
168
|
+
query = self.build()
|
169
|
+
return self.repository.read_sql(query)[0][0]
|
170
|
+
|
154
171
|
@override
|
155
172
|
def join(self, table_left: Table, table_right: Table, *, by: str) -> "IStatements_two_generic[T,TRepo]":
|
156
|
-
where = ForeignKey.MAPPED[table_left][table_right]
|
173
|
+
where = ForeignKey.MAPPED[table_left.__table_name__][table_right.__table_name__]
|
157
174
|
join_query = self.JOIN_QUERY[table_left, Table](table_left, table_right, JoinType(by), where=where)
|
158
175
|
self._query_list["join"].append(join_query)
|
159
176
|
return self
|
@@ -1,13 +1,15 @@
|
|
1
|
+
from __future__ import annotations
|
1
2
|
from abc import abstractmethod
|
2
|
-
from typing import Any, Optional, override
|
3
|
+
from typing import Any, Optional, Type, override, TYPE_CHECKING
|
3
4
|
|
4
|
-
from
|
5
|
+
from ormlambda.common.interfaces.INonQueryCommand import INonQueryCommand
|
5
6
|
|
6
|
-
|
7
|
-
from
|
7
|
+
if TYPE_CHECKING:
|
8
|
+
from ormlambda import IRepositoryBase
|
9
|
+
from ormlambda import Table
|
8
10
|
|
9
11
|
|
10
|
-
class NonQueryBase[T: Table, TRepo: IRepositoryBase](INonQueryCommand):
|
12
|
+
class NonQueryBase[T: Type[Table], TRepo: IRepositoryBase](INonQueryCommand):
|
11
13
|
__slots__: tuple[str, ...] = ("_model", "_repository", "_values", "_query")
|
12
14
|
|
13
15
|
def __init__(self, model: T, repository: TRepo) -> None:
|
@@ -1,7 +1,10 @@
|
|
1
1
|
from abc import abstractmethod
|
2
|
+
from typing import TYPE_CHECKING
|
2
3
|
|
3
|
-
from
|
4
|
-
|
4
|
+
from ormlambda.common.interfaces import IQuery
|
5
|
+
|
6
|
+
if TYPE_CHECKING:
|
7
|
+
from ormlambda import Table
|
5
8
|
|
6
9
|
|
7
10
|
class QueryBase[T: Table](IQuery):
|
@@ -1,5 +1,6 @@
|
|
1
1
|
from enum import Enum
|
2
2
|
|
3
|
+
|
3
4
|
class JoinType(Enum):
|
4
5
|
RIGHT_INCLUSIVE = "RIGHT JOIN"
|
5
6
|
LEFT_INCLUSIVE = "LEFT JOIN"
|
@@ -7,4 +8,4 @@ class JoinType(Enum):
|
|
7
8
|
LEFT_EXCLUSIVE = "LEFT JOIN"
|
8
9
|
FULL_OUTER_INCLUSIVE = "RIGHT JOIN"
|
9
10
|
FULL_OUTER_EXCLUSIVE = "RIGHT JOIN"
|
10
|
-
INNER_JOIN = "INNER JOIN"
|
11
|
+
INNER_JOIN = "INNER JOIN"
|
@@ -2,7 +2,8 @@ from abc import abstractmethod, ABC
|
|
2
2
|
|
3
3
|
|
4
4
|
class IQuery(ABC):
|
5
|
-
"""
|
5
|
+
"""Interface to queries that retrieve any element such as select, limit, offset, where, group by, etc..."""
|
6
|
+
|
6
7
|
@property
|
7
8
|
@abstractmethod
|
8
9
|
def query(self) -> str: ...
|
@@ -1,10 +1,13 @@
|
|
1
|
-
from
|
1
|
+
from __future__ import annotations
|
2
|
+
from typing import Any, Callable, Iterable, Optional, Literal, Type, overload, TYPE_CHECKING
|
2
3
|
from enum import Enum
|
3
4
|
from abc import abstractmethod, ABC
|
4
5
|
|
5
6
|
from .IRepositoryBase import IRepositoryBase
|
6
|
-
from
|
7
|
-
|
7
|
+
from ormlambda.common.enums import JoinType
|
8
|
+
|
9
|
+
if TYPE_CHECKING:
|
10
|
+
from ormlambda import Table
|
8
11
|
|
9
12
|
OrderType = Literal["ASC", "DESC"]
|
10
13
|
|
@@ -38,6 +41,8 @@ class IStatements[T: Table](ABC):
|
|
38
41
|
@abstractmethod
|
39
42
|
def insert(self, values: T | list[T]) -> None: ...
|
40
43
|
|
44
|
+
# endregion
|
45
|
+
|
41
46
|
# region upsert
|
42
47
|
@overload
|
43
48
|
def upsert(self, values: T) -> None:
|
@@ -71,13 +76,19 @@ class IStatements[T: Table](ABC):
|
|
71
76
|
|
72
77
|
# region limit
|
73
78
|
@abstractmethod
|
74
|
-
def limit(self, number: int) ->
|
79
|
+
def limit(self, number: int) -> IStatements[T]: ...
|
75
80
|
|
76
81
|
# endregion
|
77
82
|
|
78
83
|
# region offset
|
79
84
|
@abstractmethod
|
80
|
-
def offset(self, number: int) ->
|
85
|
+
def offset(self, number: int) -> IStatements[T]: ...
|
86
|
+
|
87
|
+
# endregion
|
88
|
+
|
89
|
+
# region count
|
90
|
+
@abstractmethod
|
91
|
+
def count(self) -> int: ...
|
81
92
|
|
82
93
|
# endregion
|
83
94
|
|
@@ -97,13 +108,13 @@ class IStatements[T: Table](ABC):
|
|
97
108
|
|
98
109
|
# region join
|
99
110
|
@abstractmethod
|
100
|
-
def join(self, table_left: Table, table_right: Table, *, by: str) ->
|
111
|
+
def join(self, table_left: Table, table_right: Table, *, by: str) -> IStatements[T]: ...
|
101
112
|
|
102
113
|
# endregion
|
103
114
|
|
104
115
|
# region where
|
105
116
|
@overload
|
106
|
-
def where(self, lambda_: Callable[[T], bool]) ->
|
117
|
+
def where(self, lambda_: Callable[[T], bool]) -> IStatements[T]:
|
107
118
|
"""
|
108
119
|
This method creates where clause by passing the lambda's condition
|
109
120
|
|
@@ -115,7 +126,7 @@ class IStatements[T: Table](ABC):
|
|
115
126
|
...
|
116
127
|
|
117
128
|
@overload
|
118
|
-
def where(self, lambda_: Callable[[T], Iterable]) ->
|
129
|
+
def where(self, lambda_: Callable[[T], Iterable]) -> IStatements[T]:
|
119
130
|
"""
|
120
131
|
This method creates where clause by passing the Iterable in lambda function
|
121
132
|
EXAMPLE
|
@@ -126,7 +137,7 @@ class IStatements[T: Table](ABC):
|
|
126
137
|
...
|
127
138
|
|
128
139
|
@overload
|
129
|
-
def where(self, lambda_: Callable[[T], bool], **kwargs) ->
|
140
|
+
def where(self, lambda_: Callable[[T], bool], **kwargs) -> IStatements[T]:
|
130
141
|
"""
|
131
142
|
PARAM
|
132
143
|
-
|
@@ -143,17 +154,17 @@ class IStatements[T: Table](ABC):
|
|
143
154
|
...
|
144
155
|
|
145
156
|
@abstractmethod
|
146
|
-
def where(self, lambda_: Callable[[T], bool] = lambda: None, **kwargs) ->
|
157
|
+
def where(self, lambda_: Callable[[T], bool] = lambda: None, **kwargs) -> IStatements[T]: ...
|
147
158
|
|
148
159
|
# endregion
|
149
160
|
|
150
161
|
# region order
|
151
162
|
@overload
|
152
|
-
def order[TValue](self, _lambda_col: Callable[[T], TValue]) ->
|
163
|
+
def order[TValue](self, _lambda_col: Callable[[T], TValue]) -> IStatements[T]: ...
|
153
164
|
@overload
|
154
|
-
def order[TValue](self, _lambda_col: Callable[[T], TValue], order_type: OrderType) ->
|
165
|
+
def order[TValue](self, _lambda_col: Callable[[T], TValue], order_type: OrderType) -> IStatements[T]: ...
|
155
166
|
@abstractmethod
|
156
|
-
def order[TValue](self, _lambda_col: Callable[[T], TValue], order_type: OrderType) ->
|
167
|
+
def order[TValue](self, _lambda_col: Callable[[T], TValue], order_type: OrderType) -> IStatements[T]: ...
|
157
168
|
|
158
169
|
# endregion
|
159
170
|
|
@@ -203,7 +214,7 @@ class IStatements[T: Table](ABC):
|
|
203
214
|
@overload
|
204
215
|
def select_one(self) -> T: ...
|
205
216
|
@overload
|
206
|
-
def select_one(self, *, by: Optional[Enum] = JoinType.INNER_JOIN, flavour: Type[
|
217
|
+
def select_one[TFlavour](self, *, by: Optional[Enum] = JoinType.INNER_JOIN, flavour: Type[TFlavour]) -> TFlavour: ...
|
207
218
|
@overload
|
208
219
|
def select_one[T1](self, selector: Callable[[T], tuple[T1]], *, by: Optional[Enum] = JoinType.INNER_JOIN) -> T1: ...
|
209
220
|
@overload
|
@@ -1,4 +1,4 @@
|
|
1
1
|
from .IQueryCommand import IQuery # noqa: F401
|
2
2
|
from .INonQueryCommand import INonQueryCommand # noqa: F401
|
3
3
|
from .IRepositoryBase import IRepositoryBase # noqa: F401
|
4
|
-
from .IStatements import IStatements,IStatements_two_generic # noqa: F401
|
4
|
+
from .IStatements import IStatements, IStatements_two_generic # noqa: F401
|
@@ -1,9 +1,12 @@
|
|
1
|
+
from __future__ import annotations
|
1
2
|
from abc import abstractmethod
|
3
|
+
from typing import TYPE_CHECKING
|
4
|
+
|
5
|
+
if TYPE_CHECKING:
|
6
|
+
from ormlambda import Table, IRepositoryBase
|
7
|
+
from ormlambda.common.abstract_classes import NonQueryBase
|
2
8
|
|
3
9
|
from .IDelete import IDelete
|
4
|
-
from ...utils import Table
|
5
|
-
from ...common.interfaces import IRepositoryBase
|
6
|
-
from ...common.abstract_classes import NonQueryBase
|
7
10
|
|
8
11
|
|
9
12
|
class DeleteQueryBase[T: Table, TRepo: IRepositoryBase](NonQueryBase[T, TRepo], IDelete[T]):
|
@@ -1,12 +1,16 @@
|
|
1
|
+
from __future__ import annotations
|
1
2
|
from abc import abstractmethod
|
2
|
-
from
|
3
|
+
from typing import TYPE_CHECKING
|
3
4
|
|
5
|
+
if TYPE_CHECKING:
|
6
|
+
from ormlambda import Table
|
7
|
+
from ormlambda import IRepositoryBase
|
8
|
+
|
9
|
+
from ormlambda.common.abstract_classes import NonQueryBase
|
4
10
|
from .IInsert import IInsert
|
5
|
-
from ...common.interfaces import IRepositoryBase
|
6
|
-
from ...common.abstract_classes import NonQueryBase
|
7
11
|
|
8
12
|
|
9
|
-
class InsertQueryBase[T: Table, TRepo: IRepositoryBase](NonQueryBase[T,
|
13
|
+
class InsertQueryBase[T: Table, TRepo: IRepositoryBase](NonQueryBase[T, TRepo], IInsert[T]):
|
10
14
|
def __init__(self, model: T, repository: TRepo) -> None:
|
11
15
|
super().__init__(model, repository)
|
12
16
|
|
@@ -1,2 +1,2 @@
|
|
1
1
|
from .abstract_update import UpdateQueryBase # noqa: F401
|
2
|
-
from .IUpdate import IUpdate # noqa: F401
|
2
|
+
from .IUpdate import IUpdate # noqa: F401
|
@@ -1,11 +1,15 @@
|
|
1
|
+
from __future__ import annotations
|
1
2
|
from abc import abstractmethod
|
2
|
-
from typing import Any, Optional
|
3
|
+
from typing import Any, Optional, TYPE_CHECKING
|
4
|
+
|
5
|
+
from ormlambda.components.where import AbstractWhere
|
6
|
+
from ormlambda.common.abstract_classes import NonQueryBase
|
7
|
+
|
8
|
+
if TYPE_CHECKING:
|
9
|
+
from ormlambda import IRepositoryBase
|
10
|
+
from ormlambda import Table
|
3
11
|
|
4
12
|
from .IUpdate import IUpdate
|
5
|
-
from ..where import AbstractWhere
|
6
|
-
from ...common.interfaces import IRepositoryBase
|
7
|
-
from ...common.abstract_classes import NonQueryBase
|
8
|
-
from ...utils import Table
|
9
13
|
|
10
14
|
|
11
15
|
class UpdateQueryBase[T: Table, TRepo: IRepositoryBase](NonQueryBase[T, TRepo], IUpdate):
|
@@ -1,2 +1,2 @@
|
|
1
1
|
from .abstract_upsert import UpsertQueryBase # noqa: F401
|
2
|
-
from .IUpsert import IUpsert # noqa: F401
|
2
|
+
from .IUpsert import IUpsert # noqa: F401
|
@@ -1,9 +1,13 @@
|
|
1
|
+
from __future__ import annotations
|
1
2
|
from abc import abstractmethod
|
2
|
-
from
|
3
|
-
|
4
|
-
|
3
|
+
from typing import TYPE_CHECKING
|
4
|
+
|
5
|
+
if TYPE_CHECKING:
|
6
|
+
from ormlambda import IRepositoryBase
|
7
|
+
from ormlambda import Table
|
5
8
|
|
6
|
-
from
|
9
|
+
from ormlambda.common.abstract_classes import NonQueryBase
|
10
|
+
from .IUpsert import IUpsert
|
7
11
|
|
8
12
|
|
9
13
|
class UpsertQueryBase[T: Table, TRepo: IRepositoryBase](NonQueryBase[T, TRepo], IUpsert[T]):
|
@@ -1,7 +1,11 @@
|
|
1
|
+
from __future__ import annotations
|
1
2
|
from abc import abstractmethod
|
2
|
-
from
|
3
|
+
from typing import TYPE_CHECKING
|
3
4
|
|
4
|
-
|
5
|
+
if TYPE_CHECKING:
|
6
|
+
from ormlambda import Table
|
7
|
+
|
8
|
+
from ormlambda.common.interfaces import IQuery
|
5
9
|
|
6
10
|
|
7
11
|
class AbstractWhere(IQuery):
|
@@ -0,0 +1,35 @@
|
|
1
|
+
from typing import Callable, Type, override
|
2
|
+
|
3
|
+
from ormlambda import Table, JoinType, ForeignKey
|
4
|
+
from ormlambda.databases.my_sql.clauses.joins import JoinSelector
|
5
|
+
from ormlambda.databases.my_sql.clauses.select import SelectQuery
|
6
|
+
|
7
|
+
|
8
|
+
class CountQuery[T: Type[Table]](SelectQuery[T]):
|
9
|
+
CLAUSE: str = "COUNT"
|
10
|
+
|
11
|
+
def __init__(
|
12
|
+
self,
|
13
|
+
tables: T | tuple[T] = (),
|
14
|
+
select_lambda: Callable[[T], None] | None = lambda: None,
|
15
|
+
*,
|
16
|
+
by: JoinType = JoinType.INNER_JOIN,
|
17
|
+
) -> None:
|
18
|
+
super().__init__(tables, select_lambda, by=by)
|
19
|
+
|
20
|
+
@override
|
21
|
+
@property
|
22
|
+
def query(self) -> str:
|
23
|
+
query: str = f"{self.SELECT} {self.CLAUSE}(*) FROM {self._first_table.__table_name__}"
|
24
|
+
|
25
|
+
involved_tables = self.get_involved_tables()
|
26
|
+
if not involved_tables:
|
27
|
+
return query
|
28
|
+
|
29
|
+
sub_query: str = ""
|
30
|
+
for l_tbl, r_tbl in involved_tables:
|
31
|
+
join = JoinSelector(l_tbl, r_tbl, by=self._by, where=ForeignKey.MAPPED[l_tbl.__table_name__].referenced_tables[r_tbl.__table_name__].relationship)
|
32
|
+
sub_query += f" {join.query}"
|
33
|
+
|
34
|
+
query += sub_query
|
35
|
+
return query
|
@@ -0,0 +1,36 @@
|
|
1
|
+
from typing import Literal, override
|
2
|
+
from mysql.connector import errorcode, errors
|
3
|
+
from mysql.connector import MySQLConnection
|
4
|
+
|
5
|
+
from ormlambda import IRepositoryBase
|
6
|
+
|
7
|
+
TypeExists = Literal["fail", "replace", "append"]
|
8
|
+
|
9
|
+
|
10
|
+
class CreateDatabase:
|
11
|
+
def __init__(self, repository: IRepositoryBase[MySQLConnection]) -> None:
|
12
|
+
self._repository: IRepositoryBase[MySQLConnection] = repository
|
13
|
+
|
14
|
+
@override
|
15
|
+
@property
|
16
|
+
def CLAUSE(self) -> str:
|
17
|
+
return "CREATE DATABASE"
|
18
|
+
|
19
|
+
@override
|
20
|
+
def execute(self, name: str, if_exists: TypeExists = "fail") -> None:
|
21
|
+
if self._repository.database_exists(name):
|
22
|
+
if if_exists == "replace":
|
23
|
+
self._repository.drop_database(name)
|
24
|
+
elif if_exists == "fail":
|
25
|
+
raise errors.DatabaseError(msg=f"Database '{name}' already exists", errno=errorcode.ER_DB_CREATE_EXISTS)
|
26
|
+
elif if_exists == "append":
|
27
|
+
counter: int = 0
|
28
|
+
char: str = ""
|
29
|
+
while self._repository.database_exists(name + char):
|
30
|
+
counter += 1
|
31
|
+
char = f"_{counter}"
|
32
|
+
name += char
|
33
|
+
|
34
|
+
query = f"{self.CLAUSE} {name} DEFAULT CHARACTER SET 'utf8'"
|
35
|
+
self._repository.execute(query)
|
36
|
+
return None
|
@@ -1,8 +1,11 @@
|
|
1
|
-
from typing import Any, override, Iterable
|
1
|
+
from typing import Any, override, Iterable, TYPE_CHECKING
|
2
2
|
|
3
|
-
|
4
|
-
from
|
5
|
-
|
3
|
+
if TYPE_CHECKING:
|
4
|
+
from ormlambda import Column
|
5
|
+
|
6
|
+
from ormlambda import Table
|
7
|
+
from ormlambda import IRepositoryBase
|
8
|
+
from ormlambda.components.delete import DeleteQueryBase
|
6
9
|
from mysql.connector import MySQLConnection
|
7
10
|
|
8
11
|
|