数据库帮助程序和实用程序。

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;行状态
"警告"
```

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

推荐PyPI第三方库


热门话题
javajaxb在嵌套节点中生成xmlns:xsi声明   java重定向到youtube以上传jsp上可用的视频   java提高了JVM和ANT的性能   java如何将返回的JSON数据放在HTML表单中   java如何发送XWWWFORMURLENCODE在重新授权   java为什么jvm XX:+EliminateAllocations失败   堆移除和重建方法?(爪哇)   Stanford NPL in Spark(Scala)应用程序运行到Java堆空间(Java.lang.OutOfMemoryError)   调试java中打开/关闭println的任何方式(详细模式)   java IntelliJ在鼠标悬停时显示JavaDocs工具提示   Olingo Odata Java中的自动扩展选项   json将postgres文本arry转换为java列表?   oop需要帮助推断Java代码   复选框的java添加操作侦听器AbstractTableModel   java如何从公共静态void main(String[]args)传递值   java从数据库中获取大值   java Processing 2.0电影从jar运行时无法打开电影文件   java如何在不使用应用程序的情况下刷新活动?   尝试将JSON解析为ListView时的Android:JSON parse:null对象引用