Toshihiko
    正在准备搜索索引...

    接口 Query<Name, Schema, AdapterInstance>

    对一次数据库操作的可变、可链式描述。

    构造方法会替换或扩展当前 Query 状态,并返回同一个实例。如果两次独立操作需要不同的条件、字段、limit 或连接,请重新从 Model 开始。

    interface Query<
        Name extends string,
        Schema extends SchemaDefinition,
        AdapterInstance extends AdapterLike = Adapter,
    > {
        field: (
            fields:
                | string
                | readonly Extract<keyof RowFromSchema<Schema>, string>[],
        ) => this;
        orderBy: (order: QueryOrder<RowFromSchema<Schema>>) => this;
        conn(
            connection:
                | Exclude<Parameters<AdapterInstance["insert"]>[1], null>
                | null,
        ): this;
        count(): Promise<number>;
        delete(): Promise<AdapterDeleteByQueryResult<AdapterInstance>>;
        execute(
            ...arguments_: AdapterQueryExecuteArguments<AdapterInstance>,
        ): Promise<AdapterExecuteResult<AdapterInstance>>;
        fields(
            fields:
                | string
                | readonly Extract<keyof RowFromSchema<Schema>, string>[],
        ): this;
        find(): Promise<readonly QueriedYukari<Name, Schema, AdapterInstance>[]>;
        find(
            options: QueryFindManyOptions,
        ): Promise<readonly QueriedYukari<Name, Schema, AdapterInstance>[]>;
        find(
            options: QueryFindOneOptions,
        ): Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>;
        find(
            toJSON: false,
            options?: QueryFindManyOptions,
        ): Promise<readonly QueriedYukari<Name, Schema, AdapterInstance>[]>;
        find(
            toJSON: false,
            options: QueryFindOneOptions,
        ): Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>;
        find(
            toJSON: true,
            options?: QueryFindManyOptions,
        ): Promise<readonly Partial<JsonRowFromSchema<Schema>>[]>;
        find(
            toJSON: true,
            options: QueryFindOneOptions,
        ): Promise<Partial<JsonRowFromSchema<Schema>> | null>;
        find(
            options: QueryFindManyOptions,
            toJSON: true,
        ): Promise<readonly Partial<JsonRowFromSchema<Schema>>[]>;
        find(
            options: QueryFindOneOptions,
            toJSON: false,
        ): Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>;
        find(
            options: QueryFindOneOptions,
            toJSON: true,
        ): Promise<Partial<JsonRowFromSchema<Schema>> | null>;
        findById(
            id: FindByIdInput<Schema>,
        ): Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>;
        findById(
            id: FindByIdInput<Schema>,
            toJSON: false,
        ): Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>;
        findById(
            id: FindByIdInput<Schema>,
            toJSON: true,
        ): Promise<Partial<JsonRowFromSchema<Schema>> | null>;
        findOne(): Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>;
        findOne(
            toJSON: false,
        ): Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>;
        findOne(toJSON: true): Promise<Partial<JsonRowFromSchema<Schema>> | null>;
        index(indexName: string): this;
        limit(limit: string | number | readonly (string | number)[]): this;
        limit(offset: string | number, count: string | number): this;
        order(order: QueryOrder<RowFromSchema<Schema>>): this;
        update(
            data: Partial<RowFromSchema<Schema>>,
            ...support: AdapterUpdateByQueryCallArguments<AdapterInstance>,
        ): Promise<AdapterUpdateByQueryResult<AdapterInstance>>;
        where(condition: QueryWhere<RowFromSchema<Schema>>): this;
    }

    类型参数

    索引
    field: (
        fields: string | readonly Extract<keyof RowFromSchema<Schema>, string>[],
    ) => this

    以下类型的兼容性别名:fields。

    orderBy: (order: QueryOrder<RowFromSchema<Schema>>) => this

    以下类型的兼容性别名:order。

    • 选择后续执行使用的事务连接。

      参数

      • connection: Exclude<Parameters<AdapterInstance["insert"]>[1], null> | null

        Adapter 特有的连接,或 null 时会使用 Adapter 的默认连接行为。

      返回 this

      当前 Query。

    • 统计符合当前条件的数据行。

      返回 Promise<number>

      Adapter 报告的数量。

    • 替换选中的字段。

      字符串会按逗号拆分并去除空白;数组会检查 schema 字段名,而字符串仍可用于 Adapter 兼容表达式。

      参数

      • fields: string | readonly Extract<keyof RowFromSchema<Schema>, string>[]

        逗号分隔的表达式或逻辑字段名。

      返回 this

      当前 Query。

      运行时值既不是字符串也不是数组时。

    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      返回 Promise<readonly QueriedYukari<Name, Schema, AdapterInstance>[]>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      参数

      返回 Promise<readonly QueriedYukari<Name, Schema, AdapterInstance>[]>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      参数

      返回 Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      参数

      返回 Promise<readonly QueriedYukari<Name, Schema, AdapterInstance>[]>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      参数

      返回 Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      参数

      返回 Promise<readonly Partial<JsonRowFromSchema<Schema>>[]>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      参数

      返回 Promise<Partial<JsonRowFromSchema<Schema>> | null>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      参数

      返回 Promise<readonly Partial<JsonRowFromSchema<Schema>>[]>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      参数

      返回 Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 使用当前 Query 状态查找数据行。

      默认返回 Yukari 数据行数组。传入 true 会返回通过 Field Type 序列化的普通对象。single: true 会请求一个结果,并把返回类型改为一行数据或 null;noCache: true 会通知 Adapter 绕过查询缓存。布尔值和选项对象可以按任一受支持顺序传入。

      参数

      返回 Promise<Partial<JsonRowFromSchema<Schema>> | null>

      默认返回多行;以下选项启用时返回一行:single: true。

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • 按主键值查找一行数据。

      只有一个主键的 Model 可以直接接受该值;复合主键需要对象。配置 Cache 后会先尝试读取 Cache;Cache 出错时回退到 Adapter。

      参数

      返回 Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      匹配的数据行,或 null。

      向没有且仅有一个主键的 Model 传入原始类型 ID 时。

    • 按主键值查找一行数据。

      只有一个主键的 Model 可以直接接受该值;复合主键需要对象。配置 Cache 后会先尝试读取 Cache;Cache 出错时回退到 Adapter。

      参数

      返回 Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      匹配的数据行,或 null。

      向没有且仅有一个主键的 Model 传入原始类型 ID 时。

    • 按主键值查找一行数据。

      只有一个主键的 Model 可以直接接受该值;复合主键需要对象。配置 Cache 后会先尝试读取 Cache;Cache 出错时回退到 Adapter。

      参数

      返回 Promise<Partial<JsonRowFromSchema<Schema>> | null>

      匹配的数据行,或 null。

      向没有且仅有一个主键的 Model 传入原始类型 ID 时。

    • 设置 Adapter 特有的索引提示。

      参数

      • indexName: string

        不作解释、直接传给 Adapter 的索引名。

      返回 this

      当前 Query。

    • 设置结果数量,或设置 offset 与结果数量。

      为兼容 v1 会保留字符串和数组。值按十进制整数解析;无效值会变为 0;数组最多使用前两个元素。

      参数

      • limit: string | number | readonly (string | number)[]

        数量、逗号分隔值或 [offset, count]。

      返回 this

      当前 Query。

    • limit - 数量、逗号分隔值或 [offset, count]。

      参数

      • offset: string | number
      • count: string | number

      返回 this

      当前 Query。

    • 替换当前排序顺序。

      对象形式会检查 schema 字段名;字符串形式会按逗号拆分并解析为 Adapter 兼容的排序表达式。

      参数

      返回 this

      当前 Query。

    • 替换当前查询条件。

      后续调用不会与先前条件合并。需要组合条件时请使用 $and 或 $or ,用于一个条件需要多个分支时。

      参数

      返回 this

      当前 Query。

      运行时值不是对象时。