@@ -41,6 +41,7 @@ _Supported Deno verisons:_ **^1.38.5**
41
41
- [ updateByPrimaryIndex()] ( #updatebyprimaryindex )
42
42
- [ updateBySecondaryIndex()] ( #updatebysecondaryindex )
43
43
- [ updateMany()] ( #updatemany )
44
+ - [ upsert()] ( #upsert )
44
45
- [ delete()] ( #delete )
45
46
- [ deleteByPrimaryIndex()] ( #deletebyprimaryindex )
46
47
- [ deleteBySecondaryIndex()] ( #deletebysecondaryindex )
@@ -245,7 +246,7 @@ timestamp, type of either "write" or "delete", and a copy of the document value
245
246
if the type is "write".
246
247
247
248
``` ts
248
- const history = await db .users .findHistory (" user_id" )
249
+ const { result } = await db .users .findHistory (" user_id" )
249
250
```
250
251
251
252
### findUndelivered()
@@ -406,6 +407,49 @@ const { result } = await db.users.updateMany({ age: 67 }, {
406
407
const { result } = await db .users .updateMany ({ username: " XuserX" })
407
408
```
408
409
410
+ ### upsert()
411
+
412
+ Update an existing document by either id or primary index, or set a new document
413
+ entry if no document with matching id/index exists. When upserting by primary
414
+ index, an id can be optionally specified which will be used when setting a new
415
+ document entry, otherwise an id will be generated.
416
+
417
+ ``` ts
418
+ // Upsert by id
419
+ const result1 = await db .users .upsert ({
420
+ id: " user_id" ,
421
+ update: { username: " Chris" },
422
+ set: {
423
+ username: " Chris" ,
424
+ age: 54 ,
425
+ activities: [" bowling" ],
426
+ address: {
427
+ country: " USA" ,
428
+ city: " Las Vegas"
429
+ street : " St. Boulevard"
430
+ houseNumber : 23
431
+ }
432
+ }
433
+ })
434
+
435
+ // Upsert by index
436
+ const result2 = await db .users .upsert ({
437
+ index: [" username" , " Jack" ],
438
+ update: { username: " Chris" },
439
+ set: {
440
+ username: " Chris" ,
441
+ age: 54 ,
442
+ activities: [" bowling" ],
443
+ address: {
444
+ country: " USA" ,
445
+ city: " Las Vegas"
446
+ street : " St. Boulevard"
447
+ houseNumber : 23
448
+ }
449
+ }
450
+ })
451
+ ```
452
+
409
453
### delete()
410
454
411
455
Delete one or more documents with the given ids from the KV store.
0 commit comments