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

feat: SQL model for collections #5

Merged
merged 1 commit into from
Jan 18, 2024
Merged

feat: SQL model for collections #5

merged 1 commit into from
Jan 18, 2024

Conversation

bjchambers
Copy link
Contributor

Starting with this since it is outside the main API and let's me figure out the ORM and interaction with the API methods, etc.

Starting with this since it is outside the main API and let's me figure
out the ORM and interaction with the API methods, etc.
@@ -19,6 +19,9 @@ class Config:
env_file = ".env"
env_file_encoding = "utf-8"

DB: str = "sqlite:///database.db?check_same_thread=false"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This supports the databases that sql alchemy does (eg., postgres:/// or postgres+asyncpg:/// for async) which seems nice. Although it's worth noting right now that since this uses a local file, it is non-persistent (need to tweak docker compose to give this a volume).

@@ -114,7 +117,7 @@ def custom_generate_unique_id_function(route: APIRoute) -> str:
from a variety of sources -- documents, web pages, audio, etc.
""",
"servers": [
{"url": "http://127.0.0.1:8000", "description": "Local server"},
{"url": "http://localhost:8000", "description": "Local server"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes a problem with CORS and the /docs site making calls.

@bjchambers bjchambers changed the title draft: SQL model for collections feat: SQL model for collections Jan 18, 2024
Copy link
Contributor

@kerinin kerinin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's the dependency injection they were talking about. Magic!

@bjchambers
Copy link
Contributor Author

I guess that's the dependency injection they were talking about. Magic!

That part is the:

DbDep = Annotated[Engine, Depends(_db)]

which let's me do db: DbDep as an argument to any request handler and get the Engine to use.

@bjchambers bjchambers merged commit e54d7b1 into main Jan 18, 2024
@bjchambers bjchambers deleted the sqlite branch January 18, 2024 18:26
@bjchambers bjchambers added the enhancement New feature or request label Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants