表和视图结构
返回指定表或视图的列、主键和索引。
POST /api/open/v1/metadata/getTable
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| dataSourceId | 整数 | 是 | 数据源 ID。 |
| namespacePath | 字符串数组 | 是 | 目标命名空间的完整路径,可通过 listNamespaces 获取。 |
| objectType | 字符串 | 是 | TABLE(表)、VIEW(视图)。 |
| tableName | 字符串 | 是 | 表名或视图名。 |
响应字段
| data 中的字段 | 类型 | 说明 |
|---|---|---|
| tableName | 字符串 | 表名或视图名。 |
| objectType | 字符串 | TABLE(表)、VIEW(视图)。 |
| columns | 对象数组 | 列定义。 |
| columns[].name | 字符串 | 列名。 |
| columns[].type | 字符串 | 数据库列类型。 |
| columns[].nullable | 布尔值 | 是否允许空值。 |
| primaryKey | 字符串数组 | 主键列名。 |
| indexes | 对象数组 | 索引列表。 |
| indexes[].name | 字符串 | 索引名称。 |
| indexes[].unique | 布尔值 | 是否为唯一索引。 |
| indexes[].columns | 字符串数组 | 索引列名。 |
请求示例(PostgreSQL)
{
"dataSourceId": 43,
"namespacePath": ["sales", "public"],
"objectType": "TABLE",
"tableName": "orders"
}
响应示例
{
"requestId": "a53d6ed5-2018-4c47-87b7-cc99c7369e5e",
"code": "OK",
"msg": "Request succeeded.",
"data": {
"tableName": "orders",
"objectType": "TABLE",
"columns": [
{"name": "id", "type": "bigint", "nullable": false},
{"name": "customer_id", "type": "bigint", "nullable": false}
],
"primaryKey": ["id"],
"indexes": [
{"name": "orders_customer_id_idx", "unique": false, "columns": ["customer_id"]}
]
}
}