bash
pip install txpostgres
python
from txpostgres import txpostgres
python
dbpool = txpostgres.ConnectionPool(
maxConnections=10,
host='localhost',
port=5432,
database='mydb',
user='myuser',
password='mypassword'
)
python
def fetch_data():
query = "SELECT * FROM mytable"
return dbpool.runQuery(query)
result = fetch_data()
result.addCallback(handle_data)
def handle_data(data):
for row in data:
pass
python
def fetch_data():
query = "SELECT * FROM mytable"
try:
return dbpool.runQuery(query)
except Exception as e:
print("Error: ", e)
python
dbpool.close()