-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Andrea Waltlova <[email protected]>
- Loading branch information
1 parent
dd4a78f
commit b07b71a
Showing
9 changed files
with
68 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import os | ||
|
||
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
DB_NAME = os.getenv("SQLALCHEMY_DB", "release_notes_db") | ||
DB_USER = os.getenv("SQLALCHEMY_USER", "postgres") | ||
DB_PASSWORD = os.getenv("SQLALCHEMY_PASSWORD", "password") | ||
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg://{DB_USER}:{DB_PASSWORD}@localhost/{DB_NAME}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# crud.py | ||
from sqlalchemy import text | ||
from sqlalchemy.ext.asyncio import AsyncSession | ||
|
||
|
||
async def get_paragraphs(db: AsyncSession, release_note_id: int, keyword: str): | ||
query = text(""" | ||
SELECT section_id, raw_text, | ||
to_tsvector('english', raw_text) @@ to_tsquery('english', :keyword) AS relevant | ||
FROM paragraphs | ||
WHERE release_note_id = :release_note_id | ||
""") | ||
|
||
result = await db.execute(query, {"release_note_id": release_note_id, "keyword": keyword}) | ||
rows = result.fetchall() | ||
|
||
paragraphs = [{"section_id": row.section_id, "raw_text": row.raw_text, "relevant": row.relevant} for row in rows] | ||
return paragraphs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# database.py | ||
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from app.config import SQLALCHEMY_DATABASE_URI | ||
|
||
engine = create_async_engine(SQLALCHEMY_DATABASE_URI, echo=True) | ||
|
||
async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False) | ||
|
||
# Dependency to provide the database session | ||
async def get_db(): | ||
async with async_session() as session: | ||
yield session |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ fastapi | |
uvicorn | ||
beautifulsoup4 | ||
pydantic | ||
sqlalchemy | ||
psycopg[binary] |