Database Configuration
Corresponds to the database section of the configuration file.
| Field | Type | Default | Description |
|---|---|---|---|
driver | string | "sqlite3" | Database driver; supports sqlite3, mysql and postgres. |
data_source | string | SQLite file DSN | Data source connection string. Its format depends on the driver; see below. |
max_open_conns | int | 4 | Maximum number of open connections. When <= 0, the driver's default is used. |
max_idle_conns | int | 4 | Maximum number of idle connections. When <= 0, the driver's default is used. |
conn_max_life_time | int64 | 0 | Maximum lifetime of a single connection, in seconds. When <= 0, the driver's default is used. |
conn_max_idle_time | int64 | 0 | Maximum idle time of a single connection, in seconds. When <= 0, the driver's default is used. |
Values used automatically when max_open_conns / max_idle_conns / conn_max_life_time / conn_max_idle_time are set to 0:
| driver | max_open_conns | max_idle_conns | conn_max_life_time | conn_max_idle_time |
|---|---|---|---|---|
sqlite3 | 4 | 4 | unlimited | unlimited |
mysql | 10 | 10 | 30 minutes | 5 minutes |
postgres | 10 | 10 | 30 minutes | 5 minutes |
SQLite (Default, Zero Dependencies)
file:<data directory>/neokikoeru.db?mode=rwc&_busy_timeout=5000&_txlock=immediate&_journal_mode=WAL&_foreign_keys=trueWhat each parameter means:
mode=rwc: create the file if it does not exist_busy_timeout=5000: wait up to 5 seconds for a lock_txlock=immediate: take the write lock when the transaction begins, avoiding deadlocks during lock upgrades_journal_mode=WAL: WAL mode for better read/write concurrency_foreign_keys=true: enforce foreign key constraints
Never put the SQLite database on a network file system (NFS / SMB / Synology WebDAV mounts). WAL relies on reliable shared memory and file locks, and placing it on a network drive can easily corrupt the database. Media files can live on a network drive, but the database must be on a local disk.
MySQL
Example:
json
{
"driver": "mysql",
"data_source": "user:password@tcp(127.0.0.1:3306)/neokikoeru?charset=utf8mb4&parseTime=true&loc=Local"
}PostgreSQL
Example:
json
{
"driver": "postgres",
"data_source": "postgres://postgres:[email protected]:5432/neokikoeru?sslmode=disable"
}Notes
- When using MySQL or PostgreSQL, the database must be created beforehand. Neokikoeru only creates tables and indexes and migrates the schema automatically; it does not create databases.
