Skip to content

Instantly share code, notes, and snippets.

@sbalnojan
Created August 28, 2019 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbalnojan/57a19108f6b6f700202e68884725bf35 to your computer and use it in GitHub Desktop.
Save sbalnojan/57a19108f6b6f700202e68884725bf35 to your computer and use it in GitHub Desktop.
import os
from sqlalchemy import create_engine, func
from sqlalchemy.orm.session import sessionmaker
import psycopg2
import logging
def get_db_connection():
PGHOST = os.getenv("DB_HOST","localhost")
PGDATABASE = "postgres"
PGUSER = "postgres"
PGPASSWORD = ""
PGPORT = "5432"
conn_string = "postgresql://" + PGUSER + PGPASSWORD + "@" + PGHOST + ":" + PGPORT + "/" + PGDATABASE
conn = psycopg2.connect(conn_string)
return conn
def test_sql():
conn = get_db_connection()
cursor = conn.cursor()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment