本文档介绍新开发的数据库表检查API的使用方法。
POST /api/v0/database/tables
POST /api/v0/database/table/ddl
curl -X POST http://localhost:8084/api/v0/database/tables \
-H "Content-Type: application/json" \
-d '{
"db_connection": "postgresql://postgres:postgres@192.168.67.1:5432/highway_db",
"schema": "public,ods"
}'
curl -X POST http://localhost:8084/api/v0/database/tables \
-H "Content-Type: application/json" \
-d '{
"db_connection": "postgresql://postgres:postgres@192.168.67.1:5432/highway_db",
"schema": "public,ods",
"table_name_pattern": "ods_*"
}'
参数 | 类型 | 必需 | 说明 |
---|---|---|---|
db_connection | string | ✅ | 完整的PostgreSQL连接字符串 |
schema | string | ❌ | 查询的schema,支持多个用逗号分隔,默认为public |
table_name_pattern | string | ❌ | 表名模糊搜索模式,支持通配符:ods_* 、*_dim 、*fact* |
{
"success": true,
"code": 200,
"message": "获取表列表成功",
"data": {
"tables": [
"public.bss_company",
"public.bss_branch_copy",
"ods.raw_data"
],
"total": 3,
"schemas": ["public", "ods"],
"db_connection_info": {
"database": "highway_db"
}
}
}
{
"success": true,
"code": 200,
"message": "获取表列表成功",
"data": {
"tables": [
"ods.ods_user",
"ods.ods_order",
"ods.ods_product"
],
"total": 3,
"schemas": ["ods"],
"table_name_pattern": "ods_*",
"db_connection_info": {
"database": "highway_db"
}
}
}
curl -X POST http://localhost:8084/api/v0/database/table/ddl \
-H "Content-Type: application/json" \
-d '{
"db_connection": "postgresql://postgres:postgres@192.168.67.1:5432/highway_db",
"table": "public.bss_company",
"business_context": "高速公路服务区管理系统",
"type": "ddl"
}'
curl -X POST http://localhost:8084/api/v0/database/table/ddl \
-H "Content-Type: application/json" \
-d '{
"db_connection": "postgresql://postgres:postgres@192.168.67.1:5432/highway_db",
"table": "public.bss_company",
"business_context": "高速公路服务区管理系统",
"type": "md"
}'
curl -X POST http://localhost:8084/api/v0/database/table/ddl \
-H "Content-Type: application/json" \
-d '{
"db_connection": "postgresql://postgres:postgres@192.168.67.1:5432/highway_db",
"table": "public.bss_company",
"business_context": "高速公路服务区管理系统",
"type": "both"
}'
参数 | 类型 | 必需 | 说明 |
---|---|---|---|
db_connection | string | ✅ | 完整的PostgreSQL连接字符串 |
table | string | ✅ | 表名,格式为 schema.tablename |
business_context | string | ❌ | 业务上下文描述,用于LLM生成更准确的注释 |
type | string | ❌ | 输出类型:ddl/md/both,默认ddl |
{
"success": true,
"code": 200,
"message": "获取表DDL成功",
"data": {
"ddl": "-- 中文名: 服务区档口基础信息表\n-- 描述: 服务区档口基础信息表...\ncreate table public.bss_company (\n id varchar(32) not null -- 主键ID,\n ...\n);",
"md": "## bss_company(服务区档口基础信息表)\n...",
"table_info": {
"table_name": "bss_company",
"schema_name": "public",
"full_name": "public.bss_company",
"comment": "服务区档口基础信息表",
"field_count": 15,
"row_count": 1000,
"table_size": "256 kB"
},
"fields": [
{
"name": "id",
"type": "varchar",
"nullable": false,
"comment": "主键ID",
"is_primary_key": true,
"is_foreign_key": false,
"default_value": null,
"is_enum": false,
"enum_values": []
}
],
"generation_info": {
"business_context": "高速公路服务区管理系统",
"output_type": "both",
"has_llm_comments": true,
"database": "highway_db"
}
}
}
ods_*
、*_dim
、*fact*
ods_%
、%_dim
business_context
时,系统会调用LLM生成智能注释data_pipeline
模块,90%+代码复用率运行测试脚本:
python test_table_inspector_api.py
测试脚本包含:
business_context
时会调用LLM,响应时间较长*
通配符和 %
SQL语法,区分大小写// 获取表列表
const tables = await fetch('/api/v0/database/tables', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
db_connection: 'postgresql://user:pass@host:5432/db',
schema: 'public'
})
}).then(r => r.json());
// 获取表列表(使用模糊搜索)
const filteredTables = await fetch('/api/v0/database/tables', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
db_connection: 'postgresql://user:pass@host:5432/db',
schema: 'public,ods',
table_name_pattern: 'ods_*'
})
}).then(r => r.json());
// 获取表DDL
const ddl = await fetch('/api/v0/database/table/ddl', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
db_connection: 'postgresql://user:pass@host:5432/db',
table: 'public.users',
business_context: '用户管理系统',
type: 'both'
})
}).then(r => r.json());
import requests
# 获取表列表
response = requests.post('http://localhost:8084/api/v0/database/tables',
json={
'db_connection': 'postgresql://user:pass@host:5432/db',
'schema': 'public'
})
tables = response.json()
# 获取表列表(使用模糊搜索)
response = requests.post('http://localhost:8084/api/v0/database/tables',
json={
'db_connection': 'postgresql://user:pass@host:5432/db',
'schema': 'public,ods',
'table_name_pattern': 'ods_*'
})
ods_tables = response.json()
# 获取表DDL
response = requests.post('http://localhost:8084/api/v0/database/table/ddl',
json={
'db_connection': 'postgresql://user:pass@host:5432/db',
'table': 'public.users',
'business_context': '用户管理系统',
'type': 'ddl'
})
ddl = response.json()