> ## Documentation Index
> Fetch the complete documentation index at: https://docs.memorylake.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 获取数据源

> 通过 ID 或自定义 ID 获取数据源及其构建状态

```
GET /openapi/memorylake/api/v3/workspaces/{workspaceId}/db-datasources/{datasourceId}
```

获取数据源，包括它覆盖的 schema 和索引的状态。如需用创建时设置的 `custom_id` 查找，请把 `by_custom_id` 设为 `true`，并把自定义 ID 作为路径参数传入。

数据源没有 `status` 字段。索引的状态要从三个版本字段读取：

| 字段情况 | 含义 |
| - | - |
| `build_version` 为空 | 索引从未构建过。 |
| `building_version` 非空 | 正在构建。请持续轮询这个接口，直到 `building_version` 重新变为空，即表示构建结束。 |
| `data_version` 非空且与 `build_version` 不同 | 索引落后于数据。请重新[构建索引](https://docs.memorylake.cn/features/memorylake/api-reference/database/datasources/build-datasource-index.md)。 |

> [!NOTE]
>
> **所需权限：** `db_datasource:read`

### 路径参数

**workspaceId** `string` *required*

工作空间 ID

**datasourceId** `string` *required*

数据源 ID；当 `by_custom_id` 为 `true` 时为数据源的 `custom_id`

### 查询参数

**by\_custom\_id** `boolean` (default: false)

设为 `true` 时按 `custom_id` 而不是 ID 查找数据源

```bash By datasource ID theme={null}
curl -X GET 'https://app.memorylake.cn/openapi/memorylake/api/v3/workspaces/ws-8001856949ad4f6a5b6226f415ffa877/db-datasources/dbds-4b8e2f6a1c9d4e7b8a3f5c2d6e9b1a7c' \
  -H 'Authorization: Bearer sk_xxxxxx'
```

```bash By custom ID theme={null}
curl -X GET 'https://app.memorylake.cn/openapi/memorylake/api/v3/workspaces/ws-8001856949ad4f6a5b6226f415ffa877/db-datasources/sales-ds?by_custom_id=true' \
  -H 'Authorization: Bearer sk_xxxxxx'
```

### 响应

**data** `object`

**数据源对象**

**id** `string`

数据源标识符，请把它当作不透明字符串处理。

**name** `string`

显示名称

**description** `string`

自由格式的描述

**schemas** `array`

这个数据源覆盖的 schema。目前只包含一项，且不能修改。

**workspace\_id** `string`

这个数据源所属的工作空间

**db\_connection\_id** `string`

这个数据源读取数据所用的连接

**custom\_id** `string`

您为这个数据源设置的自定义标识符（如果设置过）

**table\_filter\_rule** `string`

正则表达式，决定 schema 中哪些数据表进入索引。`.*` 表示全部数据表。

**database\_count** `integer`

当前使用这个数据源的数据库记忆数量。大于零时不能删除该数据源。

**build\_version** `string`

最近一次构建完成的索引版本。首次构建完成之前为空。

**building\_version** `string`

正在构建的索引版本。没有构建在进行时为空。

**data\_version** `string`

数据版本，用于判断索引是否最新。当它非空且与 `build_version` 不同时，说明索引落后于数据，需要重新构建。

**created\_at** `string`

创建时间戳

**updated\_at** `string`

最后更新时间戳

```json Success (200) theme={null}
{
  "success": true,
  "data": {
    "id": "dbds-4b8e2f6a1c9d4e7b8a3f5c2d6e9b1a7c",
    "name": "Sales warehouse · sales",
    "description": "Orders and customers from the sales schema",
    "schemas": ["sales"],
    "workspace_id": "ws-8001856949ad4f6a5b6226f415ffa877",
    "db_connection_id": "dbconn-7c1e9a4b2d6f4a8e9b3c5d7f1a2b4c6d",
    "custom_id": "sales-ds",
    "table_filter_rule": ".*",
    "database_count": 1,
    "build_version": "20260921082748374",
    "building_version": "",
    "data_version": "",
    "created_at": "2026-09-18T07:42:43.299Z",
    "updated_at": "2026-09-21T08:27:57.501Z"
  }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.