创建一个表对象
5/10/2023 配置
# 为我们的 demo 表创建一个 Pojo
在根目录下新建一个包,名为:tables
,并在tables
包下创建一个名为demoModels.py
文件,在文件内编写以下代码:
# 位置在:example.tables.demoModels.py
from aestate.dbs import _mysql
from example.db_base import table_template
from aestate.work.Annotation import Table, Select, SelectAbst, ReadXml, Item, AopModel
def Before():
print("before")
def After(result):
print('result', result)
# 使用装示器设置表的名称,name和msg是必填字段,name为表的名称,msg为表的注释
# 如果你不喜欢使用装示器,你也可以在__init__()中使用self.__table_name__来设置表的名称
# 如果你还是不喜欢,那就将这个类的名称写成表的名称,严格区分大小写
# 为了规范起见,请务必填写描述文本
@Table(name='demo', msg='示例表')
# 使用表的全名为类名设置表的名称
# class demo(table_template):
class Demo(table_template):
def __init__(self, **kwargs):
# 新建一个名为name的字段,长度为20,不允许为空
self.name = _mysql.tag.varcharField(length=20, is_null=False, comment='名称')
# 创建一个password字段
self.password = _mysql.tag.varcharField(length=20, is_null=False, comment='密码')
# 使用内部变量设置表的名称
# self.__table_name__ = 'demo'
# 这里不设置`is_delete`字段
super(Demo, self).__init__(**kwargs)
@Select("SELECT * FROM demo WHERE id=${id} AND name=#{name}")
def find_all_where_id(self, id, name): ...
@SelectAbst()
def find_all_F_where_id_eq_and_name_eq(self, **kwargs): ...
@SelectAbst()
def find_all_F_where_id_in_and_name_like_order_by_id(self, **kwargs) -> list: ...
@AopModel(before=Before, after=After)
@SelectAbst()
def find_all_F(self, **kwargs): ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44