peewee 动态定义数据库
来源:互联网 发布:java调用wsdl接口 cxf 编辑:程序博客网 时间:2024/06/14 12:40
Dynamically defining a database
For even more control over how your database is defined/initialized, you can use the
Proxy
helper. Proxy
objects act as a placeholder, and then at run-time you can swap it out for a different object. In the example below, we will swap out the database depending on how the app is configured:database_proxy = Proxy() # Create a proxy for our db.class BaseModel(Model): class Meta: database = database_proxy # Use proxy for our DB.class User(BaseModel): username = CharField()# Based on configuration, use a different database.if app.config['DEBUG']: database = SqliteDatabase('local.db')elif app.config['TESTING']: database = SqliteDatabase(':memory:')else: database = PostgresqlDatabase('mega_production_db')# Configure our proxy to use the db we specified in config.database_proxy.initialize(database)
Warning
Only use this method if your actual database driver varies at run-time. For instance, if your tests and local dev environment run on SQLite, but your deployed app uses PostgreSQL, you can use the Proxy
to swap out engines at run-time.
However, if it is only connection values that vary at run-time, such as the path to the database file, or the database host, you should instead use Database.init()
. See Run-time database configuration for more details.
0 0
- peewee 动态定义数据库
- peewee模块操作mysql数据库
- peewee
- peewee
- Peewee中文文档【六】:数据库管理
- 轻量级的ORM框架Peewee访问sqlite数据库
- python ORM 模块peewee(一): 建立数据库对象
- python ORM 模块peewee(二): 数据库使用的基本流程
- 使用peewee将数据库从mysql导入mongodb
- peewee入门
- python轻量级ORM---peewee
- peewee 对象clone函数
- peewee 中文翻译文档
- peewee快速使用
- 在Delphi动态生成定义数据库 中国教程在线,http://www.5istudy.cn
- 动态定义数组
- C#动态定义变量
- 动态定义数组
- caffe各层参数详解(读文档记录)
- Java NIO(五)--Selector
- 多线程等待唤醒机制之生产消费者模式
- GBK UTF8 GB2132
- c++中acos,asin,atan的范围
- peewee 动态定义数据库
- MySQL创建用户的三种方法
- TCP/IP笔记
- g++基本用法
- Class 的反射
- 《时间戳、日期字符串》
- Foundation of Machine Learning 笔记第五部分 (1) —— Rademacher Complexity 和 VC 维
- 教你一步一步搭建ssm框架
- 设置mysql允许外网访问