27 lines
709 B
Python
27 lines
709 B
Python
import psycopg2
|
|
from psycopg2.sql import SQL
|
|
|
|
from anaxi.config import PostgresDatabaseConfig
|
|
|
|
|
|
def create_postgres_connection_from_config(config: PostgresDatabaseConfig):
|
|
return psycopg2.connect(
|
|
dbname=config.dbname,
|
|
user=config.user,
|
|
password=config.password,
|
|
host=config.host,
|
|
port=config.port,
|
|
)
|
|
|
|
|
|
def simply_query(config: PostgresDatabaseConfig, query: SQL):
|
|
with psycopg2.connect(
|
|
dbname=config.dbname,
|
|
user=config.user,
|
|
password=config.password,
|
|
host=config.host,
|
|
port=config.port,
|
|
) as db_connection:
|
|
cursor = db_connection.cursor()
|
|
cursor.execute(query)
|
|
return cursor.fetchall()
|