Files
X-Agents/team-require/api/database-create.md

105 lines
2.5 KiB
Markdown
Raw Normal View History

# 创建数据库配置
## 接口地址
```
POST /database/add
```
## 请求参数
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| name | string | 是 | 数据库名称 |
| description | string | 否 | 描述 |
| db_type | string | 是 | 数据库类型 |
| host | string | 是 | 主机 |
| port | int | 是 | 端口 |
| username | string | 是 | 用户名 |
| password | string | 否 | 密码 |
| database | string | 是 | 数据库名 |
| charset | string | 否 | 字符集 |
| ssl_mode | string | 否 | SSL 模式 |
| sub_tables | array | 否 | 子表配置列表 |
### sub_tables[] 详情
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| parent_table | string | 是 | 原始表名 |
| sub_table_name | string | 是 | 子表别名 |
| sub_table_comment | string | 否 | 子表注释 |
| mapping_type | string | 否 | 映射类型 |
| relation_field | string | 否 | 关联字段 |
| relation_type | string | 否 | 关联类型 |
| fields | array | 否 | 字段映射列表 |
### fields[] 详情
| 参数 | 类型 | 必填 | 说明 |
|------|------|------|------|
| column_name | string | 是 | 列名 |
| mapped_name | string | 是 | 中文映射名 |
## 请求示例
```json
{
"name": "学生数据库",
"description": "用于存储学生信息",
"db_type": "mysql",
"host": "localhost",
"port": 3306,
"username": "root",
"password": "root",
"database": "students",
"charset": "utf8mb4",
"sub_tables": [
{
"parent_table": "users",
"sub_table_name": "用户表",
"sub_table_comment": "用户信息",
"fields": [
{"column_name": "id", "mapped_name": "用户ID"},
{"column_name": "name", "mapped_name": "用户名"}
]
}
]
}
```
## 返回参数
| 参数 | 类型 | 说明 |
|------|------|------|
| id | string | 数据库记录ID |
| name | string | 数据库名称 |
| db_type | string | 数据库类型 |
| host | string | 主机 |
| port | int | 端口 |
| ... | ... | 其他字段 |
## 返回示例
```json
{
"id": "xxx-xxx-xxx",
"name": "学生数据库",
"description": "用于存储学生信息",
"db_type": "mysql",
"host": "localhost",
"port": 3306,
"username": "root",
"password": "root",
"database": "students",
"table_count": 1,
"charset": "utf8mb4",
"created_at": "2026-03-06T15:00:00Z"
}
```
## 说明
- 创建时会自动连接数据库获取表结构 DDL
- 如果传入了 `fields`(字段映射),会自动生成带 COMMENT 的新 DDL 并存储