-
Notifications
You must be signed in to change notification settings - Fork 1
feat: new_lifespan to allow configuring sqla engine directly #25
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2115d9b
feat: new_lifespan to allow configuring sqla engine directly
hadrien c0dc7b9
docs + fix typos
hadrien 425a395
Update README.md
hadrien b557ae4
add test
hadrien 3fa4f7b
Merge branch 'feat/configuration' of github.com:hadrien/FastSQLA into…
hadrien 794d8bc
type
hadrien File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,13 +1,20 @@ | ||
| # Setup | ||
|
|
||
| FastSQLA provides two ways to configure your SQLAlchemy database connection: | ||
|
|
||
| - **Environment variables** ([`lifespan`][fastsqla.lifespan]): Simple configuration | ||
| following [12-factor app](https://12factor.net/config) principles, ideal for most use cases. | ||
| - **Programmatic** ([`new_lifespan`][fastsqla.new_lifespan]): Direct SQLAlchemy engine | ||
| configuration for advanced customization needs | ||
|
|
||
| ## `fastsqla.lifespan` | ||
|
|
||
| ::: fastsqla.lifespan | ||
| options: | ||
| heading_level: false | ||
| show_source: false | ||
|
|
||
| ## Configuration | ||
| ### Lifespan configuration | ||
|
|
||
| Configuration is done exclusively via environment variables, adhering to the | ||
| [**Twelve-Factor App methodology**](https://12factor.net/config). | ||
|
|
@@ -16,7 +23,7 @@ The only required key is **`SQLALCHEMY_URL`**, which defines the database URL. I | |
| specifies the database driver in the URL's scheme and allows embedding driver parameters | ||
| in the query string. Example: | ||
|
|
||
| sqlite+aiosqlite:////tmp/test.db?check_same_thread=false | ||
| sqlite+aiosqlite:////tmp/test.db | ||
|
|
||
| All parameters of [`sqlalchemy.create_engine`][] can be configured by setting environment | ||
| variables, with each parameter name prefixed by **`SQLALCHEMY_`**. | ||
|
|
@@ -26,7 +33,7 @@ variables, with each parameter name prefixed by **`SQLALCHEMY_`**. | |
| FastSQLA is **case-insensitive** when reading environment variables, so parameter | ||
| names prefixed with **`SQLALCHEMY_`** can be provided in any letter case. | ||
|
|
||
| ### Examples | ||
| #### Examples | ||
|
|
||
| 1. :simple-postgresql: PostgreSQL url using | ||
| [`asyncpg`][sqlalchemy.dialects.postgresql.asyncpg] driver with a | ||
|
|
@@ -42,8 +49,8 @@ variables, with each parameter name prefixed by **`SQLALCHEMY_`**. | |
| [`pool_size`][sqlalchemy.create_engine.params.pool_size] of 50: | ||
|
|
||
| ```bash | ||
| export sqlalchemy_url=sqlite+aiosqlite:///tmp/test.db?check_same_thread=false | ||
| export sqlalchemy_pool_size=10 | ||
| export sqlalchemy_url=sqlite+aiosqlite:///tmp/test.db | ||
| export sqlalchemy_pool_size=50 | ||
| ``` | ||
|
|
||
| 3. :simple-mariadb: MariaDB url using [`aiomysql`][sqlalchemy.dialects.mysql.aiomysql] | ||
|
|
@@ -53,3 +60,12 @@ variables, with each parameter name prefixed by **`SQLALCHEMY_`**. | |
| export sqlalchemy_url=mysql+aiomysql://bob:[email protected]/app | ||
| export sqlalchemy_echo=true | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| ## `fastsqla.new_lifespan` | ||
|
|
||
| ::: fastsqla.new_lifespan | ||
| options: | ||
| heading_level: false | ||
| show_source: false | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.