全运会网站建设方案,上海网站怎么备案号,招投标网站,网页托管SQLAlchemy 一些基本操作
建表#xff1a;db.create_all() 一次性创建全部的表
插入数据#xff1a;
1、创建变量user User(username “hjj2”,password “1234”)
2、使用db.session.add(user)#xff0c;添加到会话对象中
3、使用db.session.commit()db.create_all() 一次性创建全部的表
插入数据
1、创建变量user User(username “hjj2”,password “1234”)
2、使用db.session.add(user)添加到会话对象中
3、使用db.session.commit()提交到数据库。
查询数据
1、查询同类全部数据users User.query.all()
2、通过主键获取如user User.query.get(1)
3、有过滤的查询采用filter_by来过滤如peter User.query.filter_by(username’peter’).first()
4、复杂表达式查询如 User.query.filter(User.email.endswith(‘example.com’)).all()
删除数据
1、db.session.delete(user)
2、db.session.commit()
更新数据
1、在使用first()或者all()等方法返回数据之前调用update方法可以修改已存在的数据的值。如User.query.filter_by(username’fake_name’).update({‘password’:’test’})
查询数据
问题循环引用的解决方案http://blog.csdn.net/handsomekang/article/details/19010407