SDK Type Declaration
Interface
DataModelMethods\<T>
Model Operation Methods Interface Definition
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
Properties
create()
create: (
params
) =>Promise
\<MethodResponse
\<CreateResponse
\<T
>>>
Method for creating a single data record.
Example
models.<model_name>.create({
data: {
// Model field data
}
}).then(({ data }) => {
console.log(data.id); // Output the created data ID
});
Parameters
Parameter | Type | Description |
---|---|---|
params | object | Contains the parameter object for creating data. |
params.data | T | - |
params.envType ? | prod or pre | Operate on production data or staging data |
Response
Promise
\<MethodResponse
\<CreateResponse
\<T
>>>
createMany()
createMany: (
params
) =>Promise
\<MethodResponse
\<CreateManyResponse
\<T
>>>
Method for creating multiple data records.
Example
models.<model_name>.createMany({
data: [
// Model field data array
]
}).then(({ data }) => {
console.log(data.idList); // Output the created data ID list
});
Parameters
Parameter | Type | Description |
---|---|---|
params | object | Contains the parameter object for creating a data array. |
params.data | T [] | - |
params.envType ? | prod or pre | Operate on production data or staging data |
Response
Promise
\<MethodResponse
\<CreateManyResponse
\<T
>>>
delete()
delete: (
params
) =>Promise
\<MethodResponse
\<DeleteResponse
\<T
>>>
Method for deleting a single data record.
Example
models.<model_name>.delete({
filter: {
where: {
// Filter conditions, e.g., deleting specific records by ID
_id: {
$eq: "specific ID value"
}
}
}
}).then(({ data }) => {
console.log(data.count); // Output the number of deleted data records
});
Parameters
Parameter | Type | Description |
---|---|---|
params | object | Contains the parameter object with filter conditions. |
params.filter | FilterParams \<T > | - |
params.envType ? | prod or pre | Operate on production data or staging data |
Response
Promise
\<MethodResponse
\<DeleteResponse
\<T
>>>
deleteMany()
deleteMany: (
params
) =>Promise
\<MethodResponse
\<DeleteManyResponse
\<T
>>>
Method for deleting multiple data records.
Example
models.<model_name>.deleteMany({
filter: {
where: {
// Filter conditions, e.g., deleting all records that meet specific conditions
}
}
}).then(({ data }) => {
console.log(data.count); // Output the number of deleted data records
});
Parameters
Parameter | Type | Description |
---|---|---|
params | object | Contains the parameter object with filter conditions. |
params.filter | FilterParams \<T > | - |
params.envType ? | prod or pre | Operate on production data or staging data |
Response
Promise
\<MethodResponse
\<DeleteManyResponse
\<T
>>>
get()
get: (
params
) =>Promise
\<MethodResponse
\<T
>>
Method for retrieving a single data record.
Example
models.<model_name>.get({
filter: {
where: {
// Filter conditions
}
},
select: {
$master: true // selects all fields from the main table
}
}).then(({ data }) => {
console.log(data); // Output the queried data
});
Parameters
Parameter | Type | Description |
---|---|---|
params | object | Contains the parameter object with filter conditions and selected fields. |
params.filter | FilterParams \<T > | - |
params.select ? | SelectParams \<T > | - |
params.envType ? | prod or pre | Operate on production data or staging data |
Response
Promise
\<MethodResponse
\<T
>>
list()
list: (
params
) =>Promise
\<MethodResponse
\<object
>>
Method for retrieving multiple data records.
Example
models.<model_name>.list({
filter: {
where: {
// Filter conditions
}
},
select: {
$master: true // selects all fields from the main table
},
getCount: true, // Enable to get total count.
pageSize: 10, // Page size
pageNumber: 1, // Current page number
orderBy: [{ createdAt: 'desc' }] // Sorting parameters
}).then(({ data }) => {
console.log(data.records, data.total); // Output queried data records and total count
});
Parameters
Parameter | Type | Description |
---|---|---|
params | object | Contains the parameter object with filter conditions, selected fields, pagination options, and sorting options. |
params.filter ? | FilterParams \<T > | Filter conditions |
params.getCount ? | boolean | Whether to get the count of records matching the filter conditions |
params.orderBy ? | OrderByParams [] | Sorting parameters, currently supporting sorting by up to 3 fields. |
params.pageNumber ? | number | Page number |
params.pageSize ? | number | 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. |
params.select ? | SelectParams \<T > | Specifies the fields to return from the main table or related tables. To query all fields of the main table, use { $master: true } |
params.envType ? | prod or pre | Operate on production data or staging data |
Response
Promise
\<MethodResponse
\<object
>>
update()
update: (
params
) =>Promise
\<MethodResponse
\<UpdateResponse
\<T
>>>
Method for updating a single data record.
Example
models.<model_name>.update({
data: {
// Updated data fields
},
filter: {
where: {
// Filter conditions
}
}
}).then(({ data }) => {
console.log(data.count); // Number of updated data records
});
Parameters
Parameter | Type | Description |
---|---|---|
params | object | Contains the parameter object with update data and filter conditions. |
params.data | T | - |
params.filter | FilterParams \<T > | - |
params.envType ? | prod or pre | Operate on production data or staging data |
Response
Promise
\<MethodResponse
\<UpdateResponse
\<T
>>>
updateMany()
updateMany: (
params
) =>Promise
\<MethodResponse
\<CreateManyResponse
\<T
>>>
Method for updating multiple data records.
Example
models.<model_name>.updateMany({
data: {
// Updated data fields
},
filter: {
where: {
// Filter conditions
}
}
}).then(({ data }) => {
console.log(data.count); // Number of updated data records
});
Parameters
Parameter | Type | Description |
---|---|---|
params | object | Contains the parameter object with update data and filter conditions. |
params.data | T | - |
params.filter | FilterParams \<T > | - |
params.envType ? | prod or pre | Operate on production data or staging data |
Response
Promise
\<MethodResponse
\<CreateManyResponse
\<T
>>>
upsert()
upsert: (
params
) =>Promise
\<MethodResponse
\<UpsertResponse
\<T
>>>
Method for creating or updating
Example
models.<model_name>.upsert({
update: {
// Updated data fields
},
create: {
// Created data fields
},
filter: {
where: {
// Filter conditions
}
}
}).then(({ data }) => {
console.log(data.count); // Number of updated data records
});
Parameters
Parameter | Type | Description |
---|---|---|
params | object | Contains the parameter object with data objects for creation or update and filter conditions. |
params.create | T | - |
params.filter | FilterParams \<T > | - |
params.update | T | - |
params.envType ? | prod or pre | Operate on production data or staging data |
Response
Promise
\<MethodResponse
\<UpsertResponse
\<T
>>>
Model
Basic Model Type Definition
Properties
_id?
optional
_id:string
_openid?
optional
_openid:string
createBy?
optional
createBy:string
createdAt?
optional
createdAt:number
owner?
optional
owner:string
updateBy?
optional
updateBy:string
updatedAt?
optional
updatedAt:number
Type Alias
BasicComparisonOperator
BasicComparisonOperator:
"$eq"
|"$neq"
|"$gt"
|"$gte"
|"$lt"
|"$lte"
|"$in"
|"$nin"
Basic Comparison Operator Type Definitions.
ComparisonOperator
ComparisonOperator:
BasicComparisonOperator
|SpecialComparisonOperator
Comparison operator type definitions, including basic and special operators.
Example
$eq: equal to;
CreateManyResponse\<T>
CreateManyResponse\<
T
>:object
Response type definition for creating multiple records.
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
Type Declaration
idList
idList:
string
[]
List of IDs for created records.
CreateResponse\<T>
CreateResponse\<
T
>:object
Return type definition for the data creation method.
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
Type Declaration
id
id:
string
DeleteManyResponse\<T>
DeleteManyResponse\<
T
>:UpdateResponse
\<T
>
Response type definition for deleting multiple records, same as the response type for update operations.
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
DeleteResponse\<T>
DeleteResponse\<
T
>:object
Response type definition for delete operations, indicating the number of affected records.
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
Type Declaration
count
count:
number
The number of records affected by the delete operation. If count is 0, it means no records were deleted. If count is greater than 0, it means the corresponding number of records were successfully deleted.
FilterCondition
FilterCondition:
{ [key in ComparisonOperator]?: any }
Complex Query Conditions Type Definition
Example
{
* "$eq": "val"
* }
FilterConditionItem\<T>
FilterConditionItem\<
T
>:{ [key in keyof T]?: FilterCondition }
Filter parameter type definition.
This type definition allows conditional filtering on model fields and supports complex query operations.
Examples
Example 1: Use the $and
operator to combine conditions, ensuring all conditions are met.
{
"$and": [
{
"key": {
"$eq": "val"
}
}
]
}
Example 2: Use the $and
operator to combine conditions, which includes the $in
operator to check array inclusion.
{
"$and": [
{
"key1": {
"$in": ["foo", "bar"]
}
},
{
"key2": {
"$in": [1, 2]
}
}
]
}
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
FilterObject\<T>
FilterObject\<
T
>: { [operator in LogicalOperator]?: FilterConditionItem\<T>[] | FilterObject\<T> }
Define the type of filter parameters.
Examples
{
"$and": [
{
"title": {
"$eq": "hello"
}
}
]
}
{
"$or": [
{
"$and": [
{
"title": {
"$eq": "hello"
}
},
{
"body": {
"$neq": "world"
}
}
]
},
{
"createdBy": {
"$eq": "xxx"
}
}
]
}
Type Parameters
Type Parameters | Description |
---|---|
T | Represents the type of the model field. This type definition allows using complex query conditions to filter data. |
FilterParams\<T>
FilterParams\<
T
>:object
Define the type of filter parameters.
Example
{
relateWhere: {
comments: {
where: {
comment: {
$nempty: true,
},
},
},
},
where: {},
}
Type Parameters
Type Parameters | Description |
---|---|
T | Represents the type of the model field. |
Type Declaration
relateWhere?
optional
relateWhere:{ [K in RelationKeys<T>]?: Object }
Relationship Query
where?
optional
where:FilterConditionItem
\<T
> |FilterObject
\<T
>
Basic query
ListParams\<T>
ListParams\<
T
>:object
list method parameter definitions.
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
Type Declaration
filter?
optional
filter:FilterParams
\<T
>
getCount?
optional
getCount:boolean
orderBy?
optional
orderBy:OrderByParams
[]
pageNumber?
optional
pageNumber:number
pageSize?
optional
pageSize:number
relateWhere?
optional
relateWhere:any
select?
optional
select:SelectParams
\<T
> |object
ListResponse\<T>
ListResponse\<
T
>:MethodResponse
\<object
>
Return type definition for the data list method.
Type Declaration
records
records:
T
[]
total?
optional
total:number
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
LogicalOperator
LogicalOperator:
"$and"
|"$or"
Logical Operator Type Definitions.
MethodResponse\<T>
MethodResponse\<
T
>:object
Return type definition for the model operation method.
Type Parameters
Type Parameters | Description |
---|---|
T | Type of returned data. |
Type Declaration
data
data:
T
Returned data.
requestId?
optional
requestId:string
Unique identifier for the request.
OrderByParams
OrderByParams:
object
Sorting parameter structure definition.
Example
{
"createdAt": "asc",
}
Index Signature
[key
: string
]: "asc"
| "desc"
RelationField\<T>
RelationField\<
T
>:T
extendsobject
?U
:never
Type Parameters
Type Parameters |
---|
T |
SelectParams\<T>
SelectParams\<
T
>: { [K in keyof T]?: T[K] extends (infer U)[] | undefined ? SelectParams\<U> | boolean : T[K] extends object | undefined ? SelectParams\<T[K]> | boolean : boolean } &object
Selection parameter structure definition, used to specify the fields to be returned in a query.
Examples
{
"key1": true,
}
{
$master: true,
}
{
$master: true,
comments: {
comment: true,
}
}
Type Declaration
$master?
optional
$master:boolean
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
SpecialComparisonOperator
SpecialComparisonOperator:
"$search"
|"$nsearch"
|"$empty"
|"$nempty"
Special comparison operator type definitions.
UpdateResponse\<T>
UpdateResponse\<
T
>:object
Response type definition for update operations.
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
Type Declaration
count
count:
number
The number of records affected by the update operation.
UpsertResponse\<T>
UpsertResponse\<
T
>:object
Response type definition for create or update operations.
Type Parameters
Type Parameters | Description |
---|---|
T | Type of model field. |
Type Declaration
count
count:
number
Number of updated records. A non-zero value indicates a successful update.
id
id:
string
Number of changes. A non-"" value indicates successful creation.
OrmRawQueryClient
ORM client interface for executing raw SQL
Properties
$runSQL()?
This method only supports server-side invocation.
optional
$runSQL: (sql
,params
?,config
?) =>Promise
\<MethodResponse
\<object
>>
Parameters
Parameter | Type | Description |
---|---|---|
sql | string | SQL statement |
params ? | Record \<string , any > | sql template variables |
config ? | SQLCommandParams | Configuration |
Response
Promise
\<MethodResponse
\<object
>>
$runSQLRaw()?
This method only supports server-side invocation.
optional
$runSQLRaw: (sql
,config
?) =>Promise
\<MethodResponse
\<object
>>
Parameters
Parameter | Type | Description |
---|---|---|
sql | string | SQL statement |
config ? | SQLCommandParams | Configuration |
Response
Promise
\<MethodResponse
\<object
>>
SQLCommandParams
Properties
timeout?
optional
timeout:number
Timeout defaults to 5s, with a maximum of 15s.
optional
dbLinkName:string
English identifier for the data connector, default value is the cloud database MySQL identifier. It needs to be changed when using your own MySQL.