数据库帮助程序和实用程序。
dbhelpers的Python项目详细描述
dbhelpers
==
[![构建状态](https://travis-ci.org/albertoalcolea/dbhelpers.svg?branch=master)(https://travis ci.org/albertoalcolea/dbhelpers)
y要安装dbhelpers,需要使用pip:
$pip install dbhelpers
usage
---
=psycopg2连接(db='mydb',user='myuser',passwd='mypass').connect()
(…)
conn.close()
具有默认参数的连接类:
`` python
从dbhelpers导入mysqldbconnection
类customconn(mysqldbconnection):
默认用户='myuser'
默认密码='mypass'
默认主机='localhost'
默认端口=13306
defaul特别是{'charset':'utf8mb4'}
>
光标在"with"块中执行。当块结束时,光标关闭。如果'commit=true'(默认情况下为true),则块结束时还会执行'connection.commit()'。
``python
从dbhelpers导入cm cursor
d,status)值(23,'info')"
lback()`方法而不是python 2.7和3.x中的'conn.commit()`
```
fetchiter
`fetchiter`可以用作大型记录集的生成器:
``python
from dbhelpers import fetchiter
fetchiter(游标)中的行:
执行
```
默认的块大小是1000。
` fetchiter`重复调用'cursor.fetchmany()',直到没有更多的数据返回。fetchiter函数的行为类似于迭代器。
chiter(cursor,size=50,batch=true):
做点什么,block是一个有50行的元组,postgresql server cursor
o向服务器查询时,服务器计算整个记录集,然后"fetchiter"检索为了避免进程内存被填满,服务器游标在postgres服务器上运行伪迭代器,并迭代计算块中的部分记录集。
`` python
从dbhelpers导入fetchiter
hing
cursor.execute("close c")
````
`fetchiter`可以返回服务器游标结果,如上例所示(作为interator或块),您可以更改块大小。默认块大小为1000。
`fetchone'fetchmany'fetchmany'nt,`fetchall'fetchalt'fetchiter'nt` fetchall'fetchall'fetchall'fetchiter'nt`将行返回namet元组:
`python
>使用cm_cursor(conn)作为游标:
cursor.execute("select id,status from mytable where id=23")
row=fetchone_nt(cursor)
t;gt;行状态
"警告"
```
==
[![构建状态](https://travis-ci.org/albertoalcolea/dbhelpers.svg?branch=master)(https://travis ci.org/albertoalcolea/dbhelpers)
y要安装dbhelpers,需要使用pip:
$pip install dbhelpers
usage
---
=psycopg2连接(db='mydb',user='myuser',passwd='mypass').connect()
(…)
conn.close()
具有默认参数的连接类:
`` python
从dbhelpers导入mysqldbconnection
类customconn(mysqldbconnection):
默认用户='myuser'
默认密码='mypass'
默认主机='localhost'
默认端口=13306
defaul特别是{'charset':'utf8mb4'}
>
光标在"with"块中执行。当块结束时,光标关闭。如果'commit=true'(默认情况下为true),则块结束时还会执行'connection.commit()'。
``python
从dbhelpers导入cm cursor
d,status)值(23,'info')"
lback()`方法而不是python 2.7和3.x中的'conn.commit()`
```
fetchiter
`fetchiter`可以用作大型记录集的生成器:
``python
from dbhelpers import fetchiter
fetchiter(游标)中的行:
执行
```
默认的块大小是1000。
` fetchiter`重复调用'cursor.fetchmany()',直到没有更多的数据返回。fetchiter函数的行为类似于迭代器。
chiter(cursor,size=50,batch=true):
做点什么,block是一个有50行的元组,postgresql server cursor
o向服务器查询时,服务器计算整个记录集,然后"fetchiter"检索为了避免进程内存被填满,服务器游标在postgres服务器上运行伪迭代器,并迭代计算块中的部分记录集。
`` python
从dbhelpers导入fetchiter
hing
cursor.execute("close c")
````
`fetchiter`可以返回服务器游标结果,如上例所示(作为interator或块),您可以更改块大小。默认块大小为1000。
`fetchone'fetchmany'fetchmany'nt,`fetchall'fetchalt'fetchiter'nt` fetchall'fetchall'fetchall'fetchiter'nt`将行返回namet元组:
`python
>使用cm_cursor(conn)作为游标:
cursor.execute("select id,status from mytable where id=23")
row=fetchone_nt(cursor)
t;gt;行状态
"警告"
```