### TableChat API 测试集合 ### 基础 URL @baseUrl = http://localhost:7888/api/v1 @pgUrl = postgresql://root:0412yxyxysYs@localhost:5432/postgres
### 1. 列出所有数据库连接 GET {{baseUrl}}/dbs Content-Type: application/json
### 2. 添加 PostgreSQL 数据库连接 PUT {{baseUrl}}/dbs/testdb Content-Type: application/json
- {
- "url": "{{pgUrl}}"
}
### 3. 获取特定数据库信息 GET {{baseUrl}}/dbs/testdb Content-Type: application/json
### 4. 更新数据库连接 PUT {{baseUrl}}/dbs/testdb Content-Type: application/json
- {
- "url": "{{pgUrl}}"
}
### 5. 删除数据库连接 DELETE {{baseUrl}}/dbs/testdb Content-Type: application/json
### 6. 执行简单查询 - SELECT 1 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT 1 as test_column"
}
### 7. 查询当前数据库版本 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT version()"
}
### 8. 查询当前时间 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT NOW() as current_time, CURRENT_USER as current_user"
}
### 9. 列出所有表 (public schema) POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT tablename FROM pg_tables WHERE schemaname = 'public'"
}
### 10. 查询带 LIMIT 的语句(测试 LIMIT 保留) POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT * FROM pg_tables LIMIT 5"
}
### 11. 查询不带 LIMIT(测试自动注入 LIMIT 1000) POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT * FROM pg_tables"
}
### 12. 测试 WHERE 条件查询 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT * FROM pg_tables WHERE schemaname = 'public'"
}
### 13. 测试 JOIN 查询 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT t.tablename, c.column_name, c.data_type FROM pg_tables t JOIN information_schema.columns c ON t.tablename = c.table_name WHERE t.schemaname = 'public' LIMIT 10"
}
### 14. 测试 SQL 语法错误 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELEC * FRM pg_tables"
}
### 15. 测试非 SELECT 语句 - INSERT (应该被拒绝) POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "INSERT INTO test_table VALUES (1, 'test')"
}
### 16. 测试非 SELECT 语句 - UPDATE (应该被拒绝) POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "UPDATE pg_tables SET tablename = 'hacked'"
}
### 17. 测试非 SELECT 语句 - DELETE (应该被拒绝) POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "DELETE FROM pg_tables"
}
### 18. 测试 DDL 语句 - CREATE (应该被拒绝) POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "CREATE TABLE evil_table (id INT)"
}
### 19. 测试 DDL 语句 - DROP (应该被拒绝) POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "DROP TABLE pg_tables"
}
### 20. 测试查询不存在的数据库 POST {{baseUrl}}/dbs/nonexistent/query Content-Type: application/json
- {
- "sql": "SELECT 1"
}
### 21. 列出所有 schema POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT schema_name FROM information_schema.schemata ORDER BY schema_name"
}
### 22. 列出某个 schema 的所有表 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT table_name, table_type FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name"
}
### 23. 查询表的列信息 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT column_name, data_type, is_nullable, column_default FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'pg_tables' ORDER BY ordinal_position"
}
### 24. 查询表的主键信息 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT tc.table_name, kcu.column_name FROM information_schema.table_constraints tc JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name WHERE tc.constraint_type = 'PRIMARY KEY' AND tc.table_schema = 'public' LIMIT 10"
}
### 25. 测试大结果集(自动 LIMIT) POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT * FROM information_schema.columns"
}
### 26. 测试复杂查询 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT t.tablename, COUNT(c.column_name) as column_count FROM pg_tables t LEFT JOIN information_schema.columns c ON t.tablename = c.table_name WHERE t.schemaname = 'public' GROUP BY t.tablename ORDER BY column_count DESC"
}
### 27. 查询数据库大小 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT pg_database.datname as database_name, pg_size_pretty(pg_database_size(pg_database.datname)) as size FROM pg_database ORDER BY pg_database_size(pg_database.datname) DESC LIMIT 10"
}
### 28. 查询表大小 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) as size FROM pg_tables WHERE schemaname = 'public' ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC LIMIT 10"
}
### 29. 查询活动连接数 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT count(*) as active_connections FROM pg_stat_activity WHERE state = 'active'"
}
### 30. 查询索引信息 POST {{baseUrl}}/dbs/testdb/query Content-Type: application/json
- {
- "sql": "SELECT schemaname, tablename, indexname, indexdef FROM pg_indexes WHERE schemaname = 'public' LIMIT 10"
}
### 31. 自然语言查询 - 简单查询 POST {{baseUrl}}/dbs/testdb/query/natural Content-Type: application/json
- {
- "prompt": "查询所有的 schema 名称"
}
### 32. 自然语言查询 - 表信息查询 POST {{baseUrl}}/dbs/testdb/query/natural Content-Type: application/json
- {
- "prompt": "列出 public schema 下的所有表"
}
### 33. 自然语言查询 - 带条件的查询 POST {{baseUrl}}/dbs/testdb/query/natural Content-Type: application/json
- {
- "prompt": "查询数据库的版本信息"
}
### 34. 自然语言查询 - 统计查询 POST {{baseUrl}}/dbs/testdb/query/natural Content-Type: application/json
- {
- "prompt": "统计 pg_tables 表中有多少条记录"
}
### 35. 自然语言查询 - 复杂查询 POST {{baseUrl}}/dbs/testdb/query/natural Content-Type: application/json
- {
- "prompt": "查询每个 schema 下有多少张表,按表数量倒序排列"
}
### 36. 自然语言查询 - 不存在的数据库 POST {{baseUrl}}/dbs/nonexistent/query/natural Content-Type: application/json
- {
- "prompt": "查询用户信息"
}
### 37. 获取数据库 Metadata GET {{baseUrl}}/dbs/testdb/metadata Content-Type: application/json
### 38. 强制刷新 Metadata GET {{baseUrl}}/dbs/testdb/metadata?refresh=true Content-Type: application/json
### 39. 刷新 Metadata (POST) POST {{baseUrl}}/dbs/testdb/metadata/refresh Content-Type: application/json
### 40. 获取不存在数据库的 Metadata GET {{baseUrl}}/dbs/nonexistent/metadata Content-Type: application/json
### 41. 创建编辑器记忆 - 保存 SQL 内容 POST {{baseUrl}}/editor-memory Content-Type: application/json
- {
- "connectionId": "test_conn_1", "content": "SELECT * FROM users WHERE id = 1;"
}
### 42. 创建编辑器记忆 - 保存空内容 POST {{baseUrl}}/editor-memory Content-Type: application/json
- {
- "connectionId": "test_conn_2", "content": ""
}
### 43. 创建编辑器记忆 - 保存多行 SQL POST {{baseUrl}}/editor-memory Content-Type: application/json
- {
- "connectionId": "test_conn_1", "content": "SELECT u.id, u.name, o.order_datenFROM users unJOIN orders o ON u.id = o.user_idnWHERE o.status = 'completed';"
}
### 44. 获取指定连接的所有编辑器记忆 GET {{baseUrl}}/editor-memory/test_conn_1 Content-Type: application/json
### 45. 获取不存在连接的编辑器记忆(应返回空列表) GET {{baseUrl}}/editor-memory/nonexistent_conn Content-Type: application/json
### 46. 获取指定连接的最新编辑器记忆 GET {{baseUrl}}/editor-memory/latest/test_conn_1 Content-Type: application/json
### 47. 获取不存在连接的最新记忆(应返回 null) GET {{baseUrl}}/editor-memory/latest/nonexistent_conn Content-Type: application/json
### 48. 删除单条编辑器记忆(需要先创建并获取 ID) # 先创建一条记录用于测试删除 POST {{baseUrl}}/editor-memory Content-Type: application/json
- {
- "connectionId": "test_delete", "content": "SELECT 1 as to_be_deleted;"
}
### 49. 删除单条编辑器记忆 - 使用实际 ID # 替换 {id} 为实际的记录 ID DELETE {{baseUrl}}/editor-memory/1 Content-Type: application/json
### 50. 删除不存在的记忆记录(应返回 404) DELETE {{baseUrl}}/editor-memory/99999 Content-Type: application/json
### 51. 清空指定连接的所有编辑器记忆 DELETE {{baseUrl}}/editor-memory/connection/test_conn_1 Content-Type: application/json
### 52. 清空不存在连接的编辑器记忆(应返回删除数为 0) DELETE {{baseUrl}}/editor-memory/connection/empty_connection Content-Type: application/json
### 53. 测试完整工作流 - 创建、查询、删除 # Step 1: 创建记录 POST {{baseUrl}}/editor-memory Content-Type: application/json
- {
- "connectionId": "workflow_test", "content": "SELECT * FROM test_workflow;"
}
### Step 2: 查询该连接的所有记录 GET {{baseUrl}}/editor-memory/workflow_test Content-Type: application/json
### Step 3: 获取最新记录 GET {{baseUrl}}/editor-memory/latest/workflow_test Content-Type: application/json
### Step 4: 清空该连接的所有记录 DELETE {{baseUrl}}/editor-memory/connection/workflow_test Content-Type: application/json
### Step 5: 验证清空后为空 GET {{baseUrl}}/editor-memory/workflow_test Content-Type: application/json
### 54. 创建新对话 POST {{baseUrl}}/dbs/testdb/conversations Content-Type: application/json
- {
- "title": "Test Conversation"
}
### 55. 创建对话 - 使用默认标题 POST {{baseUrl}}/dbs/testdb/conversations Content-Type: application/json
{}
### 56. 列出所有对话 GET {{baseUrl}}/dbs/testdb/conversations Content-Type: application/json
### 57. 列出对话 - 限制数量 GET {{baseUrl}}/dbs/testdb/conversations?limit=10 Content-Type: application/json
### 58. 获取特定对话(替换 {conversationId} 为实际 ID) GET {{baseUrl}}/conversations/{conversationId} Content-Type: application/json
### 59. 获取对话 - 带消息限制 GET {{baseUrl}}/conversations/{conversationId}?messageLimit=50 Content-Type: application/json
### 60. 更新对话标题 PATCH {{baseUrl}}/conversations/{conversationId} Content-Type: application/json
- {
- "title": "Updated Title"
}
### 61. 添加用户消息到对话 POST {{baseUrl}}/conversations/{conversationId}/messages Content-Type: application/json
- {
- "role": "user", "content": "Help me query all users from the database"
}
### 62. 添加助手消息到对话(带 tool calls) POST {{baseUrl}}/conversations/{conversationId}/messages Content-Type: application/json
- {
"role": "assistant", "content": "I'll help you query the users. Let me first check the table structure.", "toolCalls": [
- {
- "id": "tool-1", "tool": "list_tables", "input": {}, "status": "completed", "output": "["users", "orders", "products"]", "durationMs": 150
}
]
}
### 63. 生成对话标题 POST {{baseUrl}}/conversations/{conversationId}/generate-title Content-Type: application/json
- {
- "firstMessage": "Help me query all users from the database"
}
### 64. 删除对话 DELETE {{baseUrl}}/conversations/{conversationId} Content-Type: application/json
### 65. 获取不存在的对话(应返回 404) GET {{baseUrl}}/conversations/non-existent-id Content-Type: application/json
### 66. 对话完整工作流测试 # Step 1: 创建对话 POST {{baseUrl}}/dbs/testdb/conversations Content-Type: application/json
- {
- "title": "Workflow Test Conversation"
}
### Step 2: 添加用户消息(替换 {conversationId}) POST {{baseUrl}}/conversations/{conversationId}/messages Content-Type: application/json
- {
- "role": "user", "content": "Show me the database schema"
}
### Step 3: 添加助手回复 POST {{baseUrl}}/conversations/{conversationId}/messages Content-Type: application/json
- {
- "role": "assistant", "content": "Here is the database schema with all tables and their columns..."
}
### Step 4: 获取对话及消息 GET {{baseUrl}}/conversations/{conversationId} Content-Type: application/json
### Step 5: 删除测试对话 DELETE {{baseUrl}}/conversations/{conversationId} Content-Type: application/json