|
8 | 8 | from sqlmodel.ext.asyncio.session import AsyncSession |
9 | 9 |
|
10 | 10 | from common.config import conf |
11 | | -from common.enums import ModelType |
| 11 | +from common.enums import DBOperator, ModelType |
12 | 12 | from common.serializers import BaseTable, DBQuery, FilterQuery, RowLike |
13 | 13 | from common.utils.errors import ErrorService |
14 | 14 | from common.utils.log import logger |
15 | 15 | from common.utils.parse_obj import set_elements_by_dict |
16 | 16 |
|
17 | 17 | opts = { |
18 | | - "eq": "__eq__", |
19 | | - "ne": "__ne__", |
20 | | - "lt": "__lt__", |
21 | | - "le": "__le__", |
22 | | - "gt": "__gt__", |
23 | | - "ge": "__ge__", |
24 | | - "like": "like", |
25 | | - "ilike": "ilike", # PostgreSQL only |
26 | | - "in": "in_", |
27 | | - "not_in": "notin_", |
28 | | - "is_null": "is_", |
| 18 | + DBOperator.eq: "__eq__", |
| 19 | + DBOperator.ne: "__ne__", |
| 20 | + DBOperator.lt: "__lt__", |
| 21 | + DBOperator.le: "__le__", |
| 22 | + DBOperator.gt: "__gt__", |
| 23 | + DBOperator.ge: "__ge__", |
| 24 | + DBOperator.like: "like", |
| 25 | + DBOperator.ilike: "ilike", # PostgreSQL only |
| 26 | + DBOperator.in_: "in_", |
| 27 | + DBOperator.not_in: "notin_", |
| 28 | + DBOperator.is_null: "is_", |
29 | 29 | } |
30 | 30 |
|
31 | 31 |
|
@@ -195,7 +195,7 @@ async def delete_rows( |
195 | 195 | @classmethod |
196 | 196 | async def get_by_id(cls, _id: str | int, **kwargs): |
197 | 197 | filter_query = FilterQuery( |
198 | | - query=[DBQuery(key=cls.table.id.key, opt="eq", value=int(_id))], |
| 198 | + query=[DBQuery(key=cls.table.id.key, opt=DBOperator.eq, value=int(_id))], |
199 | 199 | relation_model=kwargs.get("relation_model", False), |
200 | 200 | ) |
201 | 201 | return await cls.fetch_rows(filter_query=filter_query, limit=1) |
0 commit comments