MCPcopy
hub / github.com/directus/directus / deleteMany

Method deleteMany

api/src/services/items.ts:1110–1231  ·  view source on GitHub ↗

* Delete multiple items by primary key.

(keys: PrimaryKey[], opts: MutationOptions = {})

Source from the content-addressed store, hash-verified

1108 * Delete multiple items by primary key.
1109 */
1110 async deleteMany(keys: PrimaryKey[], opts: MutationOptions = {}): Promise<PrimaryKey[]> {
1111 if (!opts.mutationTracker) opts.mutationTracker = this.createMutationTracker();
1112
1113 if (!opts.bypassLimits) {
1114 opts.mutationTracker.trackMutations(keys.length);
1115 }
1116
1117 const primaryKeyField = this.schema.collections[this.collection]!.primary;
1118 validateKeys(this.schema, this.collection, primaryKeyField, keys);
1119
1120 const keysAfterHooks =
1121 opts.emitEvents !== false
1122 ? await emitter.emitFilter(
1123 this.eventScope === 'items'
1124 ? ['items.delete', `${this.collection}.items.delete`]
1125 : `${this.eventScope}.delete`,
1126 keys,
1127 {
1128 collection: this.collection,
1129 },
1130 {
1131 database: this.knex,
1132 schema: this.schema,
1133 accountability: this.accountability,
1134 },
1135 )
1136 : keys;
1137
1138 if (this.accountability) {
1139 await validateAccess(
1140 {
1141 accountability: this.accountability,
1142 action: 'delete',
1143 collection: this.collection,
1144 primaryKeys: keysAfterHooks,
1145 },
1146 {
1147 knex: this.knex,
1148 schema: this.schema,
1149 },
1150 );
1151 }
1152
1153 if (opts.preMutationError) {
1154 throw opts.preMutationError;
1155 }
1156
1157 await transaction(this.knex, async (trx) => {
1158 const previousSeatCount = await captureSeatCount(trx, opts.userIntegrityCheckFlags);
1159
1160 await trx(this.collection).whereIn(primaryKeyField, keysAfterHooks).delete();
1161
1162 if (opts.userIntegrityCheckFlags) {
1163 if (opts.onRequireUserIntegrityCheck) {
1164 opts.onRequireUserIntegrityCheck(opts.userIntegrityCheckFlags);
1165 } else {
1166 await validateUserCountIntegrity({
1167 flags: opts.userIntegrityCheckFlags,

Callers 5

handlerFunction · 0.95
deleteManyMethod · 0.95
deleteByQueryMethod · 0.95
deleteOneMethod · 0.95
onMessageMethod · 0.95

Calls 14

createMutationTrackerMethod · 0.95
validateKeysFunction · 0.85
validateAccessFunction · 0.85
transactionFunction · 0.85
captureSeatCountFunction · 0.85
shouldClearCacheFunction · 0.85
getDatabaseFunction · 0.85
trackMutationsMethod · 0.80
emitFilterMethod · 0.80
emitActionMethod · 0.80
deleteMethod · 0.65

Tested by

no test coverage detected