An object is a collection of named fields and values.
As a record is essentially an object with a required id
field that can be created, updated, or deleted, they can be worked with in almost exactly the same way as a standalone object.
A field of an object can be of any value type, including another object, with no limit to the depth of any nested objects or values within. This allows objects and arrays tno be stored within each other in order to model complex data scenarios.
CREATE person SET metadata = { interest_level: 83.67, information: { age: 23, gender: 'm', }, marketing: true, activities: [ "clicked link", "contact form", "read email", "viewed website", "viewed website", "viewed website", "read email", ] };
Similar to record IDs, field names can be constructed from ASCII characters, underscores, and numbers. To create a field name with complex characters, backticks can be used.
CREATE ONLY user SET my_name = 'name'; CREATE ONLY user SET `mi_nómine😊` = 'name';
Output-------- Query -------- { id: user:nronupvxvdm7r1n5hlzm, my_name: 'name' } -------- Query 2 -------- { id: user:eb5pu7u9g67dy773hsv9, "mi_nómine😊": 'name' }
Inside a standalone object, non-ASCII field names can also be set by using a string.
SELECT * FROM ONLY { "mi_nómine": "name" };
Output{ "mi_nómine": 'name' }
A field created from an operation will have a field name that represents the operation(s) used to construct it.
SELECT math::mean(temps), [ math::min(temps), math::max(temps) ] FROM { temps: [-5, 8, 9] };
Output[ { "[math::min(temps), math::max(temps)]": [ -5, 9 ], "math::mean": 4 } ]
Using AS
allows these automatically calculated field names to be replaced with custom names.
SELECT math::mean(temps) AS mean_temps, [ math::min(temps), math::max(temps) ] AS avg_temps FROM { temps: [-5, 8, 9] };
Output[ { "avg_temps": [ -5, 9 ], "mean_temps": 4 } ]