11# Setup
22
3- To configure just using environment variables, check [ ` lifespan ` ] [ fastsqla.lifespan ] .
3+ FastSQLA provides two ways to configure your SQLAlchemy database connection:
44
5- To configure programatically, check [ ` new_lifespan ` ] [ fastsqla.new_lifespan ]
5+ - ** Environment variables** ([ ` lifespan ` ] [ fastsqla.lifespan ] ): Simple configuration
6+ following [ 12-factor app] ( https://12factor.net/config ) principles, ideal for most use cases.
7+ - ** Programmatic** ([ ` new_lifespan ` ] [ fastsqla.new_lifespan ] ): Direct SQLAlchemy engine
8+ configuration for advanced customization needs
69
710## ` fastsqla.lifespan `
811
@@ -20,7 +23,7 @@ The only required key is **`SQLALCHEMY_URL`**, which defines the database URL. I
2023specifies the database driver in the URL's scheme and allows embedding driver parameters
2124in the query string. Example:
2225
23- sqlite+aiosqlite:////tmp/test.db?check_same_thread=false
26+ sqlite+aiosqlite:////tmp/test.db
2427
2528All parameters of [ ` sqlalchemy.create_engine ` ] [ ] can be configured by setting environment
2629variables, with each parameter name prefixed by ** ` SQLALCHEMY_ ` ** .
@@ -46,8 +49,8 @@ variables, with each parameter name prefixed by **`SQLALCHEMY_`**.
4649 [` pool_size` ][sqlalchemy.create_engine.params.pool_size] of 50:
4750
4851 ` ` ` bash
49- export sqlalchemy_url=sqlite+aiosqlite:///tmp/test.db? check_same_thread=false
50- export sqlalchemy_pool_size=10
52+ export sqlalchemy_url=sqlite+aiosqlite:///tmp/test.db
53+ export sqlalchemy_pool_size=50
5154 ` ` `
5255
53563. :simple-mariadb: MariaDB url using [` aiomysql` ][sqlalchemy.dialects.mysql.aiomysql]
@@ -65,4 +68,4 @@ variables, with each parameter name prefixed by **`SQLALCHEMY_`**.
6568::: fastsqla.new_lifespan
6669 options:
6770 heading_level: false
68- show_source: false
71+ show_source: false
0 commit comments