A small module for working quickly with the PostgreSQL
- Install package from pip
pip install postgresqlconnector
- Use connector
from postgresqlconnector import DB
print(DB.query('''select * from pg_stat_activity'''))
Get all rows from your sql query
- sql: str - Your query
- params: dict - Params for query
- Array of Record
result = DB.query('''select * from pg_stat_activity''')
print(result[0])
print(result[0].pid)
Get first row from your sql query
- sql: str - Your query
- params: dict - Params for query
- Record
result = DB.row('''select * from pg_stat_activity''')
print(result.pid)
Get first column from first row from you sql query
- sql: str - Your query
- params: dict - Params for query
- Scalar
result = DB.scalar('''select pid, * from pg_stat_activity''')
print(result)
Set database connections
- host: str = 'localhose' - Host
- port: str = '5432' - Port
- dbname: str = 'postgres' - Database name
- user: str = 'postgres' - User
- password: str = 'postgres' - Password
Work with transaction.
If an exception occurs in your code, the transaction will rollback
with DB.create_transaction():
# block for your code