MySQL数据库包装器

mydb的Python项目详细描述


Install

pip install mydb

Usage

Single Connection

from mydb.connection import Connection

db = Connection("mysql://youngking@localhost:13306/mydatabase")
for article in db.query("SELECT * FROM articles"):
    print article.title

Multiple Connection Like Master/Slave

from mydb.router import ConnectionRouter
from mydb.proxy import DBProxy
router = ConnectionRouter(["myapp.somewhere.MasterSlaveRouter"])
db = DBProxy(router)

for article in db.query("SELECT * FROM articles"):
    print article.title

Database routers

数据库路由器是一个类,它最多提供两种方法:

读取数据库(语句,**提示)

Suggest the database that should be used for read operations for ``SELECT`` statement.

If a database operation is able to provide any additional information that might assist in selecting a database, it will be provided in the hints dictionary. Details on valid hints are provided below.

Returns None if there is no suggestion.

db_for_write(型号,**提示)

Suggest the database that should be used for writes of statements except ``SELECT``.

If a database operation is able to provide any additional information that might assist in selecting a database, it will be provided in the hints dictionary. Details on valid hints are provided below.

tests/test_router.py中有一个示例。

路由器不必提供所有这些方法——它可能会忽略其中的一个或多个方法。如果省略其中一种方法, mydb在执行相关检查时将跳过该路由器。

mydb.router中有一些默认路由器,您可以从中继承并覆盖它们。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用Eclipse Helios for Web项目   java指定行。作为编译器设置的分隔符?   osm映射中带有osmdroid的java标记   java Android ClassNotFoundException在路径:DexPathList上未找到类   java从j2me调用GWT方法   更新到java 8后的aspectj问题   如何仅从根元素java,com提取文本内容。滴虫软件。是的。html   安卓公司。谷歌。火基。数据库DatabaseException:未能转换java类型的值。将字符串改为长字符串   从java中的方法返回arraylist变量   java如果将引用重新分配给同步块内的锁对象,会是什么?   java下载。使用spring mvc的资源文件中的xlsx文件   java Eclipse提供了什么工具来运行Eclipse中未包含的程序?   spring boot Java泛型如何读取传递给泛型方法的类型上的字段或调用方法   Javacard中的javaecdsa签名