Skip to main content

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.

  1. Abstracts common database queries.
  2. Abstracts common relationships.
  3. Abstracts common complex entities.

Learn about Data Models

Feature Description

Invoke Data Model Methods

  1. callModel (Recommended)
  2. callDataSource Compatible with callModel.

Parameter Description

Parameter NameTypeDefault ValueRequiredDescription
namestringNoneYesData source identifier
dataSourceNamestringNoneYesEquivalent to name
methodNamestringNoneYesData source method name
paramsobjectNoneYesMethod parameters, to be filled according to the actual input parameters of the method.
fetchOptionobjectNoneNoOptions

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

  1. 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.
  2. 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 student

teacher model teacher

course selection model course

Creating

Parameter Description

Create Single Record

Input Parameter Structure

PropertyTypeDefault ValueExampleRequiredDescription
data{ [key: string]: any; }None{name: "demo"}YesCorresponding data source field structure

Output Parameter Structure

PropertyTypeDefault ValueExampleRequiredDescription
idstring None"7L5G32U9PE"Yesid is the identifier for the corresponding created data source record
Idstring None"7L5G32U9PE"YesId is the identifier for the corresponding created data source record (to be deprecated)

Create Multiple Records

Input Parameter Structure

PropertyTypeDefault ValueExampleRequiredDescription
data{ [key: string]: any }[]None[{name: "juli"}]YesCannot be an empty array; empty objects passed will be ignored

Output Parameter Structure

PropertyTypeDefault ValueExampleDescription
idListidList: string[]None["7L5G32U9PE"]idList is the identifier list for the corresponding created data source records
IdListIdList: string[]None["7L5G32U9PE"]IdList is the identifier list for the corresponding created data source records (to be deprecated)

⚠️ Important Notes

  1. Permissions
    • Only a developer identity (i.e., super administrator role) can modify system fields.
  2. Filtering
    • Fields not defined in the model will be filtered out.
  3. 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

PropertyTypeDefault ValueExampleRequiredDescription
data{ [key: string]: any; }None{name: "juli"}YesCorresponding data source field structure
filter{ where: FilterObject}None{filter: {where: {_id:{$eq:"foo"}}}}YesComplex query structure

FilterObject is 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

PropertyTypeDefault ValueExampleDescription
countcount: 0 or 1None1Number of changed records. A non-zero value indicates successful update.
CountCount: 0 or 1None1Number of changed records. A non-zero value indicates successful update. (To be deprecated)

Modify Multiple Records

Input Parameter Structure

PropertyTypeDefault ValueExampleRequiredDescription
data{ [key: string]: any; }None{name: "juli"}YesCorresponding data source field structure
filter{ where: FilterObject}None{filter: {where: {}}}YesComplex 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

PropertyTypeDefault ValueExampleDescription
countcount: 0 or 1None1Number of changed records. A non-zero value indicates successful update.
CountCount: 0 or 1None1Number 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

PropertyTypeDefault ValueExampleRequiredDescription
filter{ where: FilterObject}None{filter: {where: {_id:{$eq:"foo"}}}}YesComplex query structure

FilterObject is 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

PropertyTypeDefault ValueExampleDescription
countcount: 0 or 1None1Number of changed records. A non-zero value indicates successful update.
CountCount: 0 or 1None1Number of changed records. A non-zero value indicates successful update. (To be deprecated)

Delete Multiple Records

Input Parameter Structure

PropertyTypeDefault ValueExampleRequiredDescription
filter{ where: FilterObject}None{filter: {where: {}}}YesComplex 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

PropertyTypeDefault ValueExampleDescription
countcount: 0 or 1None1Number of changed records. A non-zero value indicates successful update.
CountCount: 0 or 1None1Number 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

PropertyTypeDefault ValueExampleRequiredDescription
filter{ where: FilterObject}None{filter: {where: {}}}YesComplex query structure
select{ [key: string]: boolean }None{ $master: true }YesSpecifies fields to return from the current table or related tables. To query all fields of the current table, use { $master: true }
compatibleWithV1booleanfalseNoCompatibility with legacy relationships, detailed below
relateWhereNoneNoSupports querying related tables for data models

Output Parameter Structure

PropertyTypeDefault ValueExampleDescription
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

PropertyTypeDefault ValueRequiredDescription
filter{ where: FilterObject}NoneYesComplex query structure
select{ [key: string]: boolean }NoneYes{ $master: true } Specifies fields to return from the current table or related tables. To query all fields of the current table, use { $master: true }
getCountbooleanfalseNoObtains the query count of filter matching conditions
getRecordsbooleantrueNoWhether to obtain data
pageSizenumber10NoPage 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.
pageNumbernumber1NoPage number
orderBy{[key: string]: "asc" "desc" }[]NoneNoSorting. Currently supports sorting by up to 3 fields
compatibleWithV1booleanfalseNoCompatibility with legacy relationships, detailed below
relateWhereNoneNosupports querying associated tables for data models
limitnumberNoneNoLimits the number of returned records. If used together with pageSize, limit takes precedence
offsetoffsetNoneNoSpecifies 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

PropertyTypeDefault ValueExampleDescription
records{ [key: string]: any }[]None{ name: "juli" }The array in records contains the corresponding data source data objects
totalnumberNone3When 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

  1. 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.
  2. 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
}
}

Query Relationships

How to Use Relationships

Use Complex Queries

How to Use Complex Queries