关于 appdb
appdb 是面向 Domo App Platform 开发者的技能指南,说明如何通过 @domoinc/toolkit 的 AppDBClient 管理集合文档,并处理查询结果中的内容与元数据。
主要功能
- 01使用 AppDBClient 执行文档 CRUD
- 02按条件查询及批量更新
- 03从文档 content 解析应用字段
- 04在 manifest.json 声明集合
适用场景
- 01在 Domo 应用中创建和维护集合数据
- 02按状态或优先级筛选文档
- 03将查询结果整理为界面可用数据
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ stahura/ domo-ai-vibe-rules --skill appdb安装后在 Claude Code 中输入/appdb确认已加载。
详细介绍
规则:Domo App Platform AppDB(工具包优先)
本规则工具包优先。请使用 AppDBClient,而不是原始的 domo.get/post/put/delete 端点。
规范客户端
yarn add @domoinc/toolkit
import { AppDBClient } from '@domoinc/toolkit';
type Task = {
title: string;
status: 'active' | 'completed';
priority: 'Low' | 'High' | 'Urgent';
};
const tasksClient = new AppDBClient.DocumentsClient<Task>('TasksCollection');
核心操作
创建
const created = await tasksClient.create({
title: 'New Task',
status: 'active',
priority: 'High'
});
const task = created.body;
读取 / 查询
const all = await tasksClient.get();
const active = await tasksClient.get({ status: { $eq: 'active' } });
const highOpen = await tasksClient.get({
$and: [{ status: { $ne: 'completed' } }, { priority: { $in: ['High', 'Urgent'] } }]
});
AppDB 响应结构(关键)
由 .get() 返回的文档会带有元数据包装,你的字段位于 doc.content 内。
.create() 接受的格式:
{ vendor: 'Acme', riskLevel: 'High', notes: 'Late payments' }
.get() 返回的内容(结构):
[
{
"id": "04b1756e-7b6d-4d77-842f-7975a6474d8a",
"datastoreId": "a3b85171-...",
"collectionId": "ba194a7d-...",
"syncRequired": true,
"owner": 767612617,
"createdOn": "2026-03-22T02:22:42.030Z",
"updatedOn": "2026-03-22T02:22:42.030Z",
"updatedBy": 767612617,
"content": {
"vendor": "Acme",
"riskLevel": "High",
"notes": "Late payments"
}
}
]
要点:
- 你的应用字段嵌套在
doc.content内,而不是在顶层。 doc.id是用于.update()和.delete()的文档 ID。- 元数据字段(
datastoreId、collectionId、owner、createdOn等)位于顶层。 - 整体结果可能在
response.body中,或直接就是数组。
必需的解析模式:
const response = await tasksClient.get();
const rawDocs = response.body || response;
const docs = Array.isArray(rawDocs) ? rawDocs : [];
const parsed = docs.map((doc) => ({
id: doc.id,
...doc.content
}));
常见错误:
// WRONG: fields are inside content
const docs = response.body || response;
docs[0].vendor; // undefined
// CORRECT
docs[0].content.vendor; // "Acme"
更新
await tasksClient.update({
id: 'document-uuid',
content: { title: 'Updated', status: 'completed', priority: 'Low' }
});
await tasksClient.partialUpdate(
{ status: { $eq: 'active' } },
{ $set: { status: 'archived' } }
);
删除
await tasksClient.delete('document-uuid');
await tasksClient.delete(['uuid-1', 'uuid-2']);
Manifest 要求
集合仍必须存在于 manifest.json 的 collections 下。
{
"collections": [
{
"name": "TasksCollection",
"schema": {
"columns": [
{ "name": "title", "type": "STRING" },
{ "name": "status", "type": "STRING" }
]
}
}
]
}
检查清单
- manifest 中存在
collections映射 - 使用
AppDBClient.DocumentsClient进行 CRUD - 在 UI/使用前,已将
.get()的结果从doc.content中解包 - 正确使用查询/更新操作符(
$eq、$in、$set、$inc等) - UI 流程中包含错误处理和加载状态
评论
支持 Markdown