mysqldb的小包装
lurker的Python项目详细描述
潜伏者是建立在python mysqldb之上的一个微型mysql包装器。
(对于单独的环境,比如devconfig、prodconfig和testconfig)
`` python
类数据库配置(baselovergerconfig):
主机='本地主机'
用户='根'
密码='
数据库='
连接=连接(dbconfig)
`````
*没有配置对象
`` python
连接=连接()。快速连接(“mysql用户”,“mysql密码”,“数据库名”,“主机”)
```
发送查询
——
``python
])
返回一个结果集
all-people=connection.get-people=connection.get-results(“select*from people”)
返回一行
one-people=connection.get-row(“select*from people where id=1”)
使用redis
——
*以激活缓存支持,需要在配置类中设置缓存和缓存信息变量。
``python
from lurker.configuration import baselurkerconfig
from lurker.connection import connection
from lurker.cache.backends.redis_backend import redisbackend
class dbconfig(baselurkerconfig):
host='localhost'
user='根'
passwd='passwd'
db='数据库名称'
cache=true
cache信息={
'后端':redisbackend,
'参数':(),
'kwargs':{'host':'localhost','port':6379,'db':0},
}
````
*在获取结果和获取行中的用法
``python
>打印连接。获取行(“从id=%s的人中选择”,参数=(1,),缓存=30)
打印连接。获取行(“从id=%s的人中选择”,参数=(1,),缓存=30)
输出
调试:根:缓存未命中:从id=%s的人中选择*。id=%s
{id':1l,'name':u'emre yilmaz'}
{debug:root:cache hit:select*from people where id=%s
{u'id':1,“姓”:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓;姓:姓:姓:姓;姓:姓:姓:姓:姓;姓;姓:姓:姓;姓:姓;姓:姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓:姓;姓:姓:姓:姓:姓;姓:姓;姓:姓:姓;姓:姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓;姓;姓;姓;姓:姓;姓;姓;姓;姓;姓;姓;姓;姓;姓;姓;姓;姓;/>数据库副本:https://gist.github.com/4686232 file-db懔copy-py
(对于单独的环境,比如devconfig、prodconfig和testconfig)
`` python
类数据库配置(baselovergerconfig):
主机='本地主机'
用户='根'
密码='
数据库='
连接=连接(dbconfig)
`````
*没有配置对象
`` python
连接=连接()。快速连接(“mysql用户”,“mysql密码”,“数据库名”,“主机”)
```
发送查询
——
``python
])
返回一个结果集
all-people=connection.get-people=connection.get-results(“select*from people”)
返回一行
one-people=connection.get-row(“select*from people where id=1”)
使用redis
——
*以激活缓存支持,需要在配置类中设置缓存和缓存信息变量。
``python
from lurker.configuration import baselurkerconfig
from lurker.connection import connection
from lurker.cache.backends.redis_backend import redisbackend
class dbconfig(baselurkerconfig):
host='localhost'
user='根'
passwd='passwd'
db='数据库名称'
cache=true
cache信息={
'后端':redisbackend,
'参数':(),
'kwargs':{'host':'localhost','port':6379,'db':0},
}
````
*在获取结果和获取行中的用法
``python
>打印连接。获取行(“从id=%s的人中选择”,参数=(1,),缓存=30)
打印连接。获取行(“从id=%s的人中选择”,参数=(1,),缓存=30)
输出
调试:根:缓存未命中:从id=%s的人中选择*。id=%s
{id':1l,'name':u'emre yilmaz'}
{debug:root:cache hit:select*from people where id=%s
{u'id':1,“姓”:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓:姓;姓:姓:姓:姓;姓:姓:姓:姓:姓;姓;姓:姓:姓;姓:姓;姓:姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓:姓;姓:姓:姓:姓:姓;姓:姓;姓:姓:姓;姓:姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓:姓;姓;姓;姓;姓;姓:姓;姓;姓;姓;姓;姓;姓;姓;姓;姓;姓;姓;姓;/>数据库副本:https://gist.github.com/4686232 file-db懔copy-py