• SQLAlchemy Python 数据持久层框架


    授权协议:MIT
    开发语言:Python
    操作系统:跨平台
    收录时间:2008-11-28
     

    SQLAlchemy 是一个Python 的SQL 工具包以及数据库对象映射框架。它包含整套企业级持久化模式,专门为高效和高性能的数据库访问。

    示例代码:

    from sqlalchemy import Column, DateTime, String, Integer, ForeignKey, func
    from sqlalchemy.orm import relationship, backref
    from sqlalchemy.ext.declarative import declarative_base
     
    Base = declarative_base()
     
    class Department(Base):
        __tablename__ = 'department'
        id = Column(Integer, primary_key=True)
        name = Column(String)
     
    class Employee(Base):
        __tablename__ = 'employee'
        id = Column(Integer, primary_key=True)
        name = Column(String)
        # Use default=func.now() to set the default hiring time
        # of an Employee to be the current time when an
        # Employee record was created
        hired_on = Column(DateTime, default=func.now())
        department_id = Column(Integer, ForeignKey('department.id'))
        # Use cascade='delete,all' to propagate the deletion of a Department onto its Employees
        department = relationship(
            Department,
            backref=backref('employees',
                             uselist=True,
                             cascade='delete,all'))
     
    from sqlalchemy import create_engine
    engine = create_engine('sqlite:///orm_in_detail.sqlite')
     
    from sqlalchemy.orm import sessionmaker
    session = sessionmaker()
    session.configure(bind=engine)
    Base.metadata.create_all(engine)
    漫思
  • 相关阅读:
    [Oracle]Oracle的闪回归档
    【zabbix】snmp监控linux主机
    XFS文件系统
    PostgreSQL的使用向导
    PostgreSQL 12 YUM安装
    011.MySQL双主多从+Keepalived配置
    010.MySQL-Keepalived搭配脚本04
    009.MySQL-Keepalived搭配脚本03
    008.MySQL-Keepalived搭配脚本02
    007.MySQL-Keepalived搭配脚本01
  • 原文地址:https://www.cnblogs.com/sexintercourse/p/13803247.html
Copyright © 2020-2023  润新知