Skip to content

Data Model: Embedded Objects

Paula Gearon edited this page Oct 10, 2018 · 2 revisions

Embedded Objects

Single Entity

Embedded objects in JSON are provided with their own IDs, which are then referenced directly.

[{"string_data": "A string",
  "number_data": 5,
  "inner_data": {"value": 1}}]

Graph tuples:

[:mem/node-0001 :string_data "A string"]
[:mem/node-0001 :number_data 5]
[:mem/node-0001 :inner_data :mem/node-0002]
[:mem/node-0002 :value 1]

Pabu:

string_data(mem/node-0001, "A string").
number_data(mem/node-0001, 5).
inner_data(mem/node-0001, mem/node-0002).
value(mem/node-0002, 1).

Embedded Arrays

Embedded arrays in JSON are formed from entities that form a linked list. Each entity is given its own ID. The linked list properties are:

  • :naga/first - the value at that position in the list
  • :naga/rest - the reference to the next element of the list. If missing then the entity is the final one in the list.
  • :naga/contains - indicates all values in the list.

The :naga/contains property only appears on the first element of the list, and links the first element of the list to every value. It represents the transitive closure of the :naga/rest property followed by :naga/first. This provides an easy way to reference every member of the list without having to specify a list position. Note that this is the only property in the Naga data model that has multiple values for a single entity.

Note: If the graph database only supports typed properties, then the :naga/first and :naga/contains properties will be replaced with specific ones for each type. e.g. Datomic uses :naga/first-l for long values and :naga/first-s for strings. It should not be necessary to use these variations explicitly, as the query engine will translate automatically. See Datomic for details.

[{"string_data": "A string",
  "array_data": [4, 5, 6]}]

Graph tuples:

[:mem/node-0001 :string_data "A string"]
[:mem/node-0001 :array_data :mem/node-0002]
[:mem/node-0002 :naga/first 4]
[:mem/node-0002 :naga/rest :mem/node-0003]
[:mem/node-0003 :naga/first 5]
[:mem/node-0003 :naga/rest :mem/node-0004]
[:mem/node-0004 :naga/first 6]
[:mem/node-0002 :naga/contains :mem/node-0003]
[:mem/node-0002 :naga/contains :mem/node-0004]

Pabu:

string_data(mem/node-0001, "A string").
array_data(mem/node-0001, mem/node-0002).
naga/first(mem/node-0002, 4).
naga/rest(mem/node-0002, mem/node-0003).
naga/first(mem/node-0003, 5).
naga/rest(mem/node-0003, mem/node-0004).
naga/first(mem/node-0004, 6).
naga/contains(mem/node-0002, mem/node-0003).
naga/contains(mem/node-0002, mem/node-0004).
Clone this wiki locally