本文整理匯總了Python中psycopg.connect方法的典型用法代碼示例。如果您正苦於以下問題:Python psycopg.connect方法的具體用法?Python psycopg.connect怎麽用?Python psycopg.connect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類psycopg
的用法示例。
在下文中一共展示了psycopg.connect方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: import psycopg [as 別名]
# 或者: from psycopg import connect [as 別名]
def main():
dbh = psycopg.connect(conf.dbstring)
reloaddb(dbh, file('/local/dns-db/data/freenic/freenic.db'), 'ISO-8859-1')
示例2: get_cursor
# 需要導入模塊: import psycopg [as 別名]
# 或者: from psycopg import connect [as 別名]
def get_cursor(config):
"""Setup database connection."""
dbname = config.get('database', 'name')
dbuser = config.get('database', 'user')
dbpass = config.get('database', 'password')
dbconn = psycopg.connect(database=dbname, user=dbuser, password=dbpass)
return dbconn, dbconn.cursor()
示例3: load
# 需要導入模塊: import psycopg [as 別名]
# 或者: from psycopg import connect [as 別名]
def load():
"""
Loads a new context for the thread.
You can ask for a function to be run at loadtime by
adding it to the dictionary `loadhooks`.
"""
_context[currentThread()] = Storage()
ctx.status = '200 OK'
ctx.headers = []
if 'db_parameters' in globals():
connect(**db_parameters)
for x in loadhooks.values(): x()