CRUD Operations
UPDATE
this article provides an overview of the updating documents using the update and insert dql operations all modification operations in ditto are performed using the execute api method against the ditto store let result = try await ditto store execute(query / query /, arguments / arguments /);var result = ditto store execute(/ query /, / arguments /)const result = await ditto store execute(/ query /, / arguments /)dittoqueryresult result = (dittoqueryresult) ditto store execute( / query /, / arguments /, / continuation /);var result = await ditto store executeasync(/ query /, / arguments /);auto result = ditto get store() execute(/ query /, / arguments /) get();let result = ditto store() execute(/ query /, / arguments /); updating with update update operations ensure that only the minimum data necessary to enforce all peers converge on one view of the data replicates across the mesh try await ditto store execute(""" update cars set color = 'blue' where id = '123' """);ditto store execute(""" update cars set color = 'blue' where id = '123' """)await ditto store execute(` update cars set color = 'blue' where id = '123'`)dittoqueryresult result = (dittoqueryresult) ditto store execute( "update cars set color = 'blue' where id = '123'", new continuation<>() { @nonnull @override public coroutinecontext getcontext() { return emptycoroutinecontext instance; } @override public void resumewith(@nonnull object o) { if (o instanceof result failure) { // handle failure } } } );await ditto store executeasync( "update cars set color = 'blue' where id = '123'");ditto get store() execute( "update cars set color = 'blue' where id = '123'") get();ditto store() execute( "update cars set color = 'blue' where id = '123'", none); for complete dql syntax, see ditto query language (dql) > docid\ t3hf69sxfguv3v2ole3rz updating multiple documents in a collection update operates over a condition that allows multiple documents to be updated at the same time in the following example, all the red cars in the cars collection are updated to be blue the documents updated can be referenced by using the mutateddocumentids method on the result let result = try await ditto store execute( "update cars set color = 'blue' where id = '123'"); result mutateddocumentids foreach() { print($0) }var result = ditto store execute(""" update cars set color = 'blue' where id = '123' """) result mutateddocumentids() foreach { id > println(id) }const result = await ditto store execute(` update cars set color = 'blue' where color = 'red'`) console log(result mutateddocumentids())dittoqueryresult result = (dittoqueryresult) ditto store execute( "update cars set color = 'blue' where color = 'red'", new continuation<>() { @nonnull @override public coroutinecontext getcontext() { return emptycoroutinecontext instance; } @override public void resumewith(@nonnull object o) { if (o instanceof result failure) { // handle failure } } } ); for (string id result mutateddocumentids()) { system out println(id); }const result = await ditto store executeasync( "update cars set color = 'blue' where color = 'red'"); result mutateddocumentids foreach(id => console writeline(id));ditto get store() execute( "update cars set color = 'blue' where color = 'red'") get();ditto store() execute( "update cars set color = 'blue' where color = 'red'", none); updating with insert the insert operation provides conflict policy options to override default behavior if a document with the same id already exists by using the on id conflict do update policy, inserted documents automatically apply updates for all provided fields updating data using an insert operation may cause performance to degrade this is because when you use an insert operation to modify data, all provided fields update, even if they remain unchanged to optimize performance and reduce unnecessary overhead, apply most updates in your app through the update method instead var document = \[ " id" "123", "color" "red", ]; try await ditto store execute( query """ insert into cars documents (\ document) on id conflict do update """, arguments \[ "document" document ]);ditto store execute( "insert into cars documents (\ car)", mapof("car" to mapof( " id" to "123", "color" to "red" )))const document = { id "123", color "red", } await ditto store execute(` insert into cars documents (\ document) on id conflict do update`, { document })map\<string, string> document = new hashmap<>(); newcar put(" id", "123"); newcar put("color", "red"); dittoqueryresult result = (dittoqueryresult) ditto store execute( "insert into cars documents (\ document) on id conflict do update", collections singletonmap("document", document), new continuation<>() { @nonnull @override public coroutinecontext getcontext() { return emptycoroutinecontext instance; } @override public void resumewith(@nonnull object o) { if (o instanceof result failure) { // handle failure } } } );var args = new dictionary\<string, object> { "document", new { id = "123" , color = "red" } }; await ditto store executeasync( "insert into cars" \+ " documents (\ document) on id conflict do update", args);std map\<std string, std map\<std string, std string>> args; args\["document"] = {{" id", "123"},{"color", "red"}}; ditto get store() execute( "insert into cars documents (\ document) on id conflict do update", args) get();struct args { document car, } struct car { id string, color string } // let args = args { document car { id "123" to string(), color "red" to string() }, }; ditto store() execute( "insert into cars documents (\ document)", args); for complete dql syntax, see ditto query language (dql) > docid\ pokcnkex oxyejkoaupti