* Upsert/treat collection as singleton. * * Uses `this.createOne` / `this.updateOne` under the hood.
(data: Partial<Item>, opts?: MutationOptions)
| 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 | } |