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 a structured, simplified, and logical approach. It has the following characteristics.
- Abstracts general queries for general databases such as Mysql or Flexdb.
- Abstracts common associations.
- 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, fill in according to the actual input parameters of the method. |
fetchOption | object | None | No | Options |
Use Developer Identity (Super Administrator Role)
Some fields can only be modified and created by the developer identity. Additionally, the developer identity is required in certain query scenarios.
Example:
const res = await context.callModel({
dataSourceName: 'demo',
methodName: 'wedaGetItemV2',
params: {},
fetchOption: {useAdmin: true}
})
⚠️ Important Notes
- Security Risks
- Note the security risks here. Using the developer identity allows querying all data, and this option is actively set by the developer. Developers should be aware of the security risks here. The security risks introduced thereby do not belong to the platform's security risks.
- Permissions
- The developer identity is equivalent to the Super Administrator role.
methodName: List of Supported Methods
- Add:
wedaCreateV2
- Add batch:
wedaBatchCreateV2
- Delete:
wedaDeleteV2
- Delete batch:
wedaBatchDeleteV2
- Update:
wedaUpdateV2
- Update batch:
wedaBatchUpdateV2
- Get:
wedaGetItemV2
- Get batch:
wedaGetRecordsV2
params: Parameters Supported by the Corresponding Method
Example Model
Student Model
Teacher Model
Course Selection Model
Create
Parameter Description
Create Single Record
Input Parameter Structure
Property | Type | Default Value | Example | Required | Description |
---|---|---|---|---|---|
data | { [key: string]: any; } | None | {name: "demo"} | Yes | Corresponds to the field structure of the data source |
Output Parameter Structure
Property | Type | Default Value | Example | Required | Description |
---|---|---|---|---|---|
id | string | None | "7L5G32U9PE" | Yes | id is the identifier corresponding to the created data source record |
string | None | "7L5G32U9PE" | Yes | Id is the identifier corresponding to the 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, passing an empty object will be ignored |
Output Parameter Structure
Property | Type | Default Value | Example | Description |
---|---|---|---|---|
idList | idList: string[] | None | ["7L5G32U9PE"] | idList is the list of identifiers corresponding to the created data source records |
IdList: string[] | None | ["7L5G32U9PE"] | IdList is the list of identifiers corresponding to the created data source records (to be deprecated) |
⚠️ Important Notes
- Permissions
- System fields can only be modified when the user has developer identity (i.e., super administrator role).
- Filtering
- When passing fields not defined in the model, they will be filtered out.
- Data Validation
- Type validation is performed on the incoming data. If validation fails, please check the type value of the corresponding field.
Example
Create Single Record
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
name:"foo",
age:10
},
}, // 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",
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
name:"foo",
age:10
},
}, // 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 intentionally used as an example and will not be mentioned again.
async ({ params }) => {
const data = await $w.cloud.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
name:"foo",
age:10
},
}, // 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: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaBatchCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:[{
name:"foo",
age:2
},{
name:"bar",
age:10
}
],
}, // 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"],
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: "student", // Data model identifier
methodName: "wedaBatchCreateV2",
params: {
data:[{
name:"foo",
age:2
},{
name:"bar",
age:10
}
],
}, // 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: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view 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",
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'post', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view 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: 'teacher', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view 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",
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'teacher', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view 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: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view 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",
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaCreateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view 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
}
}
Update
- Note: Updates are incremental. If no value is passed in for a field to be updated, the field will not be modified. If null is passed in, the field will be updated to null.
- Limitation: A batch update can modify up to 200 records 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 | Corresponds to the field structure of the data source |
filter | { where: FilterObject} | None | {filter: {where: {_id:{$eq:"foo"}}}} | Yes | Complex query structure |
FilterObject
is a complex query structure. Please refer to the query parameter documentation.This method is for single-record updates. If a filter condition matches multiple records, 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 updated records. A non-zero value indicates a successful update. |
Count: 0 or 1 | None | 1 | Number of updated records. A non-zero value indicates a successful update. (To be deprecated ) |
Update Multiple
Input Parameter Structure
Property | Type | Default Value | Example | Required | Description |
---|---|---|---|---|---|
data | { [key: string]: any; } | None | {name: "juli"} | Yes | Corresponds to the field structure of the data source |
filter | { where: FilterObject} | None | {filter: {where: {}}} | Yes | Complex query structure |
FilterObject is a complex query structure. Please refer to the query parameter documentation.
Batch update can only update up to 200 records at a time.
Output Parameter Structure
Property | Type | Default Value | Example | Description |
---|---|---|---|---|
count | count: 0 or 1 | None | 1 | Number of updated records. A non-zero value indicates a successful update. |
Count: 0 or 1 | None | 1 | Number of updated records. A non-zero value indicates a successful update (To be deprecated ) |
Example
Update Single Record
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
name:"foo",
age:12
},
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
name:"foo",
age:12
},
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Parameters for the data model method
});
console.log("Request result", data);
return data;
}
View results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Update Multiple
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaBatchUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
name:"foo",
age:12
},
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaBatchUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
name:"foo",
age:12
},
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // Parameters for the data model method
});
console.log("Request result", data);
return data;
}
View results
{
"count": 2,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Update Association for a Single Data Record (Many-to-One)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
teacher_id:{_id:"BERMV99BBN"},
},
filter:{
where:{
name:{$eq:"foo"}
}
}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
teacher_id:{_id:"BERMV99BBN"},
},
filter:{
where:{
name:{$eq:"foo"}
}
}
}, // 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 of a Single Data Record (One-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'teacher', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
student_list:[{_id:"BERN1Y59JG"}, {_id:"BERN0LHV2Y"}],
},
filter:{
where:{
name:{$eq:"zhang"}
}
}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'teacher', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
student_list:[{_id:"BERN1Y59JG"}, {_id:"BERN0LHV2Y"}],
},
filter:{
where:{
name:{$eq:"zhang"}
}
}
}, // 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 of a Single Data Record (One-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'teacher', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
student_list:[],
},
filter:{
where:{
name:{$eq:"zhang"}
}
}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'teacher', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
student_list:[],
},
filter:{
where:{
name:{$eq:"zhang"}
}
}
}, // Parameters for the data model method
});
console.log("Request result", data);
return data;
}
View results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Update Association for a Single Data Record (Many-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
course_id_list:[{_id:"BERN1Y59JG"}, {_id:"BERN0LHV2Y"}],
},
filter:{
where:{
name:{$eq:"Student Zhang"}
}
}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
course_id_list:[{_id:"BERN1Y59JG"}, {_id:"BERN0LHV2Y"}],
},
filter:{
where:{
name:{$eq:"Student Zhang"}
}
}
}, // 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 of a Single Data Record (Many-to-Many)
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
course_id_list:[],
},
filter:{
where:{
name:{$eq:"Student Zhang"}
}
}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaUpdateV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
data:{
course_id_list:[],
},
filter:{
where:{
name:{$eq:"Student Zhang"}
}
}
}, // Parameters for the data model method
});
console.log("Request result", data);
return data;
}
View results
{
"count": 1,
"profile": {
"requestTimeCost": 694,
"trrigerTimeCost": 694,
"resolveParamsTimecost": 0
}
}
Deleting
- Limitation: A batch deletion can delete up to 200 records at a time.
Parameter Description
Delete Single
Input Parameter Structure
Property | Type | Default Value | Example | Required | Description |
---|---|---|---|---|---|
filter | { where: FilterObject} | None | {filter: {where: {_id:{$eq:"foo"}}}} | Yes | Complex query structure |
FilterObject
is a complex query structure. Please refer to the query parameter documentation.This method is for single-record deletion. If a filter condition matches multiple records, this method cannot be used.
Output Parameter Structure
Property | Type | Default Value | Example | Description |
---|---|---|---|---|
count | count: 0 or 1 | None | 1 | Number of updated records. A non-zero value indicates a successful update. |
Count: 0 or 1 | None | 1 | Number of updated records. A non-zero value indicates a successful update. (To be deprecated ) |
Delete Multiple
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 documentation.
Batch update can only update up to 200 records at a time.
Output Parameter Structure
Property | Type | Default Value | Example | Description |
---|---|---|---|---|
count | count: 0 or 1 | None | 1 | Number of updated records. A non-zero value indicates a successful update. |
Count: 0 or 1 | None | 1 | Number of updated records. A non-zero value indicates a successful update (To be deprecated ) |
Example
Delete Single
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaDeleteV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaDeleteV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // 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
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaBatchDeleteV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaBatchDeleteV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
filter:{
where:{
name:{$eq:"luke"}
}
}
}, // 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
- Limitation: A maximum of 200 data records can be queried in a single query.
Parameter Description
Single Record Query
Input Parameter Structure
Property | Type | Default Value | Example | Required | Description |
---|---|---|---|---|---|
filter | { where: FilterObject} | None | {filter: {where: {}}} | Required | Complex query structure |
select | { [key: string]: boolean } | None | { $master: true } | Required | Specifies the fields to return from the main table or related tables. To query all fields of the main table, use { $master: true } |
compatibleWithV1 | boolean | false | Optional | Backward compatibility for legacy relationships, detailed below | |
relateWhere | None | Optional | Supports querying associated tables in the data model |
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 |
Batch Query
Property | Type | Default Value | Required | Description |
---|---|---|---|---|
filter | { where: FilterObject} | None | Yes | Complex query structure |
select | { [key: string]: boolean } | None | Required | { $master: true } Specifies the fields to return from the main table or related tables. To query all fields of the main table, use { $master: true } |
getCount | boolean | false | No | Get the count of records matching the filter conditions |
getRecords | boolean | true | No | Whether to fetch data |
pageSize | number | 10 | No | Page size. It is recommended to specify this value. To set a different value, it must be used in conjunction with pageNumber. Both parameters must be specified to take effect. |
pageNumber | number | 1 | No | Page number |
orderBy | `{[key: string]: "asc" | "desc" }[]` | None | No |
compatibleWithV1 | boolean | false | No | Backward compatibility for legacy relationships, detailed below |
relateWhere | None | No | Supports querying associated tables in the data model | |
limit | number | None | No | Limits the number of returned records. If used together with pageSize, the limit parameter takes precedence. |
offset | offset | None | No | Specifies the offset for returned records. If used with pageNumber, offset takes precedence. Note: limit must be used with offset, and pageSize must be used with pageNumber. The two pagination methods 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 objects from the data source. |
total | number | None | 3 | If getCount is set to true in the input, returns the total count of records matching the filter conditions. Note: this value is not the length of the returned records array; it can be used for pagination. When getCount is false , this value is not reliable and should not be used. |
⚠️ Important Notes
Pagination query parameters cannot exceed 200 records per request
- This method does not support full data queries. If you need to query all data, use pagination.
Permissions
- This method is within the scope of permission controls. Please note the identity used for queries.
Example
Single Record Query
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaGetItemV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
select : {$master : true}
}, // 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,
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaGetItemV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
select : {$master : true}
}, // 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
}
}
Batch Query
APIs Example
module.exports = async function (params, context) {
const result = await context.callModel({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaGetRecordsV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
select : {
"$master" : true
},
getCount : true,
pageSize : 10,
pageNumber : 1
}, // 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,
},
],
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaGetRecordsV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
select : {
"$master" : true
},
getCount : true,
pageSize : 10,
pageNumber : 1
}, // 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: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaGetRecordsV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
select : {
"$master" : true
},
orderBy :[{age:"asc"}],
getCount : true,
pageSize : 10,
pageNumber : 1
}, // 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,
}
],
}
Visualization Development Editor Example
Request
async ({ params }) => {
const data = await $w.cloud.callDataSource({
dataSourceName: 'student', // Data model identifier, which can be viewed on the "Data Source - Data Model" list page
methodName: 'wedaGetRecordsV2', // Data model method identifier. For supported methods, navigate to the details page of any data model under "Data Source - Data Model" to view methods supported by the current model.
params: {
select : {
"$master" : true
},
orderBy :[{age:"asc"}],
getCount : true,
pageSize : 10,
pageNumber : 1
}, // 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 Association
[How to use association relationships](/en/lowcode/api/model_relation#Query Association)
Use Complex Queries
[How to use complex queries](/en/lowcode/api/model_queries#Use Complex Queries)