Introduction to the Technical Principles of Using the 'txpostgres' Class Library in Python pip install txpostgres from twisted.internet import reactor from twisted.internet.defer import inlineCallbacks from twisted.internet.task import react from txpostgres import txpostgres dsn = txpostgres.ConnectionParameters(host='localhost', port=5432, dbname='mydb', user='myuser', password='mypassword') @inlineCallbacks def query(conn): result = yield conn.runQuery('SELECT * FROM mytable') print(result) def main(): connection = txpostgres.ConnectionPool(None) dsn = txpostgres.ConnectionParameters(host='localhost', port=5432, dbname='mydb', user='myuser', password='mypassword') conn = connection.connection(txpostgres.ConnectionPool, dsn) query(conn) if __name__ == '__main__': react(main)


上一篇:
下一篇:
切换中文