pip install txpostgres
python
from twisted.internet import reactor
from twisted.python import log
from twisted.enterprise import adbapi
from txpostgres import txpostgres
dbparams = {
"user": "your_username",
"password": "your_password",
"database": "your_database",
"host": "your_host",
}
connection = txpostgres.Connection()
dbconn = adbapi.ConnectionPool(None, connection, **dbparams)
def handle_error(error):
log.err(error)
reactor.stop()
def handle_query(result):
print(result)
reactor.stop()
def handle_operation(result):
print(result)
reactor.stop()
query = "SELECT * FROM your_table"
d = dbconn.runQuery(query)
d.addCallbacks(handle_query, handle_error)
operation = "INSERT INTO your_table (column1, column2) VALUES (%s, %s)"
params = ("value1", "value2")
d = dbconn.runOperation(operation, params)
d.addCallbacks(handle_operation, handle_error)
reactor.run()