-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdao.py
More file actions
64 lines (53 loc) · 1.48 KB
/
Copy pathdao.py
File metadata and controls
64 lines (53 loc) · 1.48 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import logging
from sqlalchemy.exc import OperationalError
from wxcloudrun import db
from wxcloudrun.model import Counters
# 初始化日志
logger = logging.getLogger('log')
def query_counterbyid(id):
"""
根据ID查询Counter实体
:param id: Counter的ID
:return: Counter实体
"""
try:
return Counters.query.filter(Counters.id == id).first()
except OperationalError as e:
logger.info("query_counterbyid errorMsg= {} ".format(e))
return None
def delete_counterbyid(id):
"""
根据ID删除Counter实体
:param id: Counter的ID
"""
try:
counter = Counters.query.get(id)
if counter is None:
return
db.session.delete(counter)
db.session.commit()
except OperationalError as e:
logger.info("delete_counterbyid errorMsg= {} ".format(e))
def insert_counter(counter):
"""
插入一个Counter实体
:param counter: Counters实体
"""
try:
db.session.add(counter)
db.session.commit()
except OperationalError as e:
logger.info("insert_counter errorMsg= {} ".format(e))
def update_counterbyid(counter):
"""
根据ID更新counter的值
:param counter实体
"""
try:
counter = query_counterbyid(counter.id)
if counter is None:
return
db.session.flush()
db.session.commit()
except OperationalError as e:
logger.info("update_counterbyid errorMsg= {} ".format(e))