在项目中使用到了flask-sqlalchemy,在这总结一下用法,防止以后忘记了,又得去查英文资料。
1、sqlalchemy 使用第一阶段:
首先把表结构通过类的方式告诉sqlalchemy,如下:
class AlarmStatistical(db.Model):
__bind_key__ = 'xnet_master'
__tablename__ = 'dashboard_alarm_statistical'
id = db.Column(db.Integer, primary_key=True)
source = db.Column(db.String(255), index=True)
pod = db.Column(db.String(255), index=True)
start_time = db.Column(db.DateTime, index=True)
count = db.Column(db.Integer)
def __init__(self, source, pod, start_time, count):
self.source = source
self.pod = pod
self.start_time = start_time
self.count = count
def alter(self):
self.count +=