Legacy-to-DQL Reference
This article covers example mappings from Legacy Query APIs to DQL for basic CRUD operations as well as syncing data with the SDK.
Creating Documents
In DQL syntax, enclose string
literals within single quotes (''
); for example 'blue'
.
Use single quotes in DQL queries to ensure accuracy. Incorrectly using double quotes (""
); for example "blue"
, may prevent document matching. Currently, Ditto does not throw a warning for this issue.
Inserting a Single Document
Inserting Multiple Documents
Inserting Initial/Default Documents
This is the ability to insert documents at time 0. For more information see INSERT with INITIAL DOCUMENTS.
Upserting Documents
Legacy supports upserting by default where DQL requires the policy to be explicitly set.
Reading Data
Querying Data
Querying Data by ID
Querying Data with Limits
Querying for Null Values
Querying with Arguments
Observing Data Changes
Updating Documents
Updating a Single Document
Updating Multiple Documents
Updating Multiple Fields
Updating Nested Fields
Counters
Available in 4.11 and later with DQL_STRICT_MODE=false.
Counters are now supported in DQL. To use them you can use the APPLY keyword
followed by the field name and then the PN_INCREMENT
keyword followed by the
value you want to increment the value by.
To decrement a counter, use a negative value.
For more information on using Counters see here.
Registers
A 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:
- Stores primitive types (string, boolean) or JSON objects
- Last-write-wins conflict resolution ensures consistent values across peers
- With strict mode disabled, if you want a REGISTER Map data type in DQL, it must be specified explicitly
For more information on using types and definitions, see Registers.
Deletion
Deleting Fields
Evicting Documents
Deleting Documents
There are several ways to delete data in Ditto, and you can find more detail about them here.