Skip to content

Commit

Permalink
Fixes session factory
Browse files Browse the repository at this point in the history
  • Loading branch information
vmesel committed Jul 18, 2024
1 parent 7876f75 commit 0ab2cf3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 7 additions & 4 deletions dialog_lib/db/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

from contextlib import contextmanager

engine = sa.create_engine(os.environ.get("DATABASE_URL"))
Session = sessionmaker(bind=engine)
from functools import cache

@cache
def get_engine():
return sa.create_engine(os.environ.get("DATABASE_URL"))

@contextmanager
def session_scope():
with Session(bind=engine) as session:
with Session(bind=get_engine()) as session:
try:
yield session
session.commit()
Expand All @@ -22,4 +25,4 @@ def session_scope():

def get_session():
with session_scope() as session:
return session
return session
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
version: '3.3'
version: "3.3"
services:
db:
image: pgvector/pgvector:pg15
restart: always
volumes:
- ./etc/db-ext-vector-test.sql:/docker-entrypoint-initdb.d/init.sql
- postgres_data:/var/lib/postgresql/data/
- ./etc/db-ext-vector-test.sql:/docker-entrypoint-initdb.d/init.sql
- postgres_data:/var/lib/postgresql/data/
environment:
POSTGRES_USER: talkdai
POSTGRES_PASSWORD: talkdai
Expand Down

0 comments on commit 0ab2cf3

Please sign in to comment.