Files
012-kaopeilian/知识库/DIFY_QUICK_REFERENCE.md
111 998211c483 feat: 初始化考培练系统项目
- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
2026-01-24 19:33:28 +08:00

104 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 🚀 Dify SQL 执行器快速参考卡
## 一、配置信息(复制即用)
### API 端点
```
http://120.79.247.16:8000/api/v1/sql/execute-simple
```
### 认证配置
- **鉴权类型**: 请求头
- **鉴权头部前缀**: Custom
- **键**: `X-API-Key`
- **值**: `dify-2025-kaopeilian`
## 二、常用查询示例
### 1. 获取用户统计
```json
{
"sql": "SELECT role, COUNT(*) as count FROM users GROUP BY role"
}
```
### 2. 查询课程列表
```json
{
"sql": "SELECT id, name, category, status FROM courses WHERE status = :status",
"params": {"status": "active"}
}
```
### 3. 查询知识点
```json
{
"sql": "SELECT * FROM knowledge_points WHERE course_id = :course_id",
"params": {"course_id": 1}
}
```
### 4. 查询考试记录
```json
{
"sql": "SELECT er.*, u.username FROM exam_results er JOIN users u ON er.user_id = u.id WHERE er.user_id = :user_id ORDER BY er.created_at DESC LIMIT 10",
"params": {"user_id": 1}
}
```
## 三、数据写入示例
### 1. 插入知识点
```json
{
"sql": "INSERT INTO knowledge_points (title, content, course_id, created_at) VALUES (:title, :content, :course_id, NOW())",
"params": {
"title": "面部护理基础知识",
"content": "面部护理包括清洁、爽肤、精华、乳液等步骤...",
"course_id": 1
}
}
```
### 2. 更新用户信息
```json
{
"sql": "UPDATE users SET last_login = NOW() WHERE id = :user_id",
"params": {"user_id": 1}
}
```
## 四、主要数据表
| 表名 | 说明 | 主要字段 |
|------|------|----------|
| users | 用户表 | id, username, role, created_at |
| courses | 课程表 | id, name, category, status |
| knowledge_points | 知识点表 | id, title, content, course_id |
| exams | 考试表 | id, course_id, title, total_score |
| exam_results | 考试结果表 | id, exam_id, user_id, score |
| training_records | 培训记录表 | id, user_id, course_id, progress |
## 五、测试命令
在终端测试(任何地方都可以执行):
```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"}'
```
## 六、注意事项
1. ✅ 使用参数化查询(`:param_name`防止SQL注入
2. ✅ API Key 永不过期,无需更新
3. ✅ 支持所有SQL操作SELECT, INSERT, UPDATE, DELETE等
4. ⚠️ 服务器需要先部署才能使用公网地址
5. 💡 本地测试使用 `localhost:8000` 替换IP地址
---
**状态**: 本地可用 | 公网待部署