huangro 发表于 2013-1-30 01:39:30

使用Twisted的adbapi操作数据库

一切以程序开始,^_^
from twisted.internet import reactorfrom twisted.enterprise import adbapiimport pyPgSQL.PgSQL as PgSQLdef getSites():    return dbpool.runQuery("select * from my_table")def printResult(l):    for item in l:      print itemdbpool = adbapi.ConnectionPool("pyPgSQL.PgSQL", user="robin", \    password="1234", host="192.168.1.1", database="my_database")getSites().addCallback(printResult)reactor.callLater(4, reactor.stop)reactor.run()

注:
    pyPgSQL是PostgreSql数据库的python语言接口,其实现符合Python DB-API 2.0规范。大名鼎鼎的python网络框架twisted的企业级特性,如连接池、异步连接等就使用pyPgSQL支持PostgreSql数据库。
页: [1]
查看完整版本: 使用Twisted的adbapi操作数据库