Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #81: Changing Louis to AiLab from variables #82

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LOUIS_DSN=
AILAB_DSN=
PGBASE=
PGUSER=
USER=
Expand All @@ -9,6 +9,6 @@ PGDATA=
OPENAI_API_KEY=
OPENAI_ENDPOINT=
OPENAI_API_ENGINE=
LOUIS_SCHEMA=
AILAB_SCHEMA=
DB_SERVER_CONTAINER_NAME=
FINESSE_WEIGHTS=
22 changes: 11 additions & 11 deletions ailab/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ class DBMissingEnvironmentVariable(DBError):
def raise_error(message):
raise DBMissingEnvironmentVariable(message)

LOUIS_DSN = os.environ.get("LOUIS_DSN")
if LOUIS_DSN is None:
AILAB_DSN = os.environ.get("AILAB_DSN")
if AILAB_DSN is None:
raise ValueError("LOUIS_DSN is not set")

LOUIS_SCHEMA = os.environ.get("LOUIS_SCHEMA")
if LOUIS_SCHEMA is None:
raise ValueError("LOUIS_SCHEMA is not set")
AILAB_SCHEMA = os.environ.get("AILAB_SCHEMA")
if AILAB_SCHEMA is None:
raise ValueError("AILAB_SCHEMA is not set")

def connect_db():
"""Connect to the postgresql database and return the connection."""
logger.info(f"Connecting to {LOUIS_DSN}")
logger.info(f"Connecting to {AILAB_DSN}")
connection = psycopg.connect(
conninfo=LOUIS_DSN,
conninfo=AILAB_DSN,
row_factory=dict_row,
autocommit=False,
options=f"-c search_path={LOUIS_SCHEMA},public")
options=f"-c search_path={AILAB_SCHEMA},public")
assert connection.info.encoding == 'utf-8', (
'Encoding is not UTF8: ' + connection.info.encoding)
# psycopg.extras.register_uuid()
Expand All @@ -49,10 +49,10 @@ def cursor(connection):
"""Return a cursor for the given connection."""
return connection.cursor()

def create_postgresql_url(dbname, tablename, entity_id, parameters=None):
def create_postgresql_url(dbname, tablename, entity_id, parameters=None,schema=AILAB_SCHEMA):
if parameters is None:
return f'postgresql://{dbname}/{LOUIS_SCHEMA}/{tablename}/{entity_id}'
return f'postgresql://{dbname}/{LOUIS_SCHEMA}/{tablename}/{entity_id}?{urllib.parse.urlencode(parameters)}'
return f'postgresql://{dbname}/{schema}/{tablename}/{entity_id}'
return f'postgresql://{dbname}/{schema}/{tablename}/{entity_id}?{urllib.parse.urlencode(parameters)}'


def parse_postgresql_url(url):
Expand Down
Loading