数据源 API
$w.cloud.callDataSource
$w.cloud.callDataSource(params: ICallDataSourceParams): Promise<any>
功能描述
调用数据源,包括数据模型及 APIs
入参
params: ICallDataSourceParams
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
dataSourceName | string | 是 | 数据源标识 | |
methodName | string | 是 | 数据源方法标识 | |
params | object | 是 | 方法参数,根据方法实际入参填写 |
如果数据源是数据模型,因为其方法皆由平台提供,其可用的数据源方法(methodName)是:
- 新增:
wedaCreateV2
- 新增多条:
wedaBatchCreateV2
- 删除:
wedaDeleteV2
- 删除多条:
wedaBatchDeleteV2
- 更新:
wedaUpdateV2
- 更新多条:
wedaBatchUpdateV2
- 查询:
wedaGetItemV2
- 查询多条:
wedaGetRecordsV2
出参
根据数据源方法实际定义返回
示例
export default async function ({event, data}) {
try {
const data = await $w.cloud.callDataSource({
dataSourceName: "sjmx_ftf41oj",
methodName: "wedaGetRecordsV2",
params: {
// 返回字段选择
select: {
$master: true, // 常见的配置,返回主表
},
// 返回total字段
getCount: true,
},
});
console.log("请求结果", data); // "{"records":[{"owner":"1559148626461061122","createdAt":1690378222467,"createBy":"1559148626461061122","updateBy":"1559148626461061122","name":"foo","_id":"f8f6930864c11fee007010104a2589c4","email":"bar@weda.io","updatedAt":1690378222467},{"owner":"1559148626461061122","createdAt":1690382002594,"createBy":"1559148626461061122","updateBy":"1559148626461061122","name":"juli","_id":"f95d024c64c12eb2006fd51d38654e28","email":"juli@weda.io","updatedAt":1690382002594}],"total":2}"
} catch (e) {
console.log("错误代码", e.code, "错误信息", e.message);
}
}