This article covers example mappings from Legacy Query APIs to DQL for basic CRUD operations as well as syncing data with the SDK.
store.collection("name")
string
literals within single quotes (''
); for example 'blue'
.""
); for example "blue"
, may prevent document matching. Currently, Ditto does not throw a warning for this issue.collection.insert({...})
store.execute("INSERT INTO COLLECTION name DOCUMENTS (:doc)", {{"doc", json_doc}})
collection.upsert({...})
store.execute("INSERT INTO COLLECTION name DOCUMENTS (:doc) ON ID CONFLICT DO UPDATE", {{"doc", json_doc}})
ON ID CONFLICT DO UPDATE
to get true upsert behavior (insert or update)ON ID CONFLICT
clausecollection.find("field == $args.value").with_args({{"value", x}}).exec()
store.execute("SELECT * FROM COLLECTION name WHERE field = :value", {{"value", x}})
collection.find_by_id(doc_id).exec()
store.execute("SELECT * FROM COLLECTION name WHERE _id = :id", {{"id", doc_id}})
collection.find_by_id(id).update({ ... })
store.execute("UPDATE COLLECTION name SET field = :value WHERE _id = :id", params)
PN_INCREMENT
keyword followed by the
value you want to increment the value by.
To decrement a counter, use a negative value.
store.new_attachment(path, metadata)
- Still availablestore.fetch_attachment(token, handler)
- Still availablecollection.new_attachment()
→ Use store.new_attachment()
collection.fetch_attachment()
→ Use store.fetch_attachment()
REGISTER
is a data type in Ditto that stores a single scalar value and uses last-write-wins merge strategy for handling conflicts
Key characteristics of REGISTER: