温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

基于FLASK-SQLAlchemy的持久层SQL语法

发布时间:2020-07-27 06:05:57 来源:网络 阅读:437 作者:TaoismLi 栏目:开发技术
  1. insert into table

    a. create an object based on the Module

    b. db.session.add(object)


  2. select * from table

    a. Classname(based on the Module).query.all()

  3. select * from table where 

    a. Classname.query.filter_by(condition=value).all()

  4. select * from table where  xxx limit 1

    a. Classname.query.filter_by(condition=value).first()

  5. select count(*) from table where  xxx

    a. Classname.query.filter_by(condition=value).count()

  6. select * from table where  primarykey=xx

    a. Classname.query.get(xx/id)



    7. update column

        a. fetch object, eg. flight = Flight.query.get(x)

        b. flight.column = newValue


    8. delete from table

        a. fetch object, eg. flight = Flight.query.get(x)

        b. db.session.delete(object) 


Advanced sql:

a. Classname.query.order_by(Classname.column).all()

b. Classname.query.order_by(Classname.column.desc()).all()

c. Classname.query.filter(Classname.column != value).all()

d. Classname.query.filter(Classname.column.like(%abc%)).all()

e. Classname.query.filter(Classname.column.in_(aPythonValueList)).all()

f. Classname.query.filter(and_(condition1, condition2, ...)).all()

g. Classname.query.filter(or_(condition1, condition2, ...)).all()

h. db.session.query(Classname1, Classname2).filter(Classname1.column == Classname2.column).all()


Notice:

insert, update, delete: 

should add a statement: db.session.commit()


一对多,多对多对象关系SQL语法:

https://www.jianshu.com/p/8c038f0134f8

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI