fix(docs): fix config toml
This commit is contained in:
28
README.md
28
README.md
@@ -37,13 +37,21 @@ cargo run
|
||||
|
||||
**使用 MySQL/PostgreSQL**:
|
||||
|
||||
复制对应的配置文件并修改:
|
||||
使用环境变量配置或创建本地配置文件:
|
||||
|
||||
**方式一:使用环境变量(推荐)**
|
||||
```bash
|
||||
# 使用 MySQL
|
||||
cp config/development.mysql.toml config/local.toml
|
||||
DATABASE_TYPE=mysql DATABASE_HOST=localhost DATABASE_PORT=3306 DATABASE_USER=root DATABASE_PASSWORD=your-password DATABASE_DATABASE=web_template_dev cargo run
|
||||
|
||||
# 或使用 PostgreSQL
|
||||
cp config/development.postgresql.toml config/local.toml
|
||||
DATABASE_TYPE=postgresql DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_USER=postgres DATABASE_PASSWORD=your-password DATABASE_DATABASE=web_template_dev cargo run
|
||||
```
|
||||
|
||||
**方式二:创建本地配置文件**
|
||||
```bash
|
||||
# 复制开发环境配置
|
||||
cp config/development.toml config/local.toml
|
||||
|
||||
# 编辑 config/local.toml,修改数据库连接信息
|
||||
# 然后运行
|
||||
@@ -98,18 +106,14 @@ curl -X POST http://localhost:3000/auth/register \
|
||||
使用 `config/` 目录下的配置文件:
|
||||
|
||||
```bash
|
||||
# SQLite(默认)
|
||||
# SQLite(默认,修改 config/development.toml 中的 database.type 为 "sqlite")
|
||||
cargo run
|
||||
|
||||
# MySQL
|
||||
cp config/development.mysql.toml config/local.toml
|
||||
# 编辑 config/local.toml
|
||||
cargo run -- -c config/local.toml
|
||||
# MySQL(修改 config/development.toml 中的 database.type 为 "mysql")
|
||||
cargo run
|
||||
|
||||
# PostgreSQL
|
||||
cp config/development.postgresql.toml config/local.toml
|
||||
# 编辑 config/local.toml
|
||||
cargo run -- -c config/local.toml
|
||||
# PostgreSQL(修改 config/development.toml 中的 database.type 为 "postgresql")
|
||||
cargo run
|
||||
```
|
||||
|
||||
**生产环境**:
|
||||
|
||||
@@ -400,17 +400,16 @@ cargo run -- -c config/local.toml
|
||||
|
||||
**重要**:本项目不支持 .env 文件。开发环境请使用 `config/` 目录下的 toml 配置文件。
|
||||
|
||||
复制并修改 MySQL 配置文件:
|
||||
编辑 MySQL 配置文件:
|
||||
|
||||
```bash
|
||||
# 复制 MySQL 配置模板
|
||||
cp config/development.mysql.toml config/local.toml
|
||||
# 编辑开发环境配置文件
|
||||
nano config/development.toml
|
||||
|
||||
# 编辑 config/local.toml,修改数据库连接信息
|
||||
nano config/local.toml
|
||||
# 设置 database.type = "mysql" 并修改连接信息
|
||||
|
||||
# 运行
|
||||
cargo run -- -c config/local.toml
|
||||
cargo run
|
||||
```
|
||||
|
||||
或使用环境变量(适用于 Docker/Kubernetes):
|
||||
|
||||
@@ -92,22 +92,15 @@ cargo run
|
||||
|
||||
#### 方式二:使用 MySQL/PostgreSQL
|
||||
|
||||
**步骤 1**:复制对应的配置文件
|
||||
**步骤 1**:修改配置文件
|
||||
|
||||
```bash
|
||||
# 使用 MySQL
|
||||
cp config/development.mysql.toml config/local.toml
|
||||
|
||||
# 或使用 PostgreSQL
|
||||
cp config/development.postgresql.toml config/local.toml
|
||||
```
|
||||
|
||||
**步骤 2**:修改配置文件
|
||||
|
||||
编辑 `config/local.toml`,修改数据库连接信息:
|
||||
编辑 `config/development.toml`,修改数据库类型和连接信息:
|
||||
|
||||
```toml
|
||||
[database]
|
||||
# 修改数据库类型:mysql, postgresql 或 sqlite
|
||||
type = "mysql" # 或 "postgresql"
|
||||
|
||||
# MySQL 配置
|
||||
host = "localhost"
|
||||
port = 3306
|
||||
@@ -116,6 +109,7 @@ password = "your-password"
|
||||
database = "web_template_dev"
|
||||
|
||||
# 或 PostgreSQL 配置
|
||||
# type = "postgresql"
|
||||
# host = "localhost"
|
||||
# port = 5432
|
||||
# user = "postgres"
|
||||
@@ -123,11 +117,10 @@ database = "web_template_dev"
|
||||
# database = "web_template_dev"
|
||||
```
|
||||
|
||||
**步骤 3**:运行项目
|
||||
**步骤 2**:运行项目
|
||||
|
||||
```bash
|
||||
# 使用指定配置文件运行
|
||||
cargo run -- -c config/local.toml
|
||||
cargo run
|
||||
```
|
||||
|
||||
#### 方式三:通过环境变量覆盖(适用于 Docker/Kubernetes)
|
||||
@@ -171,11 +164,16 @@ cargo run
|
||||
|
||||
**选项 1**:修改配置文件
|
||||
|
||||
```bash
|
||||
# 复制 MySQL 配置模板
|
||||
cp config/development.mysql.toml config/local.toml
|
||||
编辑 `config/development.toml`,设置数据库类型为 `mysql` 并修改连接信息:
|
||||
|
||||
# 编辑 config/local.toml,修改数据库连接信息
|
||||
```toml
|
||||
[database]
|
||||
type = "mysql"
|
||||
host = "localhost"
|
||||
port = 3306
|
||||
user = "root"
|
||||
password = "your-password"
|
||||
database = "web_template_dev"
|
||||
```
|
||||
|
||||
**选项 2**:使用环境变量
|
||||
@@ -198,7 +196,21 @@ cargo run
|
||||
|
||||
**适用场景**:需要高级数据库功能的应用
|
||||
|
||||
**配置方法**:与 MySQL 类似,使用 `config/development.postgresql.toml` 或环境变量
|
||||
**配置方法**:
|
||||
|
||||
编辑 `config/development.toml`,设置数据库类型为 `postgresql` 并修改连接信息:
|
||||
|
||||
```toml
|
||||
[database]
|
||||
type = "postgresql"
|
||||
host = "localhost"
|
||||
port = 5432
|
||||
user = "postgres"
|
||||
password = "your-password"
|
||||
database = "web_template_dev"
|
||||
```
|
||||
|
||||
或使用环境变量(格式与 MySQL 相同)。
|
||||
|
||||
### 认证配置
|
||||
|
||||
@@ -243,7 +255,8 @@ cargo run
|
||||
|
||||
**使用指定配置文件**:
|
||||
```bash
|
||||
cargo run -- -c config/development.mysql.toml
|
||||
# 修改 config/development.toml 后运行
|
||||
cargo run
|
||||
```
|
||||
|
||||
**使用环境变量**:
|
||||
|
||||
@@ -99,9 +99,7 @@ web-rust-template/
|
||||
│
|
||||
├── config/ # 配置文件目录
|
||||
│ ├── default.toml # 默认配置
|
||||
│ ├── development.sqlite.toml # SQLite 开发环境配置
|
||||
│ ├── development.mysql.toml # MySQL 开发环境配置
|
||||
│ ├── development.postgresql.toml # PostgreSQL 开发环境配置
|
||||
│ ├── development.toml # 开发环境配置(支持 MySQL/PostgreSQL/SQLite)
|
||||
│ └── production.toml # 生产环境配置
|
||||
│
|
||||
├── sql/ # SQL 脚本
|
||||
|
||||
Reference in New Issue
Block a user