MCPcopy
hub / github.com/directus/directus / readMany

Method readMany

api/src/services/items.ts:635–648  ·  view source on GitHub ↗

* Get multiple items by primary keys. * * Uses `this.readByQuery` under the hood.

(keys: PrimaryKey[], query: Query = {}, opts?: QueryOptions)

Source from the content-addressed store, hash-verified

633 * Uses `this.readByQuery` under the hood.
634 */
635 async readMany(keys: PrimaryKey[], query: Query = {}, opts?: QueryOptions): Promise<Item[]> {
636 const primaryKeyField = this.schema.collections[this.collection]!.primary;
637 validateKeys(this.schema, this.collection, primaryKeyField, keys);
638
639 const filterWithKey = { _and: [{ [primaryKeyField]: { _in: keys } }, query.filter ?? {}] };
640 const queryWithKey = assign({}, query, { filter: filterWithKey });
641
642 // Set query limit as the number of keys
643 if (Array.isArray(keys) && keys.length > 0 && !queryWithKey.limit) {
644 queryWithKey.limit = keys.length;
645 }
646
647 return await this.readByQuery(queryWithKey, opts);
648 }
649
650 /**
651 * Update multiple items by query.

Callers 3

handlerFunction · 0.95
updateManyMethod · 0.95
onMessageMethod · 0.95

Calls 2

readByQueryMethod · 0.95
validateKeysFunction · 0.85

Tested by

no test coverage detected