MCPcopy
hub / github.com/directus/directus / upsertSingleton

Method upsertSingleton

api/src/services/items.ts:1279–1289  ·  view source on GitHub ↗

* Upsert/treat collection as singleton. * * Uses `this.createOne` / `this.updateOne` under the hood.

(data: Partial<Item>, opts?: MutationOptions)

Source from the content-addressed store, hash-verified

1277 * Uses `this.createOne` / `this.updateOne` under the hood.
1278 */
1279 async upsertSingleton(data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey> {
1280 const primaryKeyField = this.schema.collections[this.collection]!.primary;
1281
1282 const record = await this.knex.select(primaryKeyField).from(this.collection).limit(1).first();
1283
1284 if (record) {
1285 return await this.updateOne(record[primaryKeyField], data, opts);
1286 }
1287
1288 return await this.createOne(data, opts);
1289 }
1290}

Callers 2

handlerFunction · 0.95
onMessageMethod · 0.95

Calls 3

updateOneMethod · 0.95
createOneMethod · 0.95
fromMethod · 0.80

Tested by

no test coverage detected