diorit.orm 0.2.1__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.
Files changed (42) hide show
  1. diorit_orm-0.2.1/PKG-INFO +15 -0
  2. diorit_orm-0.2.1/README.md +16 -0
  3. diorit_orm-0.2.1/diorit.orm.egg-info/PKG-INFO +15 -0
  4. diorit_orm-0.2.1/diorit.orm.egg-info/SOURCES.txt +40 -0
  5. diorit_orm-0.2.1/diorit.orm.egg-info/dependency_links.txt +1 -0
  6. diorit_orm-0.2.1/diorit.orm.egg-info/requires.txt +1 -0
  7. diorit_orm-0.2.1/diorit.orm.egg-info/top_level.txt +1 -0
  8. diorit_orm-0.2.1/dioritorm/__init__.py +0 -0
  9. diorit_orm-0.2.1/dioritorm/core/Database/Filter.py +105 -0
  10. diorit_orm-0.2.1/dioritorm/core/Database/OrderBy.py +42 -0
  11. diorit_orm-0.2.1/dioritorm/core/Database/__init__.py +0 -0
  12. diorit_orm-0.2.1/dioritorm/core/Database/databasehandler.py +45 -0
  13. diorit_orm-0.2.1/dioritorm/core/Database/databasemanager.py +58 -0
  14. diorit_orm-0.2.1/dioritorm/core/Database/mysqlhandler.py +714 -0
  15. diorit_orm-0.2.1/dioritorm/core/Database/sqllitehandler.py +27 -0
  16. diorit_orm-0.2.1/dioritorm/core/Fields/__init__.py +12 -0
  17. diorit_orm-0.2.1/dioritorm/core/Fields/boolean.py +23 -0
  18. diorit_orm-0.2.1/dioritorm/core/Fields/datetime.py +40 -0
  19. diorit_orm-0.2.1/dioritorm/core/Fields/number.py +57 -0
  20. diorit_orm-0.2.1/dioritorm/core/Fields/string.py +30 -0
  21. diorit_orm-0.2.1/dioritorm/core/Record.py +64 -0
  22. diorit_orm-0.2.1/dioritorm/core/Sync/__init__.py +7 -0
  23. diorit_orm-0.2.1/dioritorm/core/Sync/apimessage.py +4 -0
  24. diorit_orm-0.2.1/dioritorm/core/Sync/sync_handler.py +226 -0
  25. diorit_orm-0.2.1/dioritorm/core/__init__.py +51 -0
  26. diorit_orm-0.2.1/dioritorm/core/base.py +193 -0
  27. diorit_orm-0.2.1/dioritorm/core/config_manager.py +24 -0
  28. diorit_orm-0.2.1/dioritorm/core/constants.py +19 -0
  29. diorit_orm-0.2.1/dioritorm/core/counter.py +33 -0
  30. diorit_orm-0.2.1/dioritorm/core/data_field.py +58 -0
  31. diorit_orm-0.2.1/dioritorm/core/document.py +28 -0
  32. diorit_orm-0.2.1/dioritorm/core/entity.py +138 -0
  33. diorit_orm-0.2.1/dioritorm/core/event.py +26 -0
  34. diorit_orm-0.2.1/dioritorm/core/inforecord.py +45 -0
  35. diorit_orm-0.2.1/dioritorm/core/object.py +14 -0
  36. diorit_orm-0.2.1/dioritorm/core/reference.py +33 -0
  37. diorit_orm-0.2.1/dioritorm/core/registry.py +47 -0
  38. diorit_orm-0.2.1/dioritorm/core/table_section.py +186 -0
  39. diorit_orm-0.2.1/dioritorm/core/table_section_record.py +9 -0
  40. diorit_orm-0.2.1/dioritorm/core/tables.py +17 -0
  41. diorit_orm-0.2.1/setup.cfg +4 -0
  42. diorit_orm-0.2.1/setup.py +20 -0
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.4
2
+ Name: diorit.orm
3
+ Version: 0.2.1
4
+ Summary: Data-modeling core for application development
5
+ Author: bogdanAntonjuk
6
+ Author-email: info@diorit.com.ua
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Dist: mysql-connector-python
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: classifier
14
+ Dynamic: requires-dist
15
+ Dynamic: summary
@@ -0,0 +1,16 @@
1
+ # App
2
+
3
+ ???? ???????' ???>?? ?????+???'?? ?? ?+???????? ????????:)
4
+
5
+ ## Підключення через corebrix
6
+
7
+ ```
8
+ pip install corebrix
9
+ ```
10
+
11
+ ```python
12
+ from dioritorm import SyncHandler
13
+
14
+ handler = SyncHandler()
15
+ handler.save({"object": "Invoice", "items": []})
16
+ ```
@@ -0,0 +1,15 @@
1
+ Metadata-Version: 2.4
2
+ Name: diorit.orm
3
+ Version: 0.2.1
4
+ Summary: Data-modeling core for application development
5
+ Author: bogdanAntonjuk
6
+ Author-email: info@diorit.com.ua
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Classifier: Operating System :: OS Independent
10
+ Requires-Dist: mysql-connector-python
11
+ Dynamic: author
12
+ Dynamic: author-email
13
+ Dynamic: classifier
14
+ Dynamic: requires-dist
15
+ Dynamic: summary
@@ -0,0 +1,40 @@
1
+ README.md
2
+ setup.py
3
+ diorit.orm.egg-info/PKG-INFO
4
+ diorit.orm.egg-info/SOURCES.txt
5
+ diorit.orm.egg-info/dependency_links.txt
6
+ diorit.orm.egg-info/requires.txt
7
+ diorit.orm.egg-info/top_level.txt
8
+ dioritorm/__init__.py
9
+ dioritorm/core/Record.py
10
+ dioritorm/core/__init__.py
11
+ dioritorm/core/base.py
12
+ dioritorm/core/config_manager.py
13
+ dioritorm/core/constants.py
14
+ dioritorm/core/counter.py
15
+ dioritorm/core/data_field.py
16
+ dioritorm/core/document.py
17
+ dioritorm/core/entity.py
18
+ dioritorm/core/event.py
19
+ dioritorm/core/inforecord.py
20
+ dioritorm/core/object.py
21
+ dioritorm/core/reference.py
22
+ dioritorm/core/registry.py
23
+ dioritorm/core/table_section.py
24
+ dioritorm/core/table_section_record.py
25
+ dioritorm/core/tables.py
26
+ dioritorm/core/Database/Filter.py
27
+ dioritorm/core/Database/OrderBy.py
28
+ dioritorm/core/Database/__init__.py
29
+ dioritorm/core/Database/databasehandler.py
30
+ dioritorm/core/Database/databasemanager.py
31
+ dioritorm/core/Database/mysqlhandler.py
32
+ dioritorm/core/Database/sqllitehandler.py
33
+ dioritorm/core/Fields/__init__.py
34
+ dioritorm/core/Fields/boolean.py
35
+ dioritorm/core/Fields/datetime.py
36
+ dioritorm/core/Fields/number.py
37
+ dioritorm/core/Fields/string.py
38
+ dioritorm/core/Sync/__init__.py
39
+ dioritorm/core/Sync/apimessage.py
40
+ dioritorm/core/Sync/sync_handler.py
@@ -0,0 +1 @@
1
+ mysql-connector-python
@@ -0,0 +1 @@
1
+ dioritorm
File without changes
@@ -0,0 +1,105 @@
1
+ from enum import Enum
2
+
3
+
4
+ class FilterOperator(Enum):
5
+ EQUALS = "=="
6
+ IN = "IN"
7
+ NOT_EQUALS = "!="
8
+ GREATER = ">"
9
+ LESS = "<"
10
+ GREATER_EQUALS = ">="
11
+ LESS_EQUALS = "<="
12
+ CONTAINS = "LIKE"
13
+ STARTS_WITH = "STARTS_WITH"
14
+ ENDS_WITH = "ENDS_WITH"
15
+
16
+
17
+ class LogicalOperator(Enum):
18
+ AND = "AND"
19
+ OR = "OR"
20
+
21
+
22
+ class Filter:
23
+ def __init__(self):
24
+ self.conditions = []
25
+ self.logical_operator = LogicalOperator.AND
26
+
27
+ def add(self, field, operator, value):
28
+ """
29
+ Додає умову фільтрації
30
+
31
+ :param field: Поле для фільтрації
32
+ :param operator: Оператор фільтрації (з FilterOperator)
33
+ :param value: Значення для порівняння
34
+ """
35
+ self.conditions.append({
36
+ "field": field,
37
+ "operator": operator,
38
+ "value": value
39
+ })
40
+ return self
41
+
42
+ def and_logic(self):
43
+ """Встановлює логічний оператор AND між умовами"""
44
+ self.logical_operator = LogicalOperator.AND
45
+ return self
46
+
47
+ def or_logic(self):
48
+ """Встановлює логічний оператор OR між умовами"""
49
+ self.logical_operator = LogicalOperator.OR
50
+ return self
51
+
52
+ def to_sql(self):
53
+ """
54
+ Конвертує фільтр в SQL WHERE умову
55
+
56
+ :return: tuple(рядок SQL, параметри)
57
+ """
58
+ if not self.conditions:
59
+ return "", []
60
+
61
+ sql_parts = []
62
+ params = []
63
+
64
+ for condition in self.conditions:
65
+ field = condition["field"]
66
+ op = condition["operator"]
67
+ value = condition["value"]
68
+
69
+ if op == FilterOperator.EQUALS:
70
+ sql_parts.append(f"{field} = %s")
71
+ params.append(value)
72
+ elif op == FilterOperator.IN:
73
+ if not isinstance(value, (list, tuple)) or not value:
74
+ sql_parts.append("FALSE") # Ніколи не спрацює, якщо список порожній
75
+ else:
76
+ placeholders = ', '.join(['%s'] * len(value))
77
+ sql_parts.append(f"{field} IN ({placeholders})")
78
+ params.extend(value)
79
+ elif op == FilterOperator.NOT_EQUALS:
80
+ sql_parts.append(f"{field} != %s")
81
+ params.append(value)
82
+ elif op == FilterOperator.GREATER:
83
+ sql_parts.append(f"{field} > %s")
84
+ params.append(value)
85
+ elif op == FilterOperator.LESS:
86
+ sql_parts.append(f"{field} < %s")
87
+ params.append(value)
88
+ elif op == FilterOperator.GREATER_EQUALS:
89
+ sql_parts.append(f"{field} >= %s")
90
+ params.append(value)
91
+ elif op == FilterOperator.LESS_EQUALS:
92
+ sql_parts.append(f"{field} <= %s")
93
+ params.append(value)
94
+ elif op == FilterOperator.CONTAINS:
95
+ sql_parts.append(f"{field} LIKE %s")
96
+ params.append(f"%{value}%")
97
+ elif op == FilterOperator.STARTS_WITH:
98
+ sql_parts.append(f"{field} LIKE %s")
99
+ params.append(f"{value}%")
100
+ elif op == FilterOperator.ENDS_WITH:
101
+ sql_parts.append(f"{field} LIKE %s")
102
+ params.append(f"%{value}")
103
+
104
+ logical_op = f" {self.logical_operator.value} "
105
+ return logical_op.join(sql_parts), params
@@ -0,0 +1,42 @@
1
+ from enum import Enum
2
+
3
+
4
+ class OrderDirection(Enum):
5
+ ASC = "ASC"
6
+ DESC = "DESC"
7
+
8
+
9
+ class OrderBy:
10
+ def __init__(self):
11
+ self.order_fields = []
12
+
13
+ def add(self, field, direction=OrderDirection.ASC):
14
+ """
15
+ Додає поле для сортування
16
+
17
+ :param field: Поле для сортування
18
+ :param direction: Напрямок сортування (за замовчуванням ASC)
19
+ """
20
+ self.order_fields.append({
21
+ "field": field,
22
+ "direction": direction
23
+ })
24
+ return self
25
+
26
+ def to_sql(self):
27
+ """
28
+ Конвертує параметри сортування в SQL ORDER BY умову
29
+
30
+ :return: рядок SQL ORDER BY
31
+ """
32
+ if not self.order_fields:
33
+ return ""
34
+
35
+ order_parts = []
36
+
37
+ for order in self.order_fields:
38
+ field = order["field"]
39
+ direction = order["direction"].value
40
+ order_parts.append(f"{field} {direction}")
41
+
42
+ return ", ".join(order_parts)
File without changes
@@ -0,0 +1,45 @@
1
+ from abc import ABC, abstractmethod
2
+ #from app.core.base import Base
3
+
4
+ class DatabaseHandler:
5
+ def __init__(self):
6
+ super().__init__()
7
+
8
+ @abstractmethod
9
+ def connect(self):
10
+ pass
11
+
12
+ def close(self):
13
+ raise NotImplementedError
14
+
15
+ def save(self,data):
16
+ raise NotImplementedError
17
+
18
+ def delete(self, entity, filter=None):
19
+ # Changed: allow handlers to receive optional Filter for conditional deletes.
20
+ raise NotImplementedError
21
+
22
+ def get(self, entity_ref):
23
+ raise NotImplementedError
24
+
25
+ def getList(self,entity):
26
+ raise NotImplementedError
27
+
28
+ @abstractmethod
29
+ def commit(self):
30
+ pass
31
+
32
+ @abstractmethod
33
+ def rollback(self):
34
+ pass
35
+
36
+ def __enter__(self):
37
+ self.connect()
38
+ return self
39
+
40
+ def __exit__(self, exc_type, exc_value, traceback):
41
+ if exc_type:
42
+ self.rollback()
43
+ else:
44
+ self.commit()
45
+ self.close()
@@ -0,0 +1,58 @@
1
+ #from app.core.base import Base
2
+ from dioritorm.core.constants import *
3
+ from .mysqlhandler import MySQLHandler
4
+ from .sqllitehandler import SQLiteHandler
5
+
6
+ class DatabaseManger:
7
+
8
+ def __init__(self):
9
+ super().__init__()
10
+ self.databaseType = DATABASE_TYPE
11
+ self.handlers = {
12
+ "mysql":MySQLHandler(),
13
+ "sqllite":SQLiteHandler()
14
+ }
15
+
16
+ def _getHandler(self):
17
+ if self.databaseType not in self.handlers:
18
+ raise ValueError(f"Unsupported database type: {self.databaseType}")
19
+ return self.handlers[self.databaseType]
20
+
21
+ def save(self,data,connection = None):
22
+ handler = self._getHandler()
23
+ #handler.save(table_name, json_data)
24
+ handler.save(data,connection)
25
+
26
+ def getByUUID(self,entity,ref):
27
+ handler = self._getHandler()
28
+ handler.getByUUID(entity,ref)
29
+
30
+ def delete(self,entity,filter=None):
31
+ handler = self._getHandler()
32
+ handler.delete(entity,filter) # Changed: forward entity and optional Filter to handler-level delete logic.
33
+
34
+
35
+ def getList(self,entity,filter=None, orderBy=None, limit=None, offset=None):
36
+ handler = self._getHandler()
37
+ return handler.getList(entity,filter,orderBy,limit,offset)
38
+
39
+ def close(self):
40
+ handler = self._getHandler()
41
+ handler.close()
42
+
43
+ def restruct(self,schema):
44
+ handler = self._getHandler()
45
+ handler.restruct(schema)
46
+ pass
47
+
48
+ def __enter__(self):
49
+ handler = self._getHandler()
50
+ return handler
51
+
52
+ def __exit__(self, exc_type, exc_value, traceback):
53
+ handler = self._getHandler()
54
+ if exc_type:
55
+ handler.connect().rollback()
56
+ else:
57
+ handler.connect().commit()
58
+ handler.close()