merkle-db.record

Core record specs and functions.

decode-entry

(decode-entry lexicoder id-field [rkey data])

Merge a record entry with an encoded key into a record data map with the decoded id in associated key fields.

encode-entry

(encode-entry lexicoder id-field record)

Project a map of record data into an entry with the encoded key and a data map with the key fields removed.

family-groups

(family-groups families data)

Build a map from family keys to maps which contain the field data for the corresponding family. Fields not grouped in a family will be added to :base. Families which had no data will have an entry with a nil value, except :base which will be an empty map.

field-merger

(field-merger spec)

Construct a new record updating function from the given merge spec. The resulting function accepts three arguments, the record id, the existing record data (or nil), and the new record data map.

If the merge spec is a function, it will be called with (f field-key old-val new-val) for each field in the record and the field-key will be set to the resulting value.

If the merge spec is a map, the keys will be used to look up a merge function for each field in the record, which will be called with (f old-val new-val). If a field has no entry in the spec, the new value is always used.

project-id

(project-id id-field record)

Projects a record into its uniquely-identifying value.

split-data

(split-data families records)

Split new record values into collections grouped by family. Each configured family and :base will have an entry in the resulting map, containing a vector of record keys to new values. The values may be nil if the record had no data for that family, an empty map if the family is :base and all the record’s data is in other families, or a map of field data belonging to that family.

{:base [[#merkle-db/key "00" {:a 123}] ...]
 :bc [[#merkle-db/key "00" {:b true, :c "cat"}] ...]
 ...}