sqlalchemy学习笔记
发布时间:2020-12-12 20:37:36 所属栏目:百科 来源:网络整理
导读:engine = create_engine('sqlite://')# create MetaDatameta = MetaData()# bind to an enginemeta.bind = engine create_all()creates foreign key constraints between tables usually inline with the table definition itself,and for this reason it al
engine = create_engine('sqlite://') # create MetaData meta = MetaData() # bind to an engine meta.bind = engine create_all()creates foreign key constraints between tables usually inline with the table definition itself,and for this reason it also generates the tables in order of their dependency. There are options to change this behavior such that ALTERTABLEis used instead.
用create_all的时候会根据外键的依赖性,顺序创建表。删除的时候亦然。 绑定一个数据库:
engine = create_engine('sqlite:///:memory:') meta = MetaData() employees = Table('employees',meta,Column('employee_id',Integer,primary_key=True),Column('employee_name',String(60),nullable=False,key='name'),Column('employee_dept',ForeignKey("departments.department_id")) ) SQLemployees.create(engine) 连接池设置: create_engine()大多时候会集成一个QueuePool。 在用sqlite的时候,会用SingletonThreadPoolorNullPool 因为sqlite的锁机制。 链接只会在用到的时候建立. 可以用poolclass参数指定pool的类型: from sqlalchemy.pool import QueuePool engine = create_engine('sqlite:///file.db',poolclass=QueuePool) 参数为 Nullpoll的时候禁用连接池。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Oracle事务和对象上集(视图、索引)
- c# – 分配大型数组; OutOfMemoryException VS OverflowExc
- SQLite入门与分析(三)---内核概述(1)
- ruby-on-rails-3.2 – 为什么我需要在rails / ajax的远程链
- 浅析jQuery Ajax通用js封装
- Convert to Current Swift Syntax Failed: Could not find
- 使用ajax和webapi进行长时间轮询时的瘦身是什么……它会杀死
- oracle用户和角色的管理授权以及表空间操作
- 基于Flex的实时H.264流转发平台之客户端(Web+Android)
- 加密 – 如何在C#3.0中以简单的方式加密cookie内容?