@@ -21,6 +21,7 @@ It also provides the `crud-storage` and `crud-router` roles for
21
21
- [ Update] ( #update )
22
22
- [ Delete] ( #delete )
23
23
- [ Replace] ( #replace )
24
+ - [ Replace many] ( #replace-many )
24
25
- [ Upsert] ( #upsert )
25
26
- [ Upsert many] ( #upsert-many )
26
27
- [ Select] ( #select )
@@ -477,6 +478,101 @@ crud.replace_object('customers', {
477
478
...
478
479
```
479
480
481
+ ### Replace many
482
+
483
+ ``` lua
484
+ -- Replace batch of tuples
485
+ local result , err = crud .replace_many (space_name , tuples , opts )
486
+ -- Replace batch of objects
487
+ local result , err = crud .replace_object_many (space_name , objects , opts )
488
+ ```
489
+
490
+ where:
491
+
492
+ * ` space_name ` (` string ` ) - name of the space to insert/replace an object
493
+ * ` tuples ` / ` objects ` (` table ` ) - array of tuples/objects to insert
494
+ * ` opts ` :
495
+ * ` timeout ` (` ?number ` ) - ` vshard.call ` timeout (in seconds)
496
+ * ` fields ` (` ?table ` ) - field names for getting only a subset of fields
497
+ * ` stop_on_error ` (` ?boolean ` ) - stop on a first error and report error
498
+ regarding the failed operation and error about what tuples were not
499
+ performed, default is ` false `
500
+ * ` rollback_on_error ` (` ?boolean ` ) - any failed operation will lead to
501
+ rollback on a storage, where the operation is failed, report error
502
+ about what tuples were rollback, default is ` false `
503
+
504
+ Returns metadata and array contains inserted rows, array of errors.
505
+ Error object can contain field ` operation_data ` .
506
+
507
+ This field can contain:
508
+ * tuple for which the error occurred;
509
+ * object with an incorrect format;
510
+ * tuple the operation on which was performed but
511
+ operation was rollback;
512
+ * tuple the operation on which was not performed
513
+ because operation was stopped by error.
514
+
515
+ Right now CRUD cannot provide batch replace with full consistency.
516
+ CRUD offers batch replace with partial consistency. That means
517
+ that full consistency can be provided only on single replicaset
518
+ using ` box ` transactions.
519
+
520
+ ** Example:**
521
+
522
+ ``` lua
523
+ crud .replace_many (' developers' , {
524
+ {1 , box .NULL , ' Elizabeth' , ' lizaaa' },
525
+ {2 , box .NULL , ' Anastasia' , ' iamnewdeveloper' },
526
+ })
527
+ ---
528
+ - metadata :
529
+ - {' name' : ' id' , ' type' : ' unsigned' }
530
+ - {' name' : ' bucket_id' , ' type' : ' unsigned' }
531
+ - {' name' : ' name' , ' type' : ' string' }
532
+ - {' name' : ' login' , ' type' : ' string' }
533
+ rows :
534
+ - [1 , 477 , ' Elizabeth' , ' lizaaa' ]
535
+ - [2 , 401 , ' Anastasia' , ' iamnewdeveloper' ]
536
+ ...
537
+ crud .replace_object_many (' developers' , {
538
+ {id = 1 , name = ' Inga' , login = ' mylogin' },
539
+ {id = 10 , name = ' Anastasia' , login = ' qwerty' },
540
+ })
541
+ ---
542
+ - metadata :
543
+ - {' name' : ' id' , ' type' : ' unsigned' }
544
+ - {' name' : ' bucket_id' , ' type' : ' unsigned' }
545
+ - {' name' : ' name' , ' type' : ' string' }
546
+ - {' name' : ' age' , ' type' : ' number' }
547
+ rows :
548
+ - [1 , 477 , ' Inga' , ' mylogin' ]
549
+ - [10 , 569 , ' Anastasia' , ' qwerty' ]
550
+
551
+ -- Partial success
552
+ -- Let's say login has unique secondary index
553
+ local res , errs = crud .replace_object_many (' developers' , {
554
+ {id = 22 , name = ' Alex' , login = ' pushkinn' },
555
+ {id = 3 , name = ' Anastasia' , login = ' qwerty' },
556
+ {id = 5 , name = ' Sergey' , login = ' s.petrenko' },
557
+ })
558
+ ---
559
+ res
560
+ - metadata :
561
+ - {' name' : ' id' , ' type' : ' unsigned' }
562
+ - {' name' : ' bucket_id' , ' type' : ' unsigned' }
563
+ - {' name' : ' name' , ' type' : ' string' }
564
+ - {' name' : ' age' , ' type' : ' number' }
565
+ rows :
566
+ - [5 , 1172 , ' Sergey' , ' crudisthebest' ],
567
+ - [22 , 655 , ' Alex' , ' pushkinn' ],
568
+
569
+ # errs -- 1
570
+ errs [1 ].class_name -- ReplaceManyError
571
+ errs [1 ].err -- 'Duplicate key exists <...>'
572
+ errs [1 ].tuple -- {3, 2804, 'Anastasia', 'qwerty'}
573
+ ...
574
+ ```
575
+
480
576
### Upsert
481
577
482
578
``` lua
0 commit comments