Library
core
classes
Core Src Data Query.query

Lawtext core references / core/src/data/query / Query

Class: Query<TItem>

core/src/data/query.Query

The query object that represents a source list and a filtering criteria.

フィルタ条件と検索元リストを表すクエリオブジェクト。

Example

A Query works as an async generator.

Query は async generator として使用できます。

const query = new Query(population, criteria);
for await (const item of query) {
    console.log(item);
}

Type parameters

Name
TItem

Hierarchy

Implements

  • AsyncIterable<TItem>

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Query<TItem>(population, criteria, options?): Query<TItem>

Instanciate a Query.

Type parameters

Name
TItem

Parameters

NameTypeDescription
populationAsyncIterable<TItem>a source list
criterianull | QueryCriteria<TItem>a filtering criteria
options?Partial<QueryOptions>options

Returns

Query<TItem>

Defined in

core/src/data/query.ts:79 (opens in a new tab)

Properties

criteria

criteria: null | CoreQueryCriteria<TItem>

Defined in

core/src/data/query.ts:70 (opens in a new tab)


options

options: QueryOptions

Defined in

core/src/data/query.ts:71 (opens in a new tab)


population

population: AsyncIterable<TItem>

Defined in

core/src/data/query.ts:69 (opens in a new tab)

Methods

[asyncIterator]

[asyncIterator](): AsyncGenerator<TItem, void, undefined>

Returns

AsyncGenerator<TItem, void, undefined>

Implementation of

AsyncIterable.[asyncIterator]

Defined in

core/src/data/query.ts:105 (opens in a new tab)


assign

assign<T>(func, criteria?, options?): Query<T extends undefined | void ? never : T & TItem>

Apply a function for each filtered item and iterate the merged object with the returned and original object.

フィルタ後の要素ごとに関数を実行し、返り値と元の要素のプロパティをマージしたオブジェクトを列挙します。

Type parameters

Name
T

Parameters

NameTypeDefault valueDescription
func(item: TItem) => T | Promise<T>undefineda function to be called for each filtered item
要素ごとに実行される関数
criterianull | QueryCriteria<T extends undefined | void ? never : T & TItem>nullan additional criteria applied after merge / マージ後に適用するフィルタ条件
options?Partial<QueryOptions>undefinedoptions which override the original ones / 上書きするオプション項目

Returns

Query<T extends undefined | void ? never : T & TItem>

  • a new Query that yields merged objects
    マージされたオブジェクトを列挙する新しい Query

Defined in

core/src/data/query.ts:180 (opens in a new tab)


filter

filter(criteria, options?): Query<TItem>

Apply an additional filter.

フィルタを追加します。

Parameters

NameTypeDescription
criterianull | QueryCriteria<TItem>an additional criteria / 追加するフィルタ条件
options?Partial<QueryOptions>options which override the original ones / 上書きするオプション項目

Returns

Query<TItem>

  • a new Query that applies criteria to the filtered items of the original Query
    フィルタ後の項目を検索元とし、criteria を検索条件とする新しい Query

Defined in

core/src/data/query.ts:211 (opens in a new tab)


forEach

forEach(func): Promise<void>

Invoke func for each filtered item. Running this function will invoke the whole iteration process of the Query.

列挙された要素ごとに func を実行します。この関数を実行すると Query の列挙を最後まで実行します。

Parameters

NameTypeDescription
func(item: TItem) => unknowna function to be called for each item
要素ごとに実行される関数

Returns

Promise<void>

Defined in

core/src/data/query.ts:376 (opens in a new tab)


limit

limit(max, options?): Query<TItem>

Yield until it reaches the maximum count.

出力の最大件数を設定します。

Parameters

NameTypeDescription
maxnumberthe maximum count
最大件数
options?Partial<QueryOptions>options which override the original ones / 上書きするオプション項目

Returns

Query<TItem>

  • a new Query that yields until it reaches the maximum count.
    最大件数に達するまで列挙を続ける新しい Query

Defined in

core/src/data/query.ts:296 (opens in a new tab)


map

map<T, TRet>(func, criteria?, options?): Query<Awaited<TRet>>

Apply a function for each filtered item.

フィルタ後の要素ごとに関数を実行します。

Type parameters

NameType
TT
TRetT extends undefined | void ? never : T

Parameters

NameTypeDefault valueDescription
func(item: TItem) => T | Promise<T>undefineda function to be called for each filtered item
要素ごとに実行される関数
criterianull | QueryCriteria<TRet>nullan additional criteria applied after filtering / 関数実行後に適用するフィルタ条件
options?Partial<QueryOptions>undefinedoptions which override the original ones / 上書きするオプション項目

Returns

Query<Awaited<TRet>>

  • a new Query that yields items returned by func
    func の返り値を列挙する新しい Query

Defined in

core/src/data/query.ts:127 (opens in a new tab)


mapWorkers

mapWorkers<T, TRet>(workersPool, criteria?, options?): Query<Awaited<TRet>>

Type parameters

NameType
TT
TRetT extends undefined | void ? never : T

Parameters

NameTypeDefault value
workersPoolWorkersPool<TItem, TRet>undefined
criterianull | QueryCriteria<TRet>null
options?Partial<QueryOptions>undefined

Returns

Query<Awaited<TRet>>

Defined in

core/src/data/query.ts:149 (opens in a new tab)


new

new(population, criteria, overrideOptions?): Query<TItem>

Parameters

NameType
populationAsyncIterable<TItem>
criterianull | QueryCriteria<TItem>
overrideOptions?Partial<QueryOptions>

Returns

Query<TItem>

Defined in

core/src/data/query.ts:97 (opens in a new tab)


pick

pick<K>(...keys): Query<Awaited<Pick<TItem, K>>>

Pick properties of each item.

特定のプロパティ以外のプロパティを削除したオブジェクトを列挙します。

Type parameters

NameType
Kextends string | number | symbol

Parameters

NameTypeDescription
...keysK[]the keys of properties to be picked
抜き出すプロパティのキー

Returns

Query<Awaited<Pick<TItem, K>>>

  • a new Query that yields the objects with the picked properties
    プロパティを抜き出した新しいオブジェクトの内容を列挙する新しい Query

Defined in

core/src/data/query.ts:337 (opens in a new tab)


property

property<K>(key): Query<Awaited<TItem[K]>>

Yield a property of each item.

特定のプロパティの内容を一つ抜き出して列挙します。

Type parameters

NameType
Kextends string | number | symbol

Parameters

NameTypeDescription
keyKthe key of a property to be picked
抜き出すプロパティのキー

Returns

Query<Awaited<TItem[K]>>

  • a new Query that yields the picked property
    抜き出したプロパティの内容を列挙する新しい Query

Defined in

core/src/data/query.ts:325 (opens in a new tab)


skip

skip(count, options?): Query<TItem>

Skip specified count.

指定した件数スキップします。

Parameters

NameTypeDescription
countnumbercount to skip
スキップする件数
options?Partial<QueryOptions>options which override the original ones / 上書きするオプション項目

Returns

Query<TItem>

  • a new Query that yields after skipping specified count.
    指定した件数のスキップ後列挙を続ける新しい Query

Defined in

core/src/data/query.ts:265 (opens in a new tab)


toArray

toArray(options?): Promise<TItem[]>

Generate an array from the Query. Running this function will invoke the whole iteration process of the Query.

Query から配列を生成します。この関数を実行すると Query の列挙を最後まで実行します。

Parameters

NameTypeDescription
optionsObjectoptions.preserveCache <boolean>: whether to suggest the Query to preserve the cached data for each item, which normally will be cleared after yield (default: false)
Queryにキャッシュされたデータを削除せずそのまま残すかどうかを指示します。
options.preserveCacheboolean-

Returns

Promise<TItem[]>

  • a Promise that resolves a generated array
    生成された配列を返す Promise

Defined in

core/src/data/query.ts:358 (opens in a new tab)


while

while(func, yieldLast?, options?): Query<TItem>

Yield while func returns true.

functrue を返す間、列挙を続けます。

Parameters

NameTypeDefault valueDescription
func(item: TItem) => boolean | Promise<boolean>undefineda function to be called for each filtered item. Returning false terminates the iteration.
要素ごとに実行される関数。falseを返すと列挙を停止します。
yieldLastbooleanfalsewhether to return the item that caused func returned false
funcfalseを返す要因となった要素を出力するかどうか
options?Partial<QueryOptions>undefinedoptions which override the original ones / 上書きするオプション項目

Returns

Query<TItem>

  • a new Query that yields while func returns true
    functrue を返す間列挙を続ける新しい Query

Defined in

core/src/data/query.ts:232 (opens in a new tab)