Types and Definitions
ditto query language (dql) offers a set of data types designed to accommodate any edge sync scenario a data type is different than a standard scalar type by declaring merge behaviors, operations, and the spectrum of scalar types accessible for individual fields /#data types /#declaring type definition /#map type specifics /#data type operations /#document operations data types in dql, you'll use three data types register , map , and attachment type by default, fields in a dql statement are assigned the register type unless otherwise specified by way of type definition following are the key characteristics register (default) map attachment last write wins merge add wins merge last write wins merge supports multiple scalar types, including primitive types, such as string and boolean , as well as a json blob, encapsulating multiple field‑value pairs that function as a single object supports embedded data types ditto attachment object declaring type definition dql type definitions describe the schema of the documents within a specific collection — defining the field types within the collection and specifying the assigned data types for each field since register is the default type in dql, you only need to specify the type definition when overriding with type map or attachment within your query to explicitly declare the type definition as non register type, add a prefix of collection and the suffix of (field1 data type, field2 data type, ) to list the fields within the collection and their associated data types dql select from collection your collection name (field1 map, field2 attachment) where field1 rating > 100 in this syntax dql collection your collection name (field1 data type, field2 data type, ) collection declares that the collection has a type definition your collection name is the name of the collection from which you want to set a definition (field1 data type, field2 data type, ) specifies the data type of each field such as register , map , or attachment select with definition dql select from collection your collection name (field1 map, field2 attachment) update with definition dql update collection your collection name (field1 map, field2 attachment) set insert with definition dql insert into collection your collection name (field1 map, field2 attachment) documents ( ) map type specifics the map (add wins map) contains fields with their own data type data types for these fields are defined using parentheses following the map keyword for example, map(sub1 data type, sub2 data type, ) dql collection your collection name (map name map(sub1 attachment, sub2 map)) single map the syntax for a single map with all other fields type register dql collection your collection name (field1 map) single attachment the syntax for a single attachment with all other fields type register dql collection your collection name (field1 attachment) map and attachment the syntax for a single map and a single attachment with all other fields type register dql collection your collection name (field1 map, field2 attachment) deeply embedded map the syntax for a document hierarchy of depth two — a single map nested with another map — with all other fields type register collection your collection name (field1 map(sub1 map)) the syntax for a document hierarchy of depth four with all other fields type register dql collection your collection name (field1 map(sub1 map(s sub1 map(s s sub1 map)))) data type operations data types have different operations available assignment operations are denoted with an equals ( = ) functional operations are denoted with an arrow ( > ) register operations the register can only be set to a specific field for example dql setting `field1` to 1 field1 = 1 map operations the map type supports inserting and tombstoning of fields using the functional operators inserting a field is an implicit operation performed by assigning a value to a field or a child of the field to assign a default value to a field, use the default() operation to perform map operations, use the arrow > operator followed by parentheses () , which contain one or more operations on child fields of the map setting or inserting field1 sub1 to 1 dql field1 > ( sub1 = 1 ) tombstoning (remove) 'field1 sub1' dql field1 > ( sub1 > tombstone() ) setting the value of 'sub1' to 1 and tombstoning 'sub2' dql field1 > ( sub1 = 1, sub2 > tombstone() ) setting the value of field1 sub1 s sub1 to 1 dql field1 > ( sub1 > ( s sub1 = 1 ) ) setting the value of field1 sub1 as default value dql field1 > ( sub1 > default() ) attachment operations to set the last write wins attachment data type, provide an attachment object dql field1 = \ attachment default value operation all data types can be set to a default value type using the default() functional operator register → null awmap → empty map {} attachment → not supported dql field1 > default() tombstone operation to remove all fields from a document, use the tombstone() functional operator dql field1 > tombstone() in ditto, fields need to be marked as "deleted" for other peers to know the field has been removed ditto does this by internally setting a tombstone metadata on the field and removing the value when tombstoning a map , all children data types are iteratively tombstoned fields that are tombstoned are ignored during subsequent dql statements while tombstoned fields are relatively inexpensive, they cannot be permanently deleted therefore, tombstoning in large numbers may cause performance to degrade document operations documents have the same data type operations as the map for syntax, see /#map operations