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
-
Query
↳
LawQuery
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
Name | Type | Description |
---|---|---|
population | AsyncIterable <TItem > | a source list |
criteria | null | 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
Name | Type | Default value | Description |
---|---|---|---|
func | (item : TItem ) => T | Promise <T > | undefined | a function to be called for each filtered item 要素ごとに実行される関数 |
criteria | null | QueryCriteria <T extends undefined | void ? never : T & TItem > | null | an additional criteria applied after merge / マージ後に適用するフィルタ条件 |
options? | Partial <QueryOptions > | undefined | options 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
Name | Type | Description |
---|---|---|
criteria | null | QueryCriteria <TItem > | an additional criteria / 追加するフィルタ条件 |
options? | Partial <QueryOptions > | options which override the original ones / 上書きするオプション項目 |
Returns
Query
<TItem
>
- a new
Query
that appliescriteria
to the filtered items of the originalQuery
フィルタ後の項目を検索元とし、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
Name | Type | Description |
---|---|---|
func | (item : TItem ) => unknown | a 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
Name | Type | Description |
---|---|---|
max | number | the 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
Name | Type |
---|---|
T | T |
TRet | T extends undefined | void ? never : T |
Parameters
Name | Type | Default value | Description |
---|---|---|---|
func | (item : TItem ) => T | Promise <T > | undefined | a function to be called for each filtered item 要素ごとに実行される関数 |
criteria | null | QueryCriteria <TRet > | null | an additional criteria applied after filtering / 関数実行後に適用するフィルタ条件 |
options? | Partial <QueryOptions > | undefined | options which override the original ones / 上書きするオプション項目 |
Returns
Query
<Awaited
<TRet
>>
- a new
Query
that yields items returned byfunc
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
Name | Type |
---|---|
T | T |
TRet | T extends undefined | void ? never : T |
Parameters
Name | Type | Default value |
---|---|---|
workersPool | WorkersPool <TItem , TRet > | undefined |
criteria | null | 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
Name | Type |
---|---|
population | AsyncIterable <TItem > |
criteria | null | 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
Name | Type |
---|---|
K | extends string | number | symbol |
Parameters
Name | Type | Description |
---|---|---|
...keys | K [] | 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
Name | Type |
---|---|
K | extends string | number | symbol |
Parameters
Name | Type | Description |
---|---|---|
key | K | the 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
Name | Type | Description |
---|---|---|
count | number | count 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
Name | Type | Description |
---|---|---|
options | Object | options.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.preserveCache | boolean | - |
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
.
func
が true
を返す間、列挙を続けます。
Parameters
Name | Type | Default value | Description |
---|---|---|---|
func | (item : TItem ) => boolean | Promise <boolean > | undefined | a function to be called for each filtered item. Returning false terminates the iteration. 要素ごとに実行される関数。 false を返すと列挙を停止します。 |
yieldLast | boolean | false | whether to return the item that caused func returned false func がfalse を返す要因となった要素を出力するかどうか |
options? | Partial <QueryOptions > | undefined | options which override the original ones / 上書きするオプション項目 |
Returns
Query
<TItem
>
- a new
Query
that yields whilefunc
returnstrue
func
がtrue
を返す間列挙を続ける新しいQuery