Toshihiko
    Preparing search index...

    Interface Query<Name, Schema, AdapterInstance>

    A mutable, chainable description of one database operation.

    Builder methods replace or extend the current Query state and return this same instance. Start again from the Model when two independent operations need different conditions, fields, limits, or connections.

    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;
    }

    Type Parameters

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

    Compatibility alias of fields.

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

    Compatibility alias of order.

    • Selects the transaction connection used by subsequent execution.

      Parameters

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

        Adapter-specific connection, or null to use the Adapter's default connection behavior.

      Returns this

      This Query.

    • Counts rows matching the current condition.

      Returns Promise<number>

      The count reported by the Adapter.

    • Replaces the selected fields.

      A string is split on commas and trimmed. An array receives schema field-name checking, while strings remain available for Adapter-compatible expressions.

      Parameters

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

        Comma-separated expression or logical field names.

      Returns this

      This Query.

      When the runtime value is neither a string nor an array.

    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Returns Promise<readonly QueriedYukari<Name, Schema, AdapterInstance>[]>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Parameters

      Returns Promise<readonly QueriedYukari<Name, Schema, AdapterInstance>[]>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Parameters

      Returns Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Parameters

      Returns Promise<readonly QueriedYukari<Name, Schema, AdapterInstance>[]>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Parameters

      Returns Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Parameters

      Returns Promise<readonly Partial<JsonRowFromSchema<Schema>>[]>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Parameters

      Returns Promise<Partial<JsonRowFromSchema<Schema>> | null>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Parameters

      Returns Promise<readonly Partial<JsonRowFromSchema<Schema>>[]>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Parameters

      Returns Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds rows using the current Query state.

      By default, the result is an array of Yukari rows. Passing true returns plain objects serialized through Field Types. single: true requests one result and changes the return type to a row or null; noCache: true tells the Adapter to bypass query caching. The boolean and options object may be passed in either supported order.

      Parameters

      Returns Promise<Partial<JsonRowFromSchema<Schema>> | null>

      Many rows by default, or one row when single: true.

      await User.where({ active: true }).find();
      await User.where({ active: true }).find(true);
      await User.where({ active: true }).find({ single: true });
    • Finds one row by its primary-key value or values.

      A Model with one primary key accepts the value directly. Composite keys require an object. With a configured Cache, this first attempts a Cache read; Cache errors fall back to the Adapter.

      Parameters

      Returns Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      The matching row, or null.

      When a primitive ID is supplied to a Model without exactly one primary key.

    • Finds one row by its primary-key value or values.

      A Model with one primary key accepts the value directly. Composite keys require an object. With a configured Cache, this first attempts a Cache read; Cache errors fall back to the Adapter.

      Parameters

      Returns Promise<QueriedYukari<Name, Schema, AdapterInstance> | null>

      The matching row, or null.

      When a primitive ID is supplied to a Model without exactly one primary key.

    • Finds one row by its primary-key value or values.

      A Model with one primary key accepts the value directly. Composite keys require an object. With a configured Cache, this first attempts a Cache read; Cache errors fall back to the Adapter.

      Parameters

      Returns Promise<Partial<JsonRowFromSchema<Schema>> | null>

      The matching row, or null.

      When a primitive ID is supplied to a Model without exactly one primary key.

    • Sets an Adapter-specific index hint.

      Parameters

      • indexName: string

        Index name passed to the Adapter without interpretation.

      Returns this

      This Query.

    • Sets the result count, or the offset and result count.

      Strings and arrays are retained for v1 compatibility. Values are parsed as base-10 integers, invalid values become 0, and at most two array entries are used.

      Parameters

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

        Count, comma-separated values, or [offset, count].

      Returns this

      This Query.

    • Sets the result count, or the offset and result count.

      Strings and arrays are retained for v1 compatibility. Values are parsed as base-10 integers, invalid values become 0, and at most two array entries are used.

      Parameters

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

      Returns this

      This Query.

    • Replaces the current sort order.

      Object forms provide schema field-name checking. String forms are parsed as comma-separated Adapter-compatible order expressions.

      Parameters

      Returns this

      This Query.

    • Replaces the current query condition.

      A later call does not merge with an earlier condition. Use $and or $or inside one condition when multiple branches are required.

      Parameters

      Returns this

      This Query.

      When the runtime value is not an object.