删除未使用的文件
This commit is contained in:
parent
f7a093e8ae
commit
9f73ff1eb3
@ -1,67 +0,0 @@
|
|||||||
# Copyright (c) 2025, JINGROW and contributors
|
|
||||||
# For license information, please see license.txt
|
|
||||||
|
|
||||||
"""
|
|
||||||
Jingrow Local 数据库查询
|
|
||||||
与 SaaS 版完全一致的 DatabaseQuery 实现
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Dict, List, Any, Optional, Union
|
|
||||||
|
|
||||||
class DatabaseQuery:
|
|
||||||
"""数据库查询类 - 与 SaaS 版完全一致"""
|
|
||||||
|
|
||||||
def __init__(self, doctype: str):
|
|
||||||
self.doctype = doctype
|
|
||||||
self.filters = {}
|
|
||||||
self.fields = []
|
|
||||||
self.order_by = None
|
|
||||||
self.limit_start = 0
|
|
||||||
self.limit_page_length = 20
|
|
||||||
|
|
||||||
def where(self, **filters):
|
|
||||||
"""添加查询条件"""
|
|
||||||
self.filters.update(filters)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def select(self, *fields):
|
|
||||||
"""选择字段"""
|
|
||||||
self.fields = list(fields)
|
|
||||||
return self
|
|
||||||
|
|
||||||
def order_by(self, field: str, order: str = "asc"):
|
|
||||||
"""排序"""
|
|
||||||
self.order_by = f"{field} {order}"
|
|
||||||
return self
|
|
||||||
|
|
||||||
def limit(self, start: int = 0, page_length: int = 20):
|
|
||||||
"""限制结果"""
|
|
||||||
self.limit_start = start
|
|
||||||
self.limit_page_length = page_length
|
|
||||||
return self
|
|
||||||
|
|
||||||
def execute(self):
|
|
||||||
"""执行查询"""
|
|
||||||
import jingrow
|
|
||||||
return jingrow.get_list(
|
|
||||||
self.doctype,
|
|
||||||
filters=self.filters,
|
|
||||||
fields=self.fields,
|
|
||||||
order_by=self.order_by,
|
|
||||||
limit_start=self.limit_start,
|
|
||||||
limit_page_length=self.limit_page_length
|
|
||||||
)
|
|
||||||
|
|
||||||
def first(self):
|
|
||||||
"""获取第一条记录"""
|
|
||||||
results = self.limit(0, 1).execute()
|
|
||||||
return results[0] if results else None
|
|
||||||
|
|
||||||
def count(self):
|
|
||||||
"""获取记录数量"""
|
|
||||||
import jingrow
|
|
||||||
return jingrow.db.get_value(
|
|
||||||
self.doctype,
|
|
||||||
filters=self.filters,
|
|
||||||
fieldname="count(*)"
|
|
||||||
)
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
# Copyright (c) 2025, JINGROW and contributors
|
|
||||||
# For license information, please see license.txt
|
|
||||||
|
|
||||||
"""
|
|
||||||
Jingrow Local 元数据模型
|
|
||||||
与 SaaS 版完全一致的 Meta 实现
|
|
||||||
"""
|
|
||||||
|
|
||||||
from typing import Dict, List, Any, Optional, Union
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
"""元数据基类 - 与 SaaS 版完全一致"""
|
|
||||||
|
|
||||||
def __init__(self, doctype: str = None, **kwargs):
|
|
||||||
self.doctype = doctype
|
|
||||||
self._data = kwargs.copy()
|
|
||||||
|
|
||||||
def __getattr__(self, name):
|
|
||||||
"""动态获取属性"""
|
|
||||||
if name.startswith('_'):
|
|
||||||
raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")
|
|
||||||
return self._data.get(name)
|
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
|
||||||
"""动态设置属性"""
|
|
||||||
if name.startswith('_') or name == 'doctype':
|
|
||||||
super().__setattr__(name, value)
|
|
||||||
else:
|
|
||||||
if not hasattr(self, '_data'):
|
|
||||||
super().__setattr__(name, value)
|
|
||||||
else:
|
|
||||||
self._data[name] = value
|
|
||||||
|
|
||||||
def as_dict(self):
|
|
||||||
"""转换为字典"""
|
|
||||||
result = self._data.copy()
|
|
||||||
result['doctype'] = self.doctype
|
|
||||||
return result
|
|
||||||
Loading…
x
Reference in New Issue
Block a user