Skip to content

Commit

Permalink
Back out collection name
Browse files Browse the repository at this point in the history
  • Loading branch information
kerinin committed Jan 29, 2024
1 parent 0c26bd0 commit 308752f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
3 changes: 0 additions & 3 deletions dewy/documents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@


class CreateRequest(BaseModel):
collection: Optional[str] = None
"""The name of the collection the document should be added to. Either `collection` or `collection_id` must be provided"""

collection_id: Optional[int] = None
"""The id of the collection the document should be added to. Either `collection` or `collection_id` must be provided"""

Expand Down
12 changes: 1 addition & 11 deletions dewy/documents/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,15 @@ async def add_document(
) -> Document:
"""Add a document."""

collection_id = req.collection_id
async with pg_pool.acquire() as conn:
if collection_id is None:
collection_id = await conn.fetchval(
"""
SELECT collection_id
FROM document
WHERE name = $1
""",
req.collection
)
row = None
row = await conn.fetchrow(
"""
INSERT INTO document (collection_id, url, ingest_state)
VALUES ($1, $2, 'pending')
RETURNING id, collection_id, url, ingest_state, ingest_error
""",
collection_id,
req.collection_id,
req.url,
)

Expand Down

0 comments on commit 308752f

Please sign in to comment.