From 9b22dd5a3a297baf4feff460abf23d9a72883b8b Mon Sep 17 00:00:00 2001 From: hideyukiMORI Date: Tue, 19 May 2026 22:51:17 +0900 Subject: [PATCH] =?UTF-8?q?docs:=20DB=5FADAPTER=E5=88=A5=E3=81=AEdb=5Furl?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=BE=8B=E3=82=92=E8=A8=AD=E5=AE=9A=E3=83=AA?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=83=AC=E3=83=B3=E3=82=B9=E3=81=AB=E8=BF=BD?= =?UTF-8?q?=E8=A8=98=20(FT2-F5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #75 Co-Authored-By: Claude Sonnet 4.6 --- docs/ja/reference/configuration.md | 21 +++++++++++++++------ docs/reference/configuration.md | 21 +++++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/docs/ja/reference/configuration.md b/docs/ja/reference/configuration.md index 49a402e..fa3abbd 100644 --- a/docs/ja/reference/configuration.md +++ b/docs/ja/reference/configuration.md @@ -69,13 +69,22 @@ | `DB_USER` | `""` | DB ユーザー名(SQLite では無視) | | `DB_PASSWORD` | `""` | DB パスワード — `SecretStr` 型(ログに出力されない) | -### 接続 URL の例 +### 生成される `db_url` -| アダプター | 生成される URL | -|---|---| -| `sqlite` | `sqlite:///path/to/db.sqlite3` | -| `mysql` | `mysql+pymysql://user:pass@host:3306/dbname` | -| `pgsql` | `postgresql+psycopg2://user:pass@host:5432/dbname` | +`AppSettings.db_url` は各変数から自動生成されるプロパティです。 +アダプターと代表的な `DB_NAME` の組み合わせごとに生成される URL を示します。 + +| `DB_ADAPTER` | `DB_NAME` | 生成される `db_url` | +|---|---|---| +| `sqlite` | `:memory:` | `sqlite:///:memory:` | +| `sqlite` | `./data/app.db` | `sqlite:///./data/app.db` | +| `sqlite` | `/var/lib/app.db` | `sqlite:////var/lib/app.db` | +| `mysql` | `mydb` | `mysql+pymysql://user:pass@localhost:3306/mydb` | +| `pgsql` | `mydb` | `postgresql+psycopg2://user:pass@localhost:5432/mydb` | + +> SQLite インメモリ DB(`DB_NAME=:memory:`)を使う場合は `create_engine()` に +> `poolclass=StaticPool` を渡してください。詳細は +> [SQLAlchemy リポジトリのハウツー](../how-to/sqlalchemy-repository.md) を参照してください。 ## .env ファイル例 diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index 187e86c..cbd2c1b 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md @@ -69,13 +69,22 @@ Uses a fixed-window algorithm keyed on client IP. Exceeding the limit returns `4 | `DB_USER` | `""` | Database user (ignored for SQLite) | | `DB_PASSWORD` | `""` | Database password — stored as `SecretStr`, never logged | -### Generated connection URLs +### Generated `db_url` -| Adapter | URL format | -|---|---| -| `sqlite` | `sqlite:///path/to/db.sqlite3` | -| `mysql` | `mysql+pymysql://user:pass@host:3306/dbname` | -| `pgsql` | `postgresql+psycopg2://user:pass@host:5432/dbname` | +`AppSettings.db_url` is a computed property built from the variables above. +The table below shows what URL is generated for each adapter + common `DB_NAME` values: + +| `DB_ADAPTER` | `DB_NAME` | Generated `db_url` | +|---|---|---| +| `sqlite` | `:memory:` | `sqlite:///:memory:` | +| `sqlite` | `./data/app.db` | `sqlite:///./data/app.db` | +| `sqlite` | `/var/lib/app.db` | `sqlite:////var/lib/app.db` | +| `mysql` | `mydb` | `mysql+pymysql://user:pass@localhost:3306/mydb` | +| `pgsql` | `mydb` | `postgresql+psycopg2://user:pass@localhost:5432/mydb` | + +> For SQLite in-memory databases (`DB_NAME=:memory:`), pass `poolclass=StaticPool` to +> `create_engine()` so all connections share the same in-process database. +> See the [SQLAlchemy repository how-to](../how-to/sqlalchemy-repository.md) for details. ## Example `.env`