Skip to content

Commit ce89d02

Browse files
authored
Merge pull request #79 from hideyukiMORI/docs/issue-75-db-url-generation-examples
docs: DB_ADAPTER別のdb_url生成例を設定リファレンスに追記 (FT2-F5)
2 parents 6260244 + 9b22dd5 commit ce89d02

2 files changed

Lines changed: 30 additions & 12 deletions

File tree

docs/ja/reference/configuration.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,22 @@
6969
| `DB_USER` | `""` | DB ユーザー名(SQLite では無視) |
7070
| `DB_PASSWORD` | `""` | DB パスワード — `SecretStr` 型(ログに出力されない) |
7171

72-
### 接続 URL の例
72+
### 生成される `db_url`
7373

74-
| アダプター | 生成される URL |
75-
|---|---|
76-
| `sqlite` | `sqlite:///path/to/db.sqlite3` |
77-
| `mysql` | `mysql+pymysql://user:pass@host:3306/dbname` |
78-
| `pgsql` | `postgresql+psycopg2://user:pass@host:5432/dbname` |
74+
`AppSettings.db_url` は各変数から自動生成されるプロパティです。
75+
アダプターと代表的な `DB_NAME` の組み合わせごとに生成される URL を示します。
76+
77+
| `DB_ADAPTER` | `DB_NAME` | 生成される `db_url` |
78+
|---|---|---|
79+
| `sqlite` | `:memory:` | `sqlite:///:memory:` |
80+
| `sqlite` | `./data/app.db` | `sqlite:///./data/app.db` |
81+
| `sqlite` | `/var/lib/app.db` | `sqlite:////var/lib/app.db` |
82+
| `mysql` | `mydb` | `mysql+pymysql://user:pass@localhost:3306/mydb` |
83+
| `pgsql` | `mydb` | `postgresql+psycopg2://user:pass@localhost:5432/mydb` |
84+
85+
> SQLite インメモリ DB(`DB_NAME=:memory:`)を使う場合は `create_engine()`
86+
> `poolclass=StaticPool` を渡してください。詳細は
87+
> [SQLAlchemy リポジトリのハウツー](../how-to/sqlalchemy-repository.md) を参照してください。
7988
8089
## .env ファイル例
8190

docs/reference/configuration.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,22 @@ Uses a fixed-window algorithm keyed on client IP. Exceeding the limit returns `4
6969
| `DB_USER` | `""` | Database user (ignored for SQLite) |
7070
| `DB_PASSWORD` | `""` | Database password — stored as `SecretStr`, never logged |
7171

72-
### Generated connection URLs
72+
### Generated `db_url`
7373

74-
| Adapter | URL format |
75-
|---|---|
76-
| `sqlite` | `sqlite:///path/to/db.sqlite3` |
77-
| `mysql` | `mysql+pymysql://user:pass@host:3306/dbname` |
78-
| `pgsql` | `postgresql+psycopg2://user:pass@host:5432/dbname` |
74+
`AppSettings.db_url` is a computed property built from the variables above.
75+
The table below shows what URL is generated for each adapter + common `DB_NAME` values:
76+
77+
| `DB_ADAPTER` | `DB_NAME` | Generated `db_url` |
78+
|---|---|---|
79+
| `sqlite` | `:memory:` | `sqlite:///:memory:` |
80+
| `sqlite` | `./data/app.db` | `sqlite:///./data/app.db` |
81+
| `sqlite` | `/var/lib/app.db` | `sqlite:////var/lib/app.db` |
82+
| `mysql` | `mydb` | `mysql+pymysql://user:pass@localhost:3306/mydb` |
83+
| `pgsql` | `mydb` | `postgresql+psycopg2://user:pass@localhost:5432/mydb` |
84+
85+
> For SQLite in-memory databases (`DB_NAME=:memory:`), pass `poolclass=StaticPool` to
86+
> `create_engine()` so all connections share the same in-process database.
87+
> See the [SQLAlchemy repository how-to](../how-to/sqlalchemy-repository.md) for details.
7988
8089
## Example `.env`
8190

0 commit comments

Comments
 (0)