import cloudbase from "@cloudbase/js-sdk";const app = cloudbase.init({env: "your-env-id", // 替换为您的环境id});const models = app.models;
models.modelName.get(options);
参数 | 类型 | 必填 | 说明 |
filter.where | object | 否 | 查询条件 |
select | object | 是 | 指定返回字段 |
// 查询 todo数据模型 _id 为 todo-id-123 的记录const todo = await models.todo.get({filter: {where: {_id: {$eq: "todo-id-123",},},},select: {$master: true, // 返回所有字段},});console.log("查询结果:", todo.data);
{data: {records: [{_id: "todo-id-123",title: "服务端任务",completed: false,// ... 其他字段}],total: 1}}
models.modelName.list(options);
参数 | 类型 | 必填 | 说明 |
filter.where | object | 否 | 查询条件 |
select | object | 是 | 指定返回字段 |
// 查询 todo数据模型 completed 为 false 的记录const todos = await models.todo.list({filter: {where: {completed: {$eq: false},},},});console.log("查询结果:", todos.data);
{data: {records: [{_id: "todo-id-1",title: "任务1",completed: false},{_id: "todo-id-2",title: "任务2",completed: false}],total: 2}}
文档反馈