-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexample_decorator.py
46 lines (32 loc) · 959 Bytes
/
example_decorator.py
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
45
46
import mysql.connector
from mybatis import Mybatis
conn = mysql.connector.connect(
host="localhost", # MySQL 主机地址
user="mybatis", # MySQL 用户名
password="mybatis", # MySQL 密码
database="mybatis", # 需要连接的数据库,
autocommit=False
)
mb = Mybatis(conn, "mapper", cache_memory_limit=50*1024*1024)
@mb.SelectOne("SELECT * FROM fruits WHERE id=#{id}")
def get_one(id:int):
pass
@mb.SelectMany("SELECT * FROM fruits")
def get_many():
pass
@mb.Insert("INSERT INTO fruits (name, category, price) VALUES (#{name}, #{category}, #{price})")
def insert():
pass
@mb.Delete("DELETE FROM fruits WHERE id=#{id}")
def delete(id:int):
pass
@mb.Update("UPDATE fruits SET name='Amazon' WHERE id=#{id}")
def update(id:int):
pass
print(get_one(id=1))
print(delete(id=4))
print(get_many())
print(insert(name="Dating", category="D", price=20))
print(get_many())
print(update(id=1))
print(get_many())