周志洋

个人站

持续学习 才能不被淘汰


Python_tips_orm_sqlalchemy


layout: post +title: “Python实用技巧-ORM 与 SQLAlchemy” +date: 2018-12-23 +description: “SQLAlchemy 基础、模型定义、查询操作” +tag: Python + +— + +### 模型定义 + +>python +>from sqlalchemy import Column, Integer, String, create_engine +>from sqlalchemy.ext.declarative import declarative_base +> +>Base = declarative_base() +> +>class User(Base): +> __tablename__ = 'users' +> id = Column(Integer, primary_key=True) +> name = Column(String(50)) +> + +### 查询操作 + +>python +>from sqlalchemy.orm import sessionmaker +> +>Session = sessionmaker(bind=engine) +>session = Session() +>users = session.query(User).filter(User.name.like('%A%')).all() +> + +
+转载请注明:周志洋的博客 » Python实用技巧-ORM 与 SQLAlchemy +

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦