postgres healthcheck works

This commit is contained in:
Pablo Martin 2024-08-09 14:45:10 +02:00
parent 91c79357f8
commit c38ce5cfe6
9 changed files with 203 additions and 8 deletions

27
anaxi/postgres_tools.py Normal file
View file

@ -0,0 +1,27 @@
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()