Data Model CRUD
[TOC]
What is a Data Model?
A data model transforms complex entities and relationships in the real world into computer-processable data representations through structured, simplified, and logical approaches. It has the following characteristics.
- Abstracts common database queries.
- Abstracts common relationships.
- Abstracts common complex entities.
Feature Description
Invoke Data Model Methods
- callModel (Recommended)
callDataSourceCompatible with callModel.
Parameter Description
| Parameter Name | Type | Default Value | Required | Description |
|---|---|---|---|---|
| name | string | None | Yes | Data source identifier |
| dataSourceName | string | None | Yes | Equivalent to name |
| methodName | string | None | Yes | Data source method name |
| params | object | None | Yes | Method parameters, to be filled according to the actual input parameters of the method. |
| fetchOption | object | None | No | Options |
Using Developer Identity (Super Administrator Role)
Certain fields can only be modified and created using a developer identity. Additionally, a developer identity is required for some query scenarios.
Example:
const res = await context.callModel({
dataSourceName: 'demo',
methodName: 'wedaGetItemV2',
params: {},
fetchOption: {useAdmin: true}
})
⚠️ Important Notes
- Security Risks
- Please note the security risks here. Using a developer identity allows access to all data, and this option is actively set by developers. Developers should be aware of the security risks involved. Security risks introduced thereby do not constitute platform security risks.
- Permissions
- A developer identity is equivalent to a Super Administrator Role.
methodName: Supported Methods
- New:
wedaCreateV2 - New Batch:
wedaBatchCreateV2 - Delete:
wedaDeleteV2 - Batch Delete:
wedaBatchDeleteV2 - Update:
wedaUpdateV2 - Batch Update:
wedaBatchUpdateV2 - Query:
wedaGetItemV2 - Batch Query:
wedaGetRecordsV2
params: Supported Parameters
Example Model
student model

teacher model

course selection model

Creating
Parameter Description
Create Single Record
Input Parameter Structure
| Property | Type | Default Value | Example | Required | Description |
|---|---|---|---|---|---|
| data | { [key: string]: any; } | None | {name: "demo"} | Yes | Corresponding data source field structure |
Output Parameter Structure
| Property | Type | Default Value | Example | Required | Description |
|---|---|---|---|---|---|
| id | string | None | "7L5G32U9PE" | Yes | id is the identifier for the corresponding created data source record |
string | None | "7L5G32U9PE" | Yes | Id is the identifier for the corresponding created data source record (to be deprecated) |
Create Multiple Records
Input Parameter Structure
| Property | Type | Default Value | Example | Required | Description |
|---|---|---|---|---|---|
| data | { [key: string]: any }[] | None | [{name: "juli"}] | Yes | Cannot be an empty array; empty objects passed will be ignored |
Output Parameter Structure
| Property | Type | Default Value | Example | Description |
|---|---|---|---|---|
| idList | idList: string[] | None | ["7L5G32U9PE"] | idList is the identifier list for the corresponding created data source records |
IdList: string[] | None | ["7L5G32U9PE"] | IdList is the identifier list for the corresponding created data source records (to be deprecated) |
⚠️ Important Notes
- Permissions
- Only a developer identity (i.e., super administrator role) can modify system fields.
- Filtering
- Fields not defined in the model will be filtered out.
- Data Validation
- Type validation will be performed on the incoming data. If a validation error occurs, check the corresponding field type value.
Example
Create Single Record
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:{
name:"foo",
age:10
},
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"id":"BH4Q75GUTA",
"Id":"BH4Q75GUTA",
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:{
name:"foo",
age:10
},
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"id": "BH47EEU864",
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Here, callDataSource and callModel are equivalent. This is specifically mentioned as an example and will not be referenced again.
async ({ params }) => {
const data = await $w.cloud.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:{
name:"foo",
age:10
},
}, // Input parameters for the data model method
});
console.log("Request result", data); return data; }
### Create Multiple Records
#### APIs Example
```javascript
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaBatchCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:[{
name:"foo",
age:2
},{
name:"bar",
age:10
}
],
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"idList":["BH4QX0UYM6","BH4QX0UYM7"],
"IdList":["BH4QX0UYM6","BH4QX0UYM7"],
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: "student", // Data model identifier
methodName: "wedaBatchCreateV2",
params: {
data:[{
name:"foo",
age:2
},{
name:"bar",
age:10
}
],
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"idList": [
"BH4R1XV17N",
"BH4R1XV17P"
],
"profile": {
"requestTimeCost": 475,
"trrigerTimeCost": 475,
"resolveParamsTimecost": 0
}
}
Create a Data Record and Associate (Many-to-One)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:{
name:"lee",
age:20,
teacher_id:{"_id":"BH4R1XV17P"},
}
}
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"id":"BH4TH0G9EY",
"Id":"BH4TH0G9EY",
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'post', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:{
name:"lee",
age:20,
teacher_id:{"_id":"BH4R1XV17P"},
}
}
});
console.log("Request result", data);
return data;
}
View Results
{
"id": "BH47EEU864",
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Create a Data Record and Associate (One-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'teacher', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:{
name:"Teacher Zhang",
isMaster:true,
student_list:[{"_id":"BERN1Y59JG"}, {"_id":"BERN0LHV2Y"}],
}
}
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"id":"BH4U9NHXGU",
"Id":"BH4U9NHXGU",
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'teacher', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:{
name:"Teacher Zhang",
isMaster:true,
student_list:[{"_id":"BERN1Y59JG"}, {"_id":"BERN0LHV2Y"}],
}
}
});
console.log("Request result", data);
return data;
}
View Results
{
"id": "BH4U9NHXGU",
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Create a Data Record and Associate (Many-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:{
name:"Student Zhang",
age:18,
course_id_list:[{"_id":"BH4BK0G1U4"}, {"_id":"BH4BGT241E"}],
}
}
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"id":"BH4UMKTNM6",
"Id":"BH4UMKTNM6",
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaCreateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under 'Data Source - Data Model' to see the methods supported by the current model.
params: {
data:{
name:"Student Zhang",
age:18,
course_id_list:[{"_id":"BH4BK0G1U4"}, {"_id":"BH4BGT241E"}],
}
}
});
console.log("Request result", data);
return data;
}
View Results
{
"id": "BH4UMKTNM6",
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Modify
- Note: Modification is an incremental update. If the value of the field to be modified is not passed in, it will not be updated. If null is passed in, it will be updated to null.
- Limitation: Batch modification allows modifying up to 200 data entries at a time.
Parameter Description
Update Single Record
Input Parameter Structure
| Property | Type | Default Value | Example | Required | Description |
|---|---|---|---|---|---|
| data | { [key: string]: any; } | None | {name: "juli"} | Yes | Corresponding data source field structure |
| filter | { where: FilterObject} | None | {filter: {where: {_id:{$eq:"foo"}}}} | Yes | Complex query structure |
FilterObjectis a complex query structure. Please refer to the query parameter description.This method is for single-record updates. If a filter condition is used and multiple records are retrieved, this method cannot be used for updating.
Output Parameter Structure
| Property | Type | Default Value | Example | Description |
|---|---|---|---|---|
| count | count: 0 or 1 | None | 1 | Number of changed records. A non-zero value indicates successful update. |
Count: 0 or 1 | None | 1 | Number of changed records. A non-zero value indicates successful update. (To be deprecated) |
Modify Multiple Records
Input Parameter Structure
| Property | Type | Default Value | Example | Required | Description |
|---|---|---|---|---|---|
| data | { [key: string]: any; } | None | {name: "juli"} | Yes | Corresponding data source field structure |
| filter | { where: FilterObject} | None | {filter: {where: {}}} | Yes | Complex query structure |
FilterObject is a complex query structure. Please refer to the query parameter description.
Batch update can update at most 200 records per operation.
Output Parameter Structure
| Property | Type | Default Value | Example | Description |
|---|---|---|---|---|
| count | count: 0 or 1 | None | 1 | Number of changed records. A non-zero value indicates successful update. |
Count: 0 or 1 | None | 1 | Number of changed records. A non-zero value indicates successful update (To be deprecated) |
Example
Update Single Record
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
name:"foo",
age:12
},
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"count":1,
"Count":1,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
name:"foo",
age:12
},
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Modify Multiple Records
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaBatchUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
name:"foo",
age:12
},
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"count":2,
"Count":2,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaBatchUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
name:"foo",
age:12
},
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"count": 2,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Modify the Association Relationship of a Single Data Record (Many-to-One)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
teacher_id:{_id:"BERMV99BBN"},
},
filter:{
where:{
name:{$eq:"foo"}
}
}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"count":1,
"Count":1,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
teacher_id:{_id:"BERMV99BBN"},
},
filter:{
where:{
name:{$eq:"foo"}
}
}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Modify the Association Relationship of a Single Data Record (One-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'teacher', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
student_list:[{_id:"BERN1Y59JG"}, {_id:"BERN0LHV2Y"}],
},
filter:{
where:{
name:{$eq:"zhang"}
}
}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"count":1,
"Count":1,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'teacher', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
student_list:[{_id:"BERN1Y59JG"}, {_id:"BERN0LHV2Y"}],
},
filter:{
where:{
name:{$eq:"zhang"}
}
}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Clear the Association Relationship of a Single Data Record (One-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'teacher', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
student_list:[],
},
filter:{
where:{
name:{$eq:"zhang"}
}
}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"count":1,
"Count":1,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'teacher', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
student_list:[],
},
filter:{
where:{
name:{$eq:"zhang"}
}
}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Modification of the Association Relationship for a Single Data Record (Many-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
course_id_list:[{_id:"BERN1Y59JG"}, {_id:"BERN0LHV2Y"}],
},
filter:{
where:{
name:{$eq:"Student Zhang"}
}
}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"count":1,
"Count":1,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
course_id_list:[{_id:"BERN1Y59JG"}, {_id:"BERN0LHV2Y"}],
},
filter:{
where:{
name:{$eq:"Student Zhang"}
}
}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Clear the Association Relationship of a Single Data Record (Many-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
course_id_list:[],
},
filter:{
where:{
name:{$eq:"Student Zhang"}
}
}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"count":1,
"Count":1,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaUpdateV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
data:{
course_id_list:[],
},
filter:{
where:{
name:{$eq:"Student Zhang"}
}
}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Delete
- Limitation: Batch deletion allows deleting up to 200 data entries at a time.
Parameter Description
Delete Single Record
Input Parameter Structure
| Property | Type | Default Value | Example | Required | Description |
|---|---|---|---|---|---|
| filter | { where: FilterObject} | None | {filter: {where: {_id:{$eq:"foo"}}}} | Yes | Complex query structure |
FilterObjectis a complex query structure. Please refer to the query parameter description.This method is for single-record deletion. If a filter condition is used and multiple records are retrieved, this method cannot be used for deletion.
Output Parameter Structure
| Property | Type | Default Value | Example | Description |
|---|---|---|---|---|
| count | count: 0 or 1 | None | 1 | Number of changed records. A non-zero value indicates successful update. |
Count: 0 or 1 | None | 1 | Number of changed records. A non-zero value indicates successful update. (To be deprecated) |
Delete Multiple Records
Input Parameter Structure
| Property | Type | Default Value | Example | Required | Description |
|---|---|---|---|---|---|
| filter | { where: FilterObject} | None | {filter: {where: {}}} | Yes | Complex query structure |
FilterObject is a complex query structure. Please refer to the query parameter description.
Batch update can update at most 200 records per operation.
Output Parameter Structure
| Property | Type | Default Value | Example | Description |
|---|---|---|---|---|
| count | count: 0 or 1 | None | 1 | Number of changed records. A non-zero value indicates successful update. |
Count: 0 or 1 | None | 1 | Number of changed records. A non-zero value indicates successful update (To be deprecated) |
Example
Delete Single Record
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaDeleteV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"count":1,
"Count":1,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaDeleteV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Delete Multiple Records
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaBatchDeleteV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"count":2,
"Count":2,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaBatchDeleteV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"count": 2,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Query
- Limitations: A single query can retrieve up to 200 data records.
Parameter Description
Query Single Record
Input Parameter Structure
| Property | Type | Default Value | Example | Required | Description |
|---|---|---|---|---|---|
| filter | { where: FilterObject} | None | {filter: {where: {}}} | Yes | Complex query structure |
| select | { [key: string]: boolean } | None | { $master: true } | Yes | Specifies fields to return from the current table or related tables. To query all fields of the current table, use { $master: true } |
| compatibleWithV1 | boolean | false | No | Compatibility with legacy relationships, detailed below | |
| relateWhere | None | No | Supports querying related tables for data models |
Output Parameter Structure
| Property | Type | Default Value | Example | Description |
|---|---|---|---|---|
| Corresponding Data Source Field Structure | { [key: string]: any } | None | { name: "juli" } | Returns details of the data source that meet the filter conditions |
Query Multiple Records
| Property | Type | Default Value | Required | Description |
|---|---|---|---|---|
| filter | { where: FilterObject} | None | Yes | Complex query structure |
| select | { [key: string]: boolean } | None | Yes | { $master: true } Specifies fields to return from the current table or related tables. To query all fields of the current table, use { $master: true } |
| getCount | boolean | false | No | Obtains the query count of filter matching conditions |
| getRecords | boolean | true | No | Whether to obtain data |
| pageSize | number | 10 | No | Page size. It is recommended to specify. To set other values, it must be used together with pageNumber, and both must be specified to take effect. |
| pageNumber | number | 1 | No | Page number |
| orderBy | {[key: string]: "asc" "desc" }[] | None | No | Sorting. Currently supports sorting by up to 3 fields |
| compatibleWithV1 | boolean | false | No | Compatibility with legacy relationships, detailed below |
| relateWhere | None | No | supports querying associated tables for data models | |
| limit | number | None | No | Limits the number of returned records. If used together with pageSize, limit takes precedence |
| offset | offset | None | No | Specifies the offset for returned records. If used together with pageNumber, offset takes precedence. Note: limit must be used with offset; pageSize must be used with pageNumber. These cannot be mixed. |
Output Parameter Structure
| Property | Type | Default Value | Example | Description |
|---|---|---|---|---|
records | { [key: string]: any }[] | None | { name: "juli" } | The array in records contains the corresponding data source data objects |
total | number | None | 3 | When getCount is set to true in input parameters, this returns the size of the result set matching the query conditions. Note: This field does not represent the length of returned records; it can be used for pagination calculations. When getCount is false, you should not rely on this value. |
⚠️ Important Notes
The pagination query parameters cannot exceed 200 at a time
- This method does not support full data set queries. If you need to query the full data set, use pagination.
Permissions
- This method falls within the scope of access control. Please ensure the identity used for queries.
Example
Query Single Record
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaGetItemV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
select : {$master : true}
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"owner":"1871099876542291970",
"createdAt":1748340164367,
"createBy":"1871099876542291970",
"updateBy":"1871099876542291970",
"_openid":"1871099876542291970",
"name":"Student Zhang",
"_id":"BH4UMKTNM6",
"age":18,
"updatedAt":1748340164367,
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaGetItemV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
select : {$master : true}
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"owner": "1871099876542291970",
"createdAt": 1748340164367,
"createBy": "1871099876542291970",
"updateBy": "1871099876542291970",
"_openid": "1871099876542291970",
"name": "Student Zhang",
"_id": "BH4UMKTNM6",
"age": 18,
"updatedAt": 1748340164367,
"profile": {
"requestTimeCost": 547,
"trrigerTimeCost": 548,
"resolveParamsTimecost": 1
}
}
Query Multiple Records
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaGetRecordsV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
select : {
"$master" : true
},
getCount : true,
pageSize : 10,
pageNumber : 1
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"total":3,
"records":[
{
"owner":"1871099876542291970",
"createdAt":1748340164367,
"createBy":"1871099876542291970",
"updateBy":"1871099876542291970",
"_openid":"1871099876542291970",
"name":"Student Zhang",
"_id":"BH4UMKTNM6",
"age":18,
"updatedAt":1748340164367,
},
{
"owner":"1871099876542291970",
"createdAt":1747299013876,
"createBy":"1871099876542291970",
"updateBy":"1871099876542291970",
"_openid":"1871099876542291970",
"name":"zhang2",
"_id":"BERN1Y59JG",
"age":33,
"updatedAt":1747299013876,
},
{
"owner":"1871099876542291970",
"createdAt":1747298998990,
"createBy":"1871099876542291970",
"updateBy":"1871099876542291970",
"_openid":"1871099876542291970",
"name":"foo",
"_id":"BERN0LHV2Y",
"age":12,
"updatedAt":1748340983535,
},
],
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaGetRecordsV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
select : {
"$master" : true
},
getCount : true,
pageSize : 10,
pageNumber : 1
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"records": [
{
"owner": "1871099876542291970",
"createdAt": 1748340164367,
"createBy": "1871099876542291970",
"updateBy": "1871099876542291970",
"_openid": "1871099876542291970",
"name": "Student Zhang",
"_id": "BH4UMKTNM6",
"age": 18,
"updatedAt": 1748340164367
},
{
"owner": "1871099876542291970",
"createdAt": 1747299013876,
"createBy": "1871099876542291970",
"updateBy": "1871099876542291970",
"_openid": "1871099876542291970",
"name": "zhang2",
"_id": "BERN1Y59JG",
"age": 33,
"updatedAt": 1747299013876
},
{
"owner": "1871099876542291970",
"createdAt": 1747298998990,
"createBy": "1871099876542291970",
"updateBy": "1871099876542291970",
"_openid": "1871099876542291970",
"name": "foo",
"_id": "BERN0LHV2Y",
"age": 12,
"updatedAt": 1748340983535
}
],
"total": 3,
"profile": {
"requestTimeCost": 367,
"trrigerTimeCost": 368,
"resolveParamsTimecost": 1
}
}
Query Multiple Records - Using Sorting
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaGetRecordsV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
select : {
"$master" : true
},
orderBy :[{age:"asc"}],
getCount : true,
pageSize : 10,
pageNumber : 1
}, // Input parameters for the data model method
});
// Return the result of this method here, which must map to the structure defined in the output parameters
return result;
};
View Results
{
"total":3,
"records":[
{
"owner":"1871099876542291970",
"createdAt":1747298998990,
"createBy":"1871099876542291970",
"updateBy":"1871099876542291970",
"_openid":"1871099876542291970",
"name":"foo",
"_id":"BERN0LHV2Y",
"age":12,
"updatedAt":1748340983535,
},
{
"owner":"1871099876542291970",
"createdAt":1748340164367,
"createBy":"1871099876542291970",
"updateBy":"1871099876542291970",
"_openid":"1871099876542291970",
"name":"Student Zhang",
"_id":"BH4UMKTNM6",
"age":18,
"updatedAt":1748340164367,
},
{
"owner":"1871099876542291970",
"createdAt":1747299013876,
"createBy":"1871099876542291970",
"updateBy":"1871099876542291970",
"_openid":"1871099876542291970",
"name":"zhang2",
"_id":"BERN1Y59JG",
"age":33,
"updatedAt":1747299013876,
}
],
}
Visual Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: dataSourceName: 'student', // Data model identifier. Navigate to the Data Source - Data Model list page to view.
methodName: methodName: 'wedaGetRecordsV2', // Data model method identifier. Supported methods can be viewed on the details page of any data model under "Data Source - Data Model" to see the methods supported by the current model.
params: {
select : {
"$master" : true
},
orderBy :[{age:"asc"}],
getCount : true,
pageSize : 10,
pageNumber : 1
}, // Input parameters for the data model method
});
console.log("Request result", data);
return data;
}
View Results
{
"records": [
{
"owner": "1871099876542291970",
"createdAt": 1747298998990,
"createBy": "1871099876542291970",
"updateBy": "1871099876542291970",
"_openid": "1871099876542291970",
"name": "foo",
"_id": "BERN0LHV2Y",
"age": 12,
"updatedAt": 1748340983535
},
{
"owner": "1871099876542291970",
"createdAt": 1748340164367,
"createBy": "1871099876542291970",
"updateBy": "1871099876542291970",
"_openid": "1871099876542291970",
"name": "Student Zhang",
"_id": "BH4UMKTNM6",
"age": 18,
"updatedAt": 1748340164367
},
{
"owner": "1871099876542291970",
"createdAt": 1747299013876,
"createBy": "1871099876542291970",
"updateBy": "1871099876542291970",
"_openid": "1871099876542291970",
"name": "zhang2",
"_id": "BERN1Y59JG",
"age": 33,
"updatedAt": 1747299013876
}
],
"total": 3,
"profile": {
"requestTimeCost": 367,
"trrigerTimeCost": 368,
"resolveParamsTimecost": 1
}
}