u= User(username = "peter", email = "test@example.com", password = "123") db.session.add(u) #:插入数据 db.session.commit() #:提交
u = User.query.get(1) || u=User.query.first() || u = User.query.filter_by(username = "peter") db.session.delete(u) #:与插入一样,必须是查询返回的对象 db.session.commit()
u = User.query.first() u.username = 'guest' db.session.commit()
User.query.get(1) #:id = 1
User.query.filter_by(username = 'peter').first() User.query.filter(User.username == 'peter').first()
User.query.filter(User.username.startswith("pet")).all() User.query.filter(User.email.endswith("@example.com")).all()
User.query.filter(User.username != 'perter').all() from sqlalchemy import not_ User.query.filter(not_(User.username == 'peter')).all()
form sqlalchemy import and_ User.query.filter(and_(User.username == 'peter', User.email.endswith('@example.com'))).first()
form sqlalchemy import or_ User.query.filter(or_(User.username != 'peter', User.email.endswith('@example.com'))).first()
User.query.first() #:返回查询到的第一个数据 User.query.all() #:返回查询到的所有数据
users = User.query.paginate(int(page),int(limit),False) for user in users.items: .....
User.query.limit(1).all()
User.query.order_by(User.username)
from sqlalchemy import desc User.query.order_by(desc(AclLogTable.date))