# 数据库API服务配置指南

**用途：** Dify工作流访问考培练系统数据库

---

## 快速配置

### 服务器信息
- **地址：** http://120.79.247.16:8000/api/v1
- **备用：** http://aiedu.ireborn.com.cn/api/v1

### Dify配置步骤

1. **导入OpenAPI Schema**
   - 文件：`openapi_sql_executor.json`
   - 位置：工具 → 导入OpenAPI

2. **配置认证**
   - 鉴权类型：请求头
   - 头部前缀：Custom
   - 键：`X-API-Key`
   - 值：`dify-2025-kaopeilian`

3. **选择端点**
   - `/sql/execute-simple`

---

## 常用SQL语句

### 查询知识点
```sql
SELECT kp.id, kp.name, kp.description, kp.topic_relation 
FROM knowledge_points kp 
INNER JOIN course_materials cm ON kp.material_id = cm.id 
WHERE kp.course_id = ? AND kp.is_deleted = FALSE AND cm.is_deleted = FALSE 
ORDER BY RAND() LIMIT 10
```

### 查询岗位信息
```sql
SELECT id, name, description, skills, level 
FROM positions 
WHERE id = ? AND is_deleted = FALSE
```

---

## 测试验证

```bash
curl -X POST http://120.79.247.16:8000/api/v1/sql/execute-simple \
  -H "X-API-Key: dify-2025-kaopeilian" \
  -H "Content-Type: application/json" \
  -d '{"sql": "SELECT COUNT(*) as total FROM users"}'
```

**预期结果：**
```json
{
  "code": 200,
  "message": "SQL 执行成功",
  "data": {
    "type": "query",
    "columns": ["total"],
    "rows": [{"total": 8}],
    "row_count": 1
  }
}
```

---

**最后更新：** 2025-10-12

