diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..a83f793309ed7985e8d07adb0295001fd60abbe4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.idea +__pycache__/ +setup.py +upload.bat +pyproject.toml +delete.py +*.pyc \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 8f02d69fcb5a98d02eebec4fb93cab6b854c9dee..0000000000000000000000000000000000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/../../../../:\Github\CACodeFramework-python-ORM\.idea/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/CACodeFramework-python-ORM.iml b/.idea/CACodeFramework-python-ORM.iml deleted file mode 100644 index 5ed0139f27bed0fe8b3612df9b3ca502d70295bb..0000000000000000000000000000000000000000 --- a/.idea/CACodeFramework-python-ORM.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index da484797c158b883f2d96a10bf70ccfcdca0d2fe..0000000000000000000000000000000000000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2da2d6447d11dfe32bfb846c3d5b199fc99..0000000000000000000000000000000000000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index d56657add3eb3c246989284ec6e6a8475603cf1d..0000000000000000000000000000000000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 99e9e955e8d95bcaddbec9f85230693536e2e743..0000000000000000000000000000000000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f4cb416c083d265558da75d457237d671..0000000000000000000000000000000000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/CACodeFramework/MainWork/Annotations.py b/CACodeFramework/MainWork/Annotations.py deleted file mode 100644 index 2f3df4be341a21106a49e6b000b51082e6ba9fa7..0000000000000000000000000000000000000000 --- a/CACodeFramework/MainWork/Annotations.py +++ /dev/null @@ -1,92 +0,0 @@ -def Table(name, msg, **kwargs): - """ - 标注该类为一个表 - :param name:表的名称 - :param msg:表的描述 - :return: - """ - - def set_to_field(func): - setattr(func, '__table_name__', name) - setattr(func, '__table_msg__', msg) - for key, value in kwargs.items(): - setattr(func, key, value) - return func - - return set_to_field - - -def Operations(): - """ - 标注该类为一个操做 - :return: - """ - - def set_to_field(func): - print('1111111') - return func - - return set_to_field - - -def Before(function): - """ - 切入操做,在执行函数之前切入指定函数 - - 切入: - - 在执行函数之前首先执行指定操做称为切入 - - """ - - def set_to_field(func): - print('1111111') - return func - - return set_to_field - - -def After(function): - """ - 切出操做,在执行函数之前切出指定函数 - - 切出: - - 在指定函数调用完毕时执行得操做成为切除 - """ - - def set_to_field(func): - print('1111111') - return func - - return set_to_field - - -from functools import wraps - - -def decorater(func): - @wraps(func) # 保持原函数名不变 - def wrapper(*args, **kwargs): - print('位置参数:{}'.format(args)) - print('关键字参数:{}'.format(kwargs)) - res = func(*args, **kwargs) - print('装饰器内函数名:%s' % func.__name__) - print('返回值:%s' % res) - print('函数func所属的类:%s' % func.__qualname__) - print('被调用时的行号:', sys._getframe().f_back.f_lineno) - return res - - return wrapper - - -class Name(): - @decorater - def func2(self, *args, **kwargs): - return 'return' - - -if __name__ == '__main__': - a = Name() - a.func2(1, 2, a=3, b=4) - print('装饰外内函数名:%s' % a.func2.__name__) diff --git a/CACodeFramework/MainWork/CACodePureORM.py b/CACodeFramework/MainWork/CACodePureORM.py index 95ae8e6a61402994d50ea2facd11e1ce3b3f9b97..2bae36728d926afa7040704fc2ded2c6fcfb2ad6 100644 --- a/CACodeFramework/MainWork/CACodePureORM.py +++ b/CACodeFramework/MainWork/CACodePureORM.py @@ -1,5 +1,5 @@ # 纯净ORM -from CACodeFramework.MainWork.opera import obj_dict, op_db +from CACodeFramework.opera import obj_dict, op_db from CACodeFramework.util.ParseUtil import ParseUtil from CACodeFramework.field.sql_fields import * @@ -30,6 +30,15 @@ class CACodePureORM(object): self.__table_name__ = '{}{}{}'.format(subscript, repository.__table_name__, subscript) self.parses = obj_dict.parses() + self.first_data = False + + def first(self): + """ + 是否只返回第一行数据 + """ + self.first_data = True + return self + # ------------------------主键-------------------------- def insert(self, pojo): @@ -309,7 +318,11 @@ class CACodePureORM(object): # 清空资源,为下一次使用做准备 self.args.clear() self.params.clear() - return _result + if self.first_data: + if type(_result) is list or type(_result) is tuple: + return _result[0] + else: + return _result def con_from(self): """ diff --git a/CACodeFramework/MainWork/CACodeRepository.py b/CACodeFramework/MainWork/CACodeRepository.py index 4fd0061f59778085aa3c13cbeb3fb3e4b7096ff7..43adfa3b950b5369d031ca0f0f40bb77f0bba260 100644 --- a/CACodeFramework/MainWork/CACodeRepository.py +++ b/CACodeFramework/MainWork/CACodeRepository.py @@ -1,6 +1,6 @@ import copy -from CACodeFramework.MainWork.opera import op_db +from CACodeFramework.opera import op_db from CACodeFramework.util.Log import CACodeLog from CACodeFramework.MainWork.CACodePureORM import CACodePureORM @@ -79,7 +79,7 @@ class Repository(object): # 模板类 self.participants = participants # 该对象的所有字段 - fds = participants.to_dict() + fds = participants.fields self.fields = list(fds.keys()) # 配置类 self.config_obj = config_obj @@ -223,8 +223,6 @@ class Repository(object): - 可自动化操作 - 请尽量使用find_many(sql)操作 :param kwargs:包含所有参数: - pojo:参照对象 - last_id:是否需要返回最后一行数据,默认False sql:处理过并加上%s的sql语句 params:需要填充的字段 print_sql:是否打印sql语句 diff --git a/CACodeFramework/MainWork/__pycache__/Annotations.cpython-39.pyc b/CACodeFramework/MainWork/__pycache__/Annotations.cpython-39.pyc deleted file mode 100644 index f8c58dfeae26ae8cd288a70af163dc1c38a14678..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/__pycache__/Annotations.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/__pycache__/CACodePojo.cpython-39.pyc b/CACodeFramework/MainWork/__pycache__/CACodePojo.cpython-39.pyc deleted file mode 100644 index 67d39a40abb877adc9e874b3813652affcb8815d..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/__pycache__/CACodePojo.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/__pycache__/CACodePureORM.cpython-39.pyc b/CACodeFramework/MainWork/__pycache__/CACodePureORM.cpython-39.pyc deleted file mode 100644 index 85963b53b56f0e106fc91e799f0914f2dda84f19..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/__pycache__/CACodePureORM.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/__pycache__/CACodeRepository.cpython-39.pyc b/CACodeFramework/MainWork/__pycache__/CACodeRepository.cpython-39.pyc deleted file mode 100644 index 6c5f6d5ee8ca3907f3d13315f3c766b03e158e58..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/__pycache__/CACodeRepository.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/__pycache__/__init__.cpython-39.pyc b/CACodeFramework/MainWork/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 5c70e4f5f15a98629aa4c960d98cb2cbf49c3057..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/exception/__pycache__/__init__.cpython-39.pyc b/CACodeFramework/MainWork/exception/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 5c21c0cdea6d85f7db1f3b09a11612f523499b8d..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/exception/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/exception/__pycache__/e_except.cpython-39.pyc b/CACodeFramework/MainWork/exception/__pycache__/e_except.cpython-39.pyc deleted file mode 100644 index ada947f55639221d46c2c7efd801b2a60f578755..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/exception/__pycache__/e_except.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/exception/e_except.py b/CACodeFramework/MainWork/exception/e_except.py deleted file mode 100644 index d76a1c846b109c8c671cd7f17597f51ee5aa6f80..0000000000000000000000000000000000000000 --- a/CACodeFramework/MainWork/exception/e_except.py +++ /dev/null @@ -1,41 +0,0 @@ -from datetime import datetime -import warnings - -from CACodeFramework.field import e_fields - - -def warn(obj, line, msg, f_warn, LogObject=None, task_name='\t\tMAIN'): - """作者:CACode 最后编辑于2021/4/13 - - 输出日志并返回日志内容 - - 此方法不会中断程序运行 - - 格式: - - 时间 类型 日志名称 对象地址 被调用行号 执行类型 信息 - 示例: - - line:234: Warning: 2021-04-13 08:24:08.169 WARN CACode-Database-Operation [1907116304800] [line:234] [2021-04-13 08:24:08.169] :INITIALIZE THIS OBJECT - """ - t = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] - info = '{} {} {} [{}] [{}] [{}] \t\t\t:{}'.format(t, f_warn, - e_fields.LOG_OPERA_NAME, - id(obj), - obj.__str__(), - task_name, - msg) - # 输出日志信息 - warnings.warn_explicit(info, category=Warning, filename='line', lineno=line) - if LogObject is not None: - LogObject.warn(info) - return info - - -def error(cls, msg): - """作者:CACode 最后编辑于2021/4/13 - - 抛出异常并终止程序执行 - Atte - """ - raise cls(msg) diff --git a/CACodeFramework/MainWork/opera/__pycache__/__init__.cpython-39.pyc b/CACodeFramework/MainWork/opera/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 182160f084aff99160926d35493f7004b84dff6b..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/opera/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/opera/__pycache__/obj_dict.cpython-39.pyc b/CACodeFramework/MainWork/opera/__pycache__/obj_dict.cpython-39.pyc deleted file mode 100644 index 7475998d1dbe35583e3c538fb681aa6ac2e4e080..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/opera/__pycache__/obj_dict.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/opera/__pycache__/op_db.cpython-39.pyc b/CACodeFramework/MainWork/opera/__pycache__/op_db.cpython-39.pyc deleted file mode 100644 index 3344c3ad6be5eda086b00a7262216aa8f98fa62d..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/MainWork/opera/__pycache__/op_db.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/__pycache__/__init__.cpython-39.pyc b/CACodeFramework/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 4b3cc958dcf1b08eb490f01173a3b9ba80737d6d..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/MainWork/exception/__init__.py b/CACodeFramework/anno/__init__.py similarity index 100% rename from CACodeFramework/MainWork/exception/__init__.py rename to CACodeFramework/anno/__init__.py diff --git a/CACodeFramework/anno/annos.py b/CACodeFramework/anno/annos.py new file mode 100644 index 0000000000000000000000000000000000000000..d68949cbdf383db7cd0ef1a4657e28b7a8b1efee --- /dev/null +++ b/CACodeFramework/anno/annos.py @@ -0,0 +1,38 @@ +import types +from functools import wraps + + +def Table(name, msg, **kwargs): + """ + 标注该类为一个表 + :param name:表的名称 + :param msg:表的描述 + :return: + """ + + def set_to_field(cls): + setattr(cls, '__table_name__', name) + setattr(cls, '__table_msg__', msg) + for key, value in kwargs.items(): + setattr(cls, key, value) + return cls + + return set_to_field + + +def Select(sql, params=None, print_sql=False): + def base_func(cls): + def _wrapper_(*args, **kwargs): + l = list(args) + del l[0] + cls_obj = cls(*l, **kwargs) + obj = cls_obj.meta() + + result = obj.find_sql(sql=sql, params=params, print_sql=print_sql) + setattr(cls_obj, 'result', result) + + return cls_obj + + return _wrapper_ + + return base_func diff --git a/CACodeFramework/anno/aop.py b/CACodeFramework/anno/aop.py new file mode 100644 index 0000000000000000000000000000000000000000..bb1d289e05011a1968615d9d32a6aa707d16b34f --- /dev/null +++ b/CACodeFramework/anno/aop.py @@ -0,0 +1,355 @@ +import types + + +class AopModel_Object(object): + """ + 此类为AopModel提供所有操作 + """ + + def __init__(self, before=None, after=None, + before_args=None, before_kwargs=None, + after_args=None, after_kwargs=None): + # wraps(func)(self) + # self.func = func + # 初始化所有字段 + self.__before_func__ = before + self.__before_args_data__ = before_args + self.__before_kwargs_data__ = before_kwargs + + self.__after_func__ = after + self.__after_args_data__ = after_args + self.__after_kwargs_data__ = after_kwargs + + def set_func(self, func): + self.func = func + + def set_args(self, *args, **kwargs): + self.args = args + self.kwargs = kwargs + + def start(self): + """ + 主操作 + """ + + # self.func = args[0] + self.init_fields() + # wraps(self.func)(self) + self.init_attr() + + # 解析参数需要 + # self.before_parse() + # 执行before操作 + self.before_run() + # 执行原始数据 + result = self.original_func() + # after解析 + # self.after_parse(result) + # after操作 + self.after_run(result) + # 返回原始数据 + return result + + def init_fields(self): + # 定义名称规则 + self.after = 'after' + self.after_args = 'after_args' + self.after_kwargs = 'after_kwargs' + + self.before = 'before' + self.before_args = 'before_args' + self.before_kwargs = 'before_kwargs' + + self.__after__ = '__after_func__' + self.__after_args__ = '__after_args__' + self.__after_kwargs__ = '__after_kwargs__' + + # 得到before参数的名称 + self.__before_name__ = self.format_name(self.before) + self.__before_args_name__ = self.format_name(self.before_args) + self.__before_kwargs_name__ = self.format_name(self.before_kwargs) + + # 得到after参数的名称 + + self.__after_name__ = self.format_name(self.__after__) + self.__after_args_name__ = self.format_name(self.__after_args__) + self.__after_kwargs_name__ = self.format_name(self.__after_kwargs__) + + def __get__(self, instance, cls): + if instance is None: + return self + else: + return types.MethodType(self, instance) + + def format_name(self, name): + """ + 格式化名称字符串 + """ + return '{}{}'.format(name, self.func.__name__) + + def setters(self, i1, i2, i3, k1, v1, k2, v2, k3, v3): + """ + 批量设置 + """ + if i1 in self.__dict__.keys(): + setattr(self, v1, self.__dict__[k1]) + if i2 in self.__dict__.keys(): + setattr(self, v2, self.__dict__[k2]) + if i3 in self.__dict__.keys(): + setattr(self, v3, self.__dict__[k3]) + + def init_attr(self): + """ + 初始化cls下的字段 + 通过使用setters下的setter()功能批量解析是否需要before或者after操作 + """ + + self.setters( + i1=self.before, + i2=self.before_args, + i3=self.before_kwargs, + k1=self.before, + k2=self.before_args, + k3=self.before_kwargs, + v3=self.__before_kwargs_name__, + v1=self.__before_name__, + v2=self.__before_args_name__, + ) + + self.setters( + i1=self.after, + i2=self.after_args, + i3=self.after_kwargs, + k1=self.after, + k2=self.after_args, + k3=self.after_kwargs, + v1=self.__after_name__, + v2=self.__after_args_name__, + v3=self.__after_kwargs_name__ + ) + + # def before_parse(self): + # """ + # 解析before参数的方法需要什么参数类型 + # """ + # __before_func__ = None + # __before_args_data__ = None + # __before_kwargs_data__ = None + # # 如果包含切入函数的字段 + # if hasattr(self, self.__before_name__): + # # 得到参数的名称 + # __before_func__ = getattr(self, self.__before_name__) + # if hasattr(self, self.__before_args_name__) and hasattr(self, self.__before_kwargs_name__): + # + # __before_args_data__ = getattr(self, self.__before_args_name__) + # __before_kwargs_data__ = getattr(self, self.__before_kwargs_name__) + # + # elif hasattr(self, self.__before_args_name__): + # __before_args_data__ = getattr(self, self.__before_args_name__) + # + # elif hasattr(self, self.__before_kwargs_name__): + # __before_kwargs_data__ = getattr(self, self.__before_kwargs_name__) + # + # # 批添加方法、参数和键值对 + # self.__before_func__ = __before_func__ + # self.__before_args_data__ = __before_args_data__ + # self.__before_kwargs_data__ = __before_kwargs_data__ + + def before_run(self): + """ + 执行before方法 + """ + if self.__before_func__ and self.__before_args_data__ and self.__before_kwargs_data__: + self.__before_func__(*self.__before_args_data__, **self.__before_kwargs_data__) + elif self.__before_func__ and self.__before_args_data__: + self.__before_func__(*self.__before_args_data__) + elif self.__before_func__ and self.__before_kwargs_data__: + self.__before_func__(**self.__before_kwargs_data__) + elif self.__before_func__: + self.__before_func__() + else: + pass + + # def after_parse(self, result): + # """ + # 解析追加方法 + # :param result:原始方法返回的值 + # """ + # __after_func__ = None + # __after_args_data__ = None + # __after_kwargs_data__ = {} + # # 如果包含切入函数的字段 + # if hasattr(self, self.__after_name__): + # # 得到参数的名称 + # __after_func__ = getattr(self, self.__after_name__) + # if hasattr(self, self.__after_args_name__) and hasattr(self, self.__after_kwargs_name__): + # + # __after_args_data__ = getattr(self, self.__after_args_name__) + # __after_kwargs_data__ = getattr(self, self.__after_kwargs_name__) + # + # elif hasattr(self, self.__after_args_name__): + # __after_args_data__ = getattr(self, self.__after_args_name__) + # + # elif hasattr(self, self.__after_kwargs_name__): + # __after_kwargs_data__ = getattr(self, self.__after_kwargs_name__) + # + # # 批添加方法、参数和键值对 + # self.__after_func__ = __after_func__ + # self.__after_args_data__ = __after_args_data__ + # __after_kwargs_data__.update({'result': result}) + # self.__after_kwargs_data__ = __after_kwargs_data__ + + def after_run(self, result): + """ + 执行after方法 + """ + if self.__after_kwargs_data__ is None: + self.__after_kwargs_data__ = {} + + self.__after_kwargs_data__.update({'result': result}) + if self.__after_func__ and self.__after_args_data__ and self.__after_kwargs_data__: + self.__after_func__(*self.__after_args_data__, **self.__after_kwargs_data__) + elif self.__after_func__ and self.__after_args_data__: + self.__after_func__(*self.__after_args_data__) + elif self.__after_func__ and self.__after_kwargs_data__: + self.__after_func__(**self.__after_kwargs_data__) + elif self.__after_func__: + self.__after_func__() + else: + pass + + def original_func(self): + """ + 最后耍无赖方法返回函数执行的结果 + 使用四个try逐一抛出 + """ + try: + return self.func(*self.args, **self.kwargs) + except TypeError as e: + pass + + try: + return self.func(*self.args) + except TypeError as e: + pass + + try: + return self.func(**self.kwargs) + except TypeError as e: + pass + + try: + return self.func() + except TypeError as e: + pass + + +def AopModel(before=None, after=None, + before_args=None, before_kwargs=None, + after_args=None, after_kwargs=None): + """ + + AOP切面模式: + 依赖AopModel装饰器,再在方法上加入@AopModel即可切入编程 + + + 优点: + + 当使用@AopModel时,内部函数将会逐级调用回调函数,执行循序是: + - func(*self.args, **self.kwargs) + - func(*self.args) + - func(**self.kwargs) + - func() + 这将意味着,如果你的参数传入错误时,AopModel依旧会遵循原始方法所使用的规则,最令人大跌眼镜的使用方法就是: + + def Before(**kwargs): + print('Before:', kwargs) + # 此处的Before方法未存在args参数,而使用@AopModel时却传入了args + @AopModel(before=Before,before_args=(0,1,2), before_kwargs={'1': '1'}) + def find_title_and_selects(self, **kwargs): + + print('function task', kwargs['uid']) + + _r = self.orm.find().where(index="<<100").end() + + print(_r) + + return _r + + 其中包含参数有: + before:切入时需要执行的函数 + + before_args:切入的参数 + 传入的列表或元组类型数据 + 如果是需要使用当前pojo中的内容时,传参格式为:(pojo.字段名) + 可扩展格式,例如需要传入字典 + + before_kwargs:切入的参数 -- 传入的字典数据 + + after:切出前需要执行的参数 + + after_args:切出的参数 + 传入的列表或元组类型数据 + 如果是需要使用当前pojo中的内容时,传参格式为:('self.字段名') + 可扩展格式,例如需要传入字典:('self.dict.key') + + after_kwargs:切出的参数 -- 传入的字典数据 + + + 执行流程: + + Before->original->After + + Before注意事项: + + 使用该参数时,方法具有返回值概不做处理,需要返回值内容可使用`global`定义一个全局字段用于保存数值 + + 当无法解析或者解析失败时m将使用pass关键字忽略操作 + + After注意事项: + + 使用该参数时,必须搭配至少一个result=None的kwargs存在于方法的形参中, + + 当original方法执行完成将把返回值固定使用result键值对注入到该函数中 + + 当无法解析或者解析失败时m将使用pass关键字忽略操作 + + + + Attributes: + + before:切入时需要执行的函数 + + after:切出前需要执行的参数 + + before_args:切入的参数 + 传入的列表或元组类型数据 + 如果是需要使用当前pojo中的内容时,传参格式为:(pojo.字段名) + 可扩展格式,例如需要传入字典 + + before_kwargs:切入的参数 -- 传入的字典数据 + + after_args:切出的参数 + 传入的列表或元组类型数据 + 如果是需要使用当前pojo中的内容时,传参格式为:('self.字段名') + 可扩展格式,例如需要传入字典:('self.dict.key') + + after_kwargs:切出的参数 -- 传入的字典数据 + + + """ + # 得到对象组 + aop_obj = AopModel_Object(before, after, + before_args, before_kwargs, + after_args, after_kwargs) + + def base_func(func): + aop_obj.set_func(func) + + def _wrapper_(*args, **kwargs): + aop_obj.set_args(*args, **kwargs) + return aop_obj.start() + + return _wrapper_ + + return base_func diff --git a/CACodeFramework/MainWork/opera/__init__.py b/CACodeFramework/cache/__init__.py similarity index 100% rename from CACodeFramework/MainWork/opera/__init__.py rename to CACodeFramework/cache/__init__.py diff --git a/util/__init__.py b/CACodeFramework/exception/__init__.py similarity index 100% rename from util/__init__.py rename to CACodeFramework/exception/__init__.py diff --git a/CACodeFramework/field/e_fields.py b/CACodeFramework/exception/e_fields.py similarity index 47% rename from CACodeFramework/field/e_fields.py rename to CACodeFramework/exception/e_fields.py index 75669c81219cd294e30d7147e36c43ab2f6bb29d..1d1b89f5c8b548ae77ed1e6fce453d8bb095c454 100644 --- a/CACodeFramework/field/e_fields.py +++ b/CACodeFramework/exception/e_fields.py @@ -1,7 +1,8 @@ -JSON_ERROR = 'CACode-J' -SYNTAX_ERROR = 'CACode-S' -ATTR_ERROR = 'CACode-A' +JSON_ERROR = 'CACode-Json' +SYNTAX_ERROR = 'CACode-Syntax' +ATTR_ERROR = 'CACode-Attr' LOG_OPERA_NAME = 'CACode-Database-Operation' WARN = 'WARN' INFO = 'INFO' DB_TASK = 'DATABASE OPERATION' +PARSE_ERROR = 'CACode-Parse' diff --git a/CACodeFramework/field/__pycache__/__init__.cpython-39.pyc b/CACodeFramework/field/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 14fd6f3a47017501306157201c02fff0abd9bcb5..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/field/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/field/__pycache__/e_fields.cpython-39.pyc b/CACodeFramework/field/__pycache__/e_fields.cpython-39.pyc deleted file mode 100644 index bd1eed38e799d2b4a63fb364ff8ab1933683d347..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/field/__pycache__/e_fields.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/field/__pycache__/field_tag.cpython-39.pyc b/CACodeFramework/field/__pycache__/field_tag.cpython-39.pyc deleted file mode 100644 index 78277e87aa949ab9c562dd91b64809c3d6e6ff12..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/field/__pycache__/field_tag.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/field/__pycache__/sql_fields.cpython-39.pyc b/CACodeFramework/field/__pycache__/sql_fields.cpython-39.pyc deleted file mode 100644 index 94bb00ca2c20bfed816ff5a89acdc4119ba5e250..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/field/__pycache__/sql_fields.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/field/field_tag.py b/CACodeFramework/field/field_tag.py deleted file mode 100644 index 2b51075cddbf14c01655614946dc23ac0551a4a0..0000000000000000000000000000000000000000 --- a/CACodeFramework/field/field_tag.py +++ /dev/null @@ -1,42 +0,0 @@ -class baseTag(object): - def __init__(self, table_name=None, - name=None, - length=None, - d_point=None, - t_type='varchar', - is_null=False, - primary_key=False, - comment="", - auto_field=False, - auto_time=False, - update_auto_time=False): - """ - :param table_name:表名称 - :param name:字段名 - :param length:长度 - :param d_point:小数点 - :param t_type:类型 - :param is_null:允许为空 - :param primary_key:键 - :param comment:注释 - :param auto_field:自增长键 - :param auto_time:默认设置当前时间 - :param update_auto_time:默认设置当前时间并根据当前时间更新 - """ - self.update_auto_time = update_auto_time - self.auto_time = auto_time - self.autoField = auto_field - self.table_name = table_name - self.comment = comment - self.primary_key = primary_key - self.is_null = is_null - self.d_point = d_point - self.name = name - self.t_type = t_type - self.length = length - - def get_table(self): - """ - 获取表数据结构 - """ - return self.__dict__ diff --git a/CACodeFramework/opera/__init__.py b/CACodeFramework/opera/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/CACodeFramework/MainWork/opera/obj_dict.py b/CACodeFramework/opera/obj_dict.py similarity index 85% rename from CACodeFramework/MainWork/opera/obj_dict.py rename to CACodeFramework/opera/obj_dict.py index 5d00ca8882472e1153e85528a4753e5a079f138f..64fed0a7bdd0d26638644f85e18e3d7fc3377d0b 100644 --- a/CACodeFramework/MainWork/opera/obj_dict.py +++ b/CACodeFramework/opera/obj_dict.py @@ -1,8 +1,8 @@ import copy import sys -from CACodeFramework.MainWork.exception import e_except -from CACodeFramework.field import e_fields +from CACodeFramework.exception import e_fields +from CACodeFramework.util.Log import CACodeLog from CACodeFramework.util.ParseUtil import ParseUtil @@ -21,7 +21,7 @@ class parses(object): # 获得该函数被调用前的行号 _l = sys._getframe().f_back.f_lineno # 格式:时间 类型 日志名称 对象地址 被调用行号 执行类型 信息 - info = e_except.warn(obj=_obj, line=_l, task_name=name, f_warn=e_fields.INFO, msg=msg, LogObject=LogObject) + info = CACodeLog.log(obj=_obj, line=_l, task_name=name, msg=msg, LogObject=LogObject) def last_id(self, **kwargs): """作者:CACode 最后编辑于2021/4/12 @@ -82,18 +82,20 @@ class parses(object): :param __table_name__:表名 :return: """ - _dict = pojo.to_dict() + _dict = pojo.fields # 得到所有的键 keys = pojo.fields # 在得到值之后解析是否为空并删除为空的值和对应的字段 cp_value = [] + # 复制新的一张字段信息 + keys_copy = [] + values = [getattr(pojo, v) for v in keys] for i, j in enumerate(values): - if j is None or pojo.eq_default(j): - del keys[i] - else: + if j is not None and not pojo.is_default(j): + keys_copy.append(keys[i]) cp_value.append(j) - return ParseUtil().parse_insert(keys, cp_value, __table_name__) + return ParseUtil().parse_insert(keys_copy, cp_value, __table_name__) def parse_obj(self, data: dict, participants): """ diff --git a/CACodeFramework/MainWork/opera/op_db.py b/CACodeFramework/opera/op_db.py similarity index 98% rename from CACodeFramework/MainWork/opera/op_db.py rename to CACodeFramework/opera/op_db.py index f850c1af06cd748243550ef5d1d9c53b5d77f5f2..a7a4d4307c7b8baba69bd65174d4ec83da200a4c 100644 --- a/CACodeFramework/MainWork/opera/op_db.py +++ b/CACodeFramework/opera/op_db.py @@ -2,7 +2,7 @@ import threading from CACodeFramework.util.Log import CACodeLog -from CACodeFramework.MainWork.opera.obj_dict import parses +from CACodeFramework.opera.obj_dict import parses from CACodeFramework.field.sql_fields import * from CACodeFramework.util.ParseUtil import ParseUtil diff --git a/CACodeFramework/MainWork/CACodePojo.py b/CACodeFramework/pojoManager/Manage.py similarity index 47% rename from CACodeFramework/MainWork/CACodePojo.py rename to CACodeFramework/pojoManager/Manage.py index 032a1cac62c23ddc04527499240332a469047590..aa0ebff71818471f3dbd66188abf6f6c0453a201 100644 --- a/CACodeFramework/MainWork/CACodePojo.py +++ b/CACodeFramework/pojoManager/Manage.py @@ -1,20 +1,28 @@ from CACodeFramework.MainWork.CACodePureORM import CACodePureORM -from CACodeFramework.field import field_tag +from CACodeFramework.pojoManager import tag from CACodeFramework.util import JsonUtil from CACodeFramework.MainWork import CACodeRepository +from abc import ABCMeta, abstractmethod -class POJO(CACodeRepository.Repository): +class Pojo(CACodeRepository.Repository): def __init__(self, config_obj=None, log_conf=None, close_log=False, **kwargs): """ 初始化ORM框架 """ + + if '__table_name__' not in self.__dict__: + self.__table_name__ = self.__class__.__name__ + + if '__table_msg__' not in self.__dict__: + self.__table_msg__ = 'The current object has no description' + self.__table_name__ = self.__table_name__ self.__table_msg__ = self.__table_msg__ self.fields = self.init_fields() for key, value in kwargs.items(): self.__setattr__(key, value) - super(POJO, self).__init__(config_obj=config_obj, + super(Pojo, self).__init__(config_obj=config_obj, participants=self, log_conf=log_conf, close_log=close_log) @@ -29,35 +37,37 @@ class POJO(CACodeRepository.Repository): # 取出这个值引用对象的父类 try: t_v = value.__class__.__bases__ - t_bf = field_tag.baseTag + t_bf = tag.baseTag if t_v[0] == t_bf: fds[key] = value except SyntaxError: continue return fds - def to_json(self): + def to_json(self, bf=False): """ 将此对象转换为json + :param bf:是否需要格式化 + 无视时间报错 """ - return JsonUtil.parse(self) + return JsonUtil.parse(self, bf) def to_dict(self): """ 将此对象转换成字典格式 """ - return self.fields + return JsonUtil.load(JsonUtil.parse(self)) - def eq_default(self, val): + def is_default(self, val): """ 是否等于默认值 """ try: t_v = val.__class__.__bases__ - t_bf = field_tag.baseTag - return t_v[0] == t_bf + t_bf = tag.baseTag + return t_v[len(t_v) - 1] == t_bf except SyntaxError: return False @@ -69,56 +79,13 @@ class POJO(CACodeRepository.Repository): return CACodePureORM(self) -class tinyintField(field_tag.baseTag): - def __init__(self, **kwargs): - super(tinyintField, self).__init__(**kwargs) - - -class intField(field_tag.baseTag): - def __init__(self, **kwargs): - super(intField, self).__init__(**kwargs) - - -class bigintField(field_tag.baseTag): - def __init__(self, **kwargs): - super(bigintField, self).__init__(**kwargs) - - -class floatField(field_tag.baseTag): - def __init__(self, **kwargs): - super(floatField, self).__init__(**kwargs) - - -class doubleField(field_tag.baseTag): - def __init__(self, **kwargs): - super(doubleField, self).__init__(**kwargs) - - -class datetimeField(field_tag.baseTag): - def __init__(self, **kwargs): - super(datetimeField, self).__init__(**kwargs) - - -class charField(field_tag.baseTag): - def __init__(self, **kwargs): - super(charField, self).__init__(**kwargs) - - -class varcharField(field_tag.baseTag): - def __init__(self, **kwargs): - super(varcharField, self).__init__(**kwargs) - - -class textField(field_tag.baseTag): - def __init__(self, **kwargs): - super(textField, self).__init__(**kwargs) - - -class tinytextField(field_tag.baseTag): - def __init__(self, **kwargs): - super(tinytextField, self).__init__(**kwargs) +class Operation(metaclass=ABCMeta): + def __int__(self): + pass + @abstractmethod + def meta(self): + pass -class longtextField(field_tag.baseTag): - def __init__(self, **kwargs): - super(longtextField, self).__init__(**kwargs) + def run(self): + return self.result diff --git a/CACodeFramework/pojoManager/__init__.py b/CACodeFramework/pojoManager/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/CACodeFramework/pojoManager/tag.py b/CACodeFramework/pojoManager/tag.py new file mode 100644 index 0000000000000000000000000000000000000000..63120356b53049ef5f6f534dba01d8d026367670 --- /dev/null +++ b/CACodeFramework/pojoManager/tag.py @@ -0,0 +1,226 @@ +from CACodeFramework.util import JsonUtil + +""" +这个文件用来为pojo对象做标记,当对象为空或为以下任意类型时 +insert操做将会忽略该字段,find操作不会处理为空的字段 +""" + + +class baseTag(object): + def __init__(self, + table_name=None, + name=None, + length=None, + d_point=None, + t_type='varchar', + is_null=False, + primary_key=False, + comment="", + auto_field=False, + auto_time=False, + update_auto_time=False): + """ + :param table_name:表名称 + :param name:字段名 + :param length:长度 + :param d_point:小数点 + :param t_type:类型 + :param is_null:允许为空 + :param primary_key:键 + :param comment:注释 + :param auto_field:自增长键 + :param auto_time:默认设置当前时间 + :param update_auto_time:默认设置当前时间并根据当前时间更新 + """ + self.update_auto_time = update_auto_time + self.auto_time = auto_time + self.autoField = auto_field + self.table_name = table_name + self.comment = comment + self.primary_key = primary_key + self.is_null = is_null + self.d_point = d_point + self.name = name + self.t_type = t_type + self.length = length + # 如果使用的是被继承的子类,那么在这里就会有一个名为fields的字段 + # 将所有自定义字段 + if self.fields: + for key, value in self.fields.items(): + setattr(self, key, value) + + del self.fields + + def get_field(self, name): + """ + 获得字段 + """ + return getattr(self, name) + + def set_field(self, name, value): + """ + 设置值 + """ + setattr(self, name, value) + + def get_table(self, bf): + """ + 获取表数据结构 + """ + if bf: + return JsonUtil.parse(self, bf) + return JsonUtil.load(JsonUtil.parse(self)) + + +class tinyintField(baseTag): + + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(tinyintField, self).__init__(**kwargs) + + +class intField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(intField, self).__init__(**kwargs) + + +class bigintField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(bigintField, self).__init__(**kwargs) + + +class floatField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(floatField, self).__init__(**kwargs) + + +class doubleField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(doubleField, self).__init__(**kwargs) + + +class datetimeField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(datetimeField, self).__init__(**kwargs) + + +class charField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(charField, self).__init__(**kwargs) + + +class varcharField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(varcharField, self).__init__(**kwargs) + + +class textField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(textField, self).__init__(**kwargs) + + +class tinytextField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(tinytextField, self).__init__(**kwargs) + + +class longtextField(baseTag): + def __init__(self, cls=None, **kwargs): + self.fields = {} + if cls: + kwargs.update(cls.__dict__) + self.fields['cls'] = cls + kwargs.update(update_field(**kwargs)) + self.fields.update(kwargs) + super(longtextField, self).__init__(**kwargs) + + +def update_field(**kwargs): + """ + 更新字典配置 + """ + + def no_rep(key, value, **kwargs): + """ + 不存在则替换 + """ + if key not in kwargs.keys(): + kwargs[key] = value + return kwargs + + def has_attr(key, **kwargs): + if key in kwargs: + return kwargs[key] + return None + + kwargs.update(no_rep('table_name', has_attr('__table_name__', **kwargs), **kwargs)) + kwargs.update(no_rep('name', has_attr('name', **kwargs), **kwargs)) + kwargs.update(no_rep('length', has_attr('length', **kwargs), **kwargs)) + kwargs.update(no_rep('d_point', has_attr('d_point', **kwargs), **kwargs)) + kwargs.update(no_rep('t_type', has_attr('t_type', **kwargs), **kwargs)) + kwargs.update(no_rep('is_null', has_attr('is_null', **kwargs), **kwargs)) + kwargs.update(no_rep('primary_key', has_attr('primary_key', **kwargs), **kwargs)) + kwargs.update(no_rep('comment', has_attr('comment', **kwargs), **kwargs)) + kwargs.update(no_rep('auto_field', has_attr('auto_field', **kwargs), **kwargs)) + kwargs.update(no_rep('auto_time', has_attr('auto_time', **kwargs), **kwargs)) + kwargs.update(no_rep('update_auto_time', has_attr('update_auto_time', **kwargs), **kwargs)) + return kwargs diff --git a/CACodeFramework/util/DbUtil.py b/CACodeFramework/util/DbUtil.py index 43dfe4a3e4ad2ec3f977d30f363802b5073f6eea..000cd1450c8b24890217c2e32b143d4224c0f3a3 100644 --- a/CACodeFramework/util/DbUtil.py +++ b/CACodeFramework/util/DbUtil.py @@ -4,8 +4,7 @@ from CACodeFramework.util.Log import CACodeLog from dbutils.pooled_db import PooledDB import pymysql -from CACodeFramework.MainWork.exception import e_except -from CACodeFramework.field import e_fields +from CACodeFramework.exception import e_fields def parse_kwa(db, **kwargs): @@ -27,8 +26,8 @@ def parse_kwa(db, **kwargs): sql = kwargs['sql'] if 'print_sql' in kwargs.keys() and kwargs['print_sql'] is True: _l = sys._getframe().f_back.f_lineno - e_except.warn(obj=db, line=_l, task_name='Print Sql', f_warn=e_fields.INFO, msg=sql) - CACodeLog.log(_obj=db, msg='Being Initialize this object') + CACodeLog.log(obj=db, line=_l, task_name='Print Sql', msg=sql) + CACodeLog.log(obj=db, msg='Being Initialize this object') cursor.execute(sql) return cursor except Exception as e: diff --git a/CACodeFramework/util/Log.py b/CACodeFramework/util/Log.py index 3750a6fd2b1fc834677991e17066ca4e88fbccd2..e1ea6572e3f623d4efe8ea97c7fcc8c8d39b2a2a 100644 --- a/CACodeFramework/util/Log.py +++ b/CACodeFramework/util/Log.py @@ -1,9 +1,10 @@ import os import sys import time +import warnings +from datetime import datetime -from CACodeFramework.MainWork.exception import e_except -from CACodeFramework.field import e_fields +from CACodeFramework.exception import e_fields def date_format(time_obj=time, fmt='%Y-%m-%d %H:%M:%S'): @@ -70,7 +71,7 @@ class CACodeLog(object): self.save_flag = save_flag @staticmethod - def log(_obj, msg, name='\t\tTask', LogObject=None): + def log(obj, msg, line=sys._getframe().f_back.f_lineno, task_name='\t\tTask', LogObject=None): """ 输出任务执行日志 @@ -80,10 +81,18 @@ class CACodeLog(object): :param LogObject:写出文件的对象 """ - # 获得该函数被调用前的行号 - _l = sys._getframe().f_back.f_lineno # 格式:时间 类型 日志名称 对象地址 被调用行号 执行类型 信息 - info = e_except.warn(obj=_obj, line=_l, task_name=name, f_warn=e_fields.INFO, msg=msg, LogObject=LogObject) + t = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] + info = '{} {} {} [{}] [{}] [{}] \t\t\t:{}'.format(t, e_fields.INFO, + e_fields.LOG_OPERA_NAME, + id(obj), + obj.__str__(), + task_name, + msg) + # 输出日志信息 + warnings.warn_explicit(info, category=Warning, filename='line', lineno=line) + if LogObject is not None: + LogObject.warn(info) return info def success(self, content): diff --git a/CACodeFramework/util/__pycache__/Config.cpython-39.pyc b/CACodeFramework/util/__pycache__/Config.cpython-39.pyc deleted file mode 100644 index da9dad889cb14654501bdf255462d1fdadf3c9db..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/util/__pycache__/Config.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/util/__pycache__/DbUtil.cpython-39.pyc b/CACodeFramework/util/__pycache__/DbUtil.cpython-39.pyc deleted file mode 100644 index 2a028cee94f31dcf080cae384e3899f75f1cb63d..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/util/__pycache__/DbUtil.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/util/__pycache__/JsonUtil.cpython-39.pyc b/CACodeFramework/util/__pycache__/JsonUtil.cpython-39.pyc deleted file mode 100644 index 3154293557ac5e4f020718c599e7e80e1defc054..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/util/__pycache__/JsonUtil.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/util/__pycache__/Log.cpython-39.pyc b/CACodeFramework/util/__pycache__/Log.cpython-39.pyc deleted file mode 100644 index f4e01472bd6234d4d7507c23591dfaf637ff13be..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/util/__pycache__/Log.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/util/__pycache__/ParseUtil.cpython-39.pyc b/CACodeFramework/util/__pycache__/ParseUtil.cpython-39.pyc deleted file mode 100644 index a3b41126c44e2e642a710c8deace49d85b0b8906..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/util/__pycache__/ParseUtil.cpython-39.pyc and /dev/null differ diff --git a/CACodeFramework/util/__pycache__/__init__.cpython-39.pyc b/CACodeFramework/util/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 6c408e2a70d3779574a7d6dcef57b8eb468c8512..0000000000000000000000000000000000000000 Binary files a/CACodeFramework/util/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/README.md b/README.md index af5f22185c2d2eb8403602667c0ef8134c58c2ed..63c2555978ef6f48b239d813e8b66ca32bacad65 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,13 @@ 简历发送至邮箱cacode@163.com,标题 CACodeFramework-姓名-语言 -## 版本更新: +# 逻辑处理流程图 -# 1.1.2.1 +![流程图](./imgs/lct.png "流程图") + +# 版本更新: + +## 1.1.2.1 - 修复多线程下查询报错 - 查询速度显著提高 @@ -60,14 +64,14 @@ - 教程正在录制中。。。 -### 1.1.1.1 +## 1.1.1.1 -- 修复半自动Repository的insert相关解析失败 -- 修复全自动ORM执行失败 -- 新增group_by(*args) -- 新增一个2048小彩蛋 -### 1.1.0.03: +## 1.1.0.03: - 修复JsonUtil.parse(obj) - 部分字典dict解析失败 @@ -76,7 +80,7 @@ - 可以使用:orm.find('title', 'success', asses=['t', None]).end()将索引对应字段转成另一个别名 最后的结果就是:SELECT `title` FROM `demo_table` as t -### 1.1.0.2: +## 1.1.0.2: - 修复find - 无法返回POJO @@ -85,7 +89,7 @@ - 修复PureORM - 修复返回值为dict而非POJO问题 -### 1.0.2.1: +## 1.0.2.1: - 修复JsonUtil - 无法解析对象 diff --git a/imgs/lct.png b/imgs/lct.png new file mode 100644 index 0000000000000000000000000000000000000000..cbd6c8339351a6dced8eadc71b96c9d7ce962ef5 Binary files /dev/null and b/imgs/lct.png differ diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index b5a3c468d9e85e7fa7469c3a90d47b48ab93e54a..0000000000000000000000000000000000000000 --- a/pyproject.toml +++ /dev/null @@ -1,6 +0,0 @@ -[build-system] -requires = [ - "setuptools>=42", - "wheel" -] -build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/setup.py b/setup.py deleted file mode 100644 index e871020242256223cc7d1d2ea8ec6ffc950a92b9..0000000000000000000000000000000000000000 --- a/setup.py +++ /dev/null @@ -1,25 +0,0 @@ -import setuptools - -with open("README.md", "r", encoding="utf-8") as fh: - long_description = fh.read() - -setuptools.setup( - name="CACodeFramework", # Replace with your own username - version="1.1.2.1", - author="CACode", - author_email="cacode@163.com", - description="CACode Framework For Python Flask,This framework corresponds to the ORM problem,You can see:https://github.com/cctvadmin/CACodeFramework-python-ORM", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/cctvadmin/CACodeFramework-python-ORM", - project_urls={ - "Bug Tracker": "https://github.com/cctvadmin/CACodeFramework-python-ORM/issues", - }, - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ], - packages=setuptools.find_packages(), - python_requires=">=3.6", -) diff --git a/test/test.py b/test/test.py index a32a4c6bd158da52e6d7a57af925e44afd353e15..10583bb76bfd487fdeeb47a4f95378ceed72b301 100644 --- a/test/test.py +++ b/test/test.py @@ -1,11 +1,10 @@ import threading -import time +import uuid -from CACodeFramework.util.Log import CACodeLog +from CACodeFramework.anno.annos import Table, Select +from CACodeFramework.anno.aop import AopModel +from CACodeFramework.pojoManager import Manage -from CACodeFramework.MainWork import CACodePojo - -from CACodeFramework.MainWork.Annotations import Table from CACodeFramework.util import Config, JsonUtil @@ -25,24 +24,53 @@ class ConF(Config.config): super(ConF, self).__init__(host, port, database, user, password, charset, conf=conf) +def Before(**kwargs): + print('Before:', kwargs) + + +def After(*args, **kwargs): + print('After', args) + print('Result:', kwargs) + + @Table(name="demo_table", msg="demo message") -class Demo(CACodePojo.POJO): +class demo_table(Manage.Pojo): def __init__(self, **kwargs): - self.index = CACodePojo.intField(name='index', primary_key=True) - self.title = CACodePojo.varcharField(length=255) - self.selects = CACodePojo.varcharField(length=255) - self.success = CACodePojo.varcharField(length=255) - super(Demo, self).__init__(config_obj=ConF(), close_log=True, **kwargs) + self.t_id = Manage.tag.intField(primary_key=True) + self.t_name = Manage.tag.varcharField(length=255) + self.t_pwd = Manage.tag.varcharField(length=255) + self.t_msg = Manage.tag.varcharField(length=255) + self.create_time = Manage.tag.datetimeField(auto_time=True) + self.update_time = Manage.tag.datetimeField(update_auto_time=True) + + super(demo_table, self).__init__(config_obj=ConF(), close_log=True, **kwargs) + + @AopModel(before=Before, before_kwargs={'1': '1'}, after=After) + def find_title_and_selects(self, **kwargs): + print('function task', kwargs['uid']) + _r = self.orm.find().end() + print(_r) + return _r + + @Select(sql='SELECT * FROM demo_table WHERE t_id=%s', params=[1]) + class find_all_where_tid(Manage.Operation): + def __init__(self, t_id): + self.t_id = t_id + + def meta(self): + return demo_table() def setData(): a = [] - h = Demo() - for i in range(2): - h = Demo(title="test title", selects="test selects", success='false') - a.append(h) + h = demo_table() + for i in range(1000): + h = demo_table(t_name='{}{}'.format('测试name', i), t_pwd='{}{}'.format('测试pwd', i), + t_msg='{}{}'.format('测试msg', i)) + # a.append(h) + h.save() # _result = testClass.insert_one(pojo=h) - _r = Demo().orm.insert(h).end() + # _r = demo_table().orm.insert(h).end() # h.insert_many(pojo_list=a) # _result = testClass.insert_many(pojo_list=pojos) # print('受影响行数:{}\t,\t已插入:{}'.format(_result, i)) @@ -54,26 +82,26 @@ data_count = 0 def th(): def A(): for i in range(100): - d = Demo() + d = demo_table() a = d.find_sql(sql='SELECT * FROM demo_table') global data_count data_count += len(a) def B(): for i in range(100): - b = Demo().find_many(sql='SELECT * FROM demo_table') + b = demo_table().find_many(sql='SELECT * FROM demo_table') global data_count data_count += len(b) def C(): for i in range(100): - c = Demo().find_all() + c = demo_table().find_all() global data_count data_count += len(c) def D(): for i in range(100): - d = Demo().find_by_field('title', 'selects') + d = demo_table().find_by_field('title', 'selects') global data_count data_count += len(d) @@ -86,7 +114,7 @@ def th(): if __name__ == '__main__': # setData() - # c = Demo().orm.find('count(*)', asses=['c'], h_func=True).end()[0] + # c = demo_table().orm.find('count(*)', asses=['c'], h_func=True).end()[0] # print('count:', c.c) # t1 = time.time() # t = th() @@ -97,6 +125,15 @@ if __name__ == '__main__': # print('time:', t2 - t1) # print('data count:', data_count) # print('average:', data_count / (t2 - t1)) - - _r = Demo().orm.update().set(success='true').where(index=17036).end() - print(_r) + d = demo_table() + # u = uuid.uuid1() + # result = d.find_title_and_selects(uid=u) + # print(JsonUtil.parse(result, True)) + # a = d.find_all_where_tid(1).run() + # print(a) + re = d.orm.find('t_id', 't_name', 't_pwd').where(t_id="<<10").first().end() + print(re.to_json(True)) + # d.before_find_title_and_selects(*d.before_args_find_title_and_selects, + # **d.before_kwargs_find_title_and_selects) + # _r = d.orm.update().set(success='true').where(index=17034).end() + # print(_r) diff --git a/upload.bat b/upload.bat deleted file mode 100644 index d2d5706428f674adfa0e5c72f6676939c036314a..0000000000000000000000000000000000000000 --- a/upload.bat +++ /dev/null @@ -1,4 +0,0 @@ -python setup.py sdist bdist_wheel -twine upload dist/* -git push origin main -git push gitee main \ No newline at end of file diff --git a/util/Generate POJOs.groovy b/util/Generate POJOs.groovy deleted file mode 100644 index e13535a578fe0e765895a1f84018cd5fb393217d..0000000000000000000000000000000000000000 --- a/util/Generate POJOs.groovy +++ /dev/null @@ -1,56 +0,0 @@ -import com.intellij.database.model.DasTable -import com.intellij.database.util.Case -import com.intellij.database.util.DasUtil - -/* - 你可以使用此脚本快捷生成POJO对象 - 最终效果为: - from CACodeFramework.MainWork.CACodePojo import POJO - - - class table(POJO): - def __init__(self): - self.shopId = None - self.title = None - self.icon = None - self.createTime = None - self.updateTime = None - - */ - -FILES.chooseDirectoryAndSave("Choose directory", "Choose where to store generated files") { dir -> - SELECTION.filter { it instanceof DasTable }.each { generate(it, dir) } -} - -def generate(table, dir) { - def className = javaName(table.getName(), false) - def fields = calcFields(table) - new File(dir, className + ".py").withPrintWriter { out -> generate(out, className, fields) } -} - -def generate(out, className, fields) { - out.println "from CACodeFramework.MainWork.CACodePojo import POJO" - out.println "" - out.println "" - out.println "class table(POJO):" - out.println " def __init__(self):" - fields.each() { - out.println " self.${it.name} = None" - } -} - -def calcFields(table) { - DasUtil.getColumns(table).reduce([]) { fields, col -> - def spec = Case.LOWER.apply(col.getDataType().getSpecification()) - fields += [[ - name : javaName(col.getName(), false)]] - } -} - -def javaName(str, capitalize) { - def s = com.intellij.psi.codeStyle.NameUtil.splitNameIntoWords(str) - .collect { Case.LOWER.apply(it).capitalize() } - .join("") - .replaceAll(/[^\p{javaJavaIdentifierPart}[_]]/, "_") - capitalize || s.length() == 1? s : Case.LOWER.apply(s[0]) + s[1..-1] -}