# SDK 类型声明

# 接口

# DataModelMethods<T>

模型操作方法接口定义。

# 类型参数

类型参数 描述
T 模型字段的类型。

# 属性

# create()

create: (params) => Promise<MethodResponse<CreateResponse<T>>>

创建单条数据的方法。

# Example
models.<model_name>.create({
  data: {
    // 模型字段数据
  }
}).then(({ data }) => {
  console.log(data.id); // 输出创建的数据ID
});
# 参数
参数 类型 描述
params object 包含创建数据的参数对象。
params.data T -
# 返回

Promise<MethodResponse<CreateResponse<T>>>

# createMany()

createMany: (params) => Promise<MethodResponse<CreateManyResponse<T>>>

创建多条数据的方法。

# Example
models.<model_name>.createMany({
  data: [
    // 模型字段数据数组
  ]
}).then(({ data }) => {
  console.log(data.idList); // 输出创建的数据ID列表
});
# 参数
参数 类型 描述
params object 包含创建数据数组的参数对象。
params.data T[] -
# 返回

Promise<MethodResponse<CreateManyResponse<T>>>

# delete()

delete: (params) => Promise<MethodResponse<DeleteResponse<T>>>

删除单条数据的方法。

# Example
models.<model_name>.delete({
  filter: {
    where: {
      // 筛选条件,例如根据ID删除特定记录
      _id: {
        $eq: "特定ID值"
      }
    }
  }
}).then(({ data }) => {
  console.log(data.count); // 输出删除的数据条数
});
# 参数
参数 类型 描述
params object 包含筛选条件的参数对象。
params.filter FilterParams<T> -
# 返回

Promise<MethodResponse<DeleteResponse<T>>>

# deleteMany()

deleteMany: (params) => Promise<MethodResponse<DeleteManyResponse<T>>>

删除多条数据的方法。

# Example
models.<model_name>.deleteMany({
  filter: {
    where: {
      // 筛选条件,例如删除所有满足特定条件的记录
    }
  }
}).then(({ data }) => {
  console.log(data.count); // 输出删除的数据条数
});
# 参数
参数 类型 描述
params object 包含筛选条件的参数对象。
params.filter FilterParams<T> -
# 返回

Promise<MethodResponse<DeleteManyResponse<T>>>

# get()

get: (params) => Promise<MethodResponse<T>>

获取单条数据的方法。

# Example
models.<model_name>.get({
  filter: {
    where: {
      // 筛选条件
    }
  },
  select: {
    $master: true // 选择主表所有字段
  }
}).then(({ data }) => {
  console.log(data); // 输出查询到的数据
});
# 参数
参数 类型 描述
params object 包含筛选条件和选择字段的参数对象。
params.filter FilterParams<T> -
params.select? SelectParams<T> -
# 返回

Promise<MethodResponse<T>>

# list()

list: (params) => Promise<MethodResponse<object>>

获取多条数据的方法。

# Example
models.<model_name>.list({
  filter: {
    where: {
      // 筛选条件
    }
  },
  select: {
    $master: true // 选择主表所有字段
  },
  getCount: true, // 开启用来获取总数
  pageSize: 10, // 分页大小
  pageNumber: 1, // 当前页码
  orderBy: [{ createdAt: 'desc' }] // 排序参数
}).then(({ data }) => {
  console.log(data.records, data.total); // 输出查询到的数据列表和总数
});
# 参数
参数 类型 描述
params object 包含筛选条件、选择字段、分页和排序选项的参数对象。
params.filter? FilterParams<T> 过滤条件
params.getCount? boolean 是否获取 filter 命中条件的查询条数
params.orderBy? OrderByParams[] 排序参数,当前仅支持最多 3 字段排序
params.pageNumber? number 分页数目
params.pageSize? number 分页大小,建议指定,如需设置为其它值,需要和 pageNo 配合使用,两者同时指定才会生效
params.select? SelectParams<T> 可以指定返回本表或者关联表的字段,如果想查询本表所有字段,请使用 { $master: true }
# 返回

Promise<MethodResponse<object>>

# update()

update: (params) => Promise<MethodResponse<UpdateResponse<T>>>

更新单条数据的方法。

# Example
models.<model_name>.update({
  data: {
    // 更新的数据字段
  },
  filter: {
    where: {
      // 筛选条件
    }
  }
}).then(({ data }) => {
  console.log(data.count); // 输出更新的数据条数
});
# 参数
参数 类型 描述
params object 包含更新数据和筛选条件的参数对象。
params.data T -
params.filter FilterParams<T> -
# 返回

Promise<MethodResponse<UpdateResponse<T>>>

# updateMany()

updateMany: (params) => Promise<MethodResponse<CreateManyResponse<T>>>

更新多条数据的方法。

# Example
models.<model_name>.updateMany({
  data: {
    // 更新的数据字段
  },
  filter: {
    where: {
      // 筛选条件
    }
  }
}).then(({ data }) => {
  console.log(data.count); // 输出更新的数据条数
});
# 参数
参数 类型 描述
params object 包含更新数据和筛选条件的参数对象。
params.data T -
params.filter FilterParams<T> -
# 返回

Promise<MethodResponse<CreateManyResponse<T>>>

# upsert()

upsert: (params) => Promise<MethodResponse<UpsertResponse<T>>>

创建或者更新的方法

# Example
models.<model_name>.upsert({
  update: {
    // 更新的数据字段
  },
  create: {
    // 创建的数据字段
  },
  filter: {
    where: {
      // 筛选条件
    }
  }
}).then(({ data }) => {
  console.log(data.count); // 输出更新的数据条数
});
# 参数
参数 类型 描述
params object 包含创建或者更新对象以及和筛选条件的参数对象。
params.create T -
params.filter FilterParams<T> -
params.update T -
# 返回

Promise<MethodResponse<UpsertResponse<T>>>


# Model

基础 Model 类型定义

# 属性

# _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

# 类型别名

# BasicComparisonOperator

BasicComparisonOperator: "$eq" | "$neq" | "$gt" | "$gte" | "$lt" | "$lte" | "$in" | "$nin"

基础比较运算符类型定义。


# ComparisonOperator

ComparisonOperator: BasicComparisonOperator | SpecialComparisonOperator

比较运算符类型定义,包括基础和特殊运算符。

# Example

$eq: 等于;

# CreateManyResponse<T>

CreateManyResponse<T>: object

创建多条记录的响应类型定义。

# 类型参数

类型参数 描述
T 模型字段的类型。

# 类型声明

# idList

idList: string[]

创建的记录的 ID 列表。


# CreateResponse<T>

CreateResponse<T>: object

数据创建方法的返回类型定义。

# 类型参数

类型参数 描述
T 模型字段的类型。

# 类型声明

# id

id: string


# DeleteManyResponse<T>

DeleteManyResponse<T>: UpdateResponse<T>

删除多条记录的响应类型定义,与更新操作的响应类型相同。

# 类型参数

类型参数 描述
T 模型字段的类型。

# DeleteResponse<T>

DeleteResponse<T>: object

删除操作的响应类型定义,用于表示删除操作影响的记录数量。

# 类型参数

类型参数 描述
T 模型字段的类型。

# 类型声明

# count

count: number

删除操作影响的记录数量。 如果 count 为 0,表示没有记录被删除; 如果 count 大于 0,表示有相应数量的记录被成功删除。


# FilterCondition

FilterCondition: { [key in ComparisonOperator]?: any }

复杂查询条件类型定义

# Example

{
 *  "$eq": "val"
 * }

# FilterConditionItem<T>

FilterConditionItem<T>: { [key in keyof T]?: FilterCondition }

过滤参数类型定义。

此类型定义允许对模型字段进行条件过滤,支持复杂的查询操作。

# Examples

示例 1: 使用$and运算符来组合条件,确保所有条件都满足。

{
  "$and": [
    {
      "key": {
        "$eq": "val"
      }
    }
  ]
}

示例 2: 使用$and运算符来组合条件,其中包含$in运算符来检查数组包含性。

{
  "$and": [
    {
      "key1": {
        "$in": ["foo", "bar"]
      }
    },
    {
      "key2": {
        "$in": [1, 2]
      }
    }
  ]
}

# 类型参数

类型参数 描述
T 模型字段的类型。

# FilterObject<T>

FilterObject<T>: { [operator in LogicalOperator]?: FilterConditionItem<T>[] | FilterObject<T> }

定义过滤参数的类型。

# Examples

{
  "$and": [
    {
      "title": {
        "$eq": "hello"
      }
    }
  ]
}
{
  "$or": [
    {
      "$and": [
        {
          "title": {
            "$eq": "hello"
          }
        },
        {
          "body": {
            "$neq": "world"
          }
        }
      ]
    },
    {
      "createdBy": {
        "$eq": "xxx"
      }
    }
  ]
}

# 类型参数

类型参数 描述
T

表示模型字段的类型。

此类型定义允许使用复杂的查询条件来过滤数据。


# FilterParams<T>

FilterParams<T>: object

定义过滤参数的类型。

# Example

{
    relateWhere: {
      comments: {
        where: {
          comment: {
            $nempty: true,
          },
        },
      },
    },
    where: {},
  }

# 类型参数

类型参数 描述
T 表示模型字段的类型。

# 类型声明

# relateWhere?

optional relateWhere: { [K in RelationKeys<T>]?: Object }

关联关系查询

# where?

optional where: FilterConditionItem<T> | FilterObject<T>

基础查询


# ListParams<T>

ListParams<T>: object

list 方法参数定义。

# 类型参数

类型参数 描述
T 模型字段的类型。

# 类型声明

# 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>

数据列表方法的返回类型定义。

# 类型声明

# records

records: T[]

# total?

optional total: number

# 类型参数

类型参数 描述
T 模型字段的类型。

# LogicalOperator

LogicalOperator: "$and" | "$or"

逻辑运算符类型定义。


# MethodResponse<T>

MethodResponse<T>: object

模型操作方法的返回类型定义。

# 类型参数

类型参数 描述
T 返回数据的类型。

# 类型声明

# data

data: T

返回的数据。

# requestId?

optional requestId: string

请求的唯一标识符。


# OrderByParams

OrderByParams: object

排序参数结构定义。

# Example

{
  "createdAt": "asc",
 }

# 索引签名

[key: string]: "asc" | "desc"


# RelationField<T>

RelationField<T>: T extends object ? U : never

# 类型参数

类型参数
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

选择参数结构定义,用于指定查询时返回的字段。

# Examples

{
   "key1": true,
 }
{
  $master: true,
 }
{
  $master: true,
  comments: {
   comment: true,
  }
 }

# 类型声明

# $master?

optional $master: boolean

# 类型参数

类型参数 描述
T 模型字段的类型。

# SpecialComparisonOperator

SpecialComparisonOperator: "$search" | "$nsearch" | "$empty" | "$nempty"

特殊比较运算符类型定义


# UpdateResponse<T>

UpdateResponse<T>: object

更新操作的响应类型定义。

# 类型参数

类型参数 描述
T 模型字段的类型。

# 类型声明

# count

count: number

更新操作影响的记录数量。


# UpsertResponse<T>

UpsertResponse<T>: object

创建或者更新的响应类型定义。

# 类型参数

类型参数 描述
T 模型字段的类型。

# 类型声明

# count

count: number

变更的条数,返回非 0 值代表更新成功

# id

id: string

变更的条数,返回非 "" 值代表创建成功