merkle-db.table

Tables are named top-level containers of records. Generally, a single table corresponds to a certain ‘kind’ of data. Tables also contain configuration determining how keys are encoded and records are stored.

ITable

protocol

Protocol for an immutable table of record data.

members

delete

(delete table id-keys)

Remove some records from the table, identified by a collection of id keys. Returns an updated table.

dirty?

(dirty? table)

Return true if the table has local non-persisted modifications.

flush!

(flush! table)(flush! table opts)

Ensure that all local state has been persisted to the storage backend. Returns an updated persisted table.

Options may include:

  • :apply-patch? If true, the current patch data will be merged into the main data tree and the returned table will have no patch link.

insert

(insert table records)(insert table records opts)

Insert some record data into the database, represented by a collection of record data maps. Returns an updated table.

Options may include:

  • :update-field A function which will be called with (f field-key old-val new-val), and should return the new value to use for that field. By default, new-val is used directly.
  • :update-record A function which will be called with (f record-key old-data new-data), and should return the data map to use for the record. By default, this merges the data maps and removes nil-valued fields.

keys

(keys table)(keys table opts)

Scan the table, returning keys of the stored records which match the given options. Returns a lazy sequence of keys, or nil if the table is empty.

If min and max keys are given, only records within the bounds will be returned (inclusive). A nil min or max implies the beginning or end of the data, respectively.

Options may include:

  • :min-key Return records with keys equal to or greater than the marker.
  • :max-key Return records with keys equal to or less than the marker.
  • :reverse (NYI) Reverse the order the keys are returned in.
  • :offset Skip this many records in the output.
  • :limit Return at most this many records.

list-partitions

(list-partitions table)

List the partitions which comprise the table. Returns a sequence of partition nodes.

read

(read table id-keys)(read table id-keys opts)

Read a set of records from the database, returning data for each present record. Returns a sequence of record data maps.

Options may include:

  • :fields Only return data for the selected set of fields. If provided, only records with data for one or more of the fields are returned, otherwise all fields and records are returned.

read-partition

(read-partition table partition-id opts)

Read all the records in the identified partition.

scan

(scan table)(scan table opts)

Scan the table, returning data from records which match the given options. Returns a lazy sequence of record data maps, sorted by key.

If min and max keys or indices are given, only records within the bounds will be returned (inclusive). A nil min or max implies the beginning or end of the data, respectively.

Options may include:

  • :fields Only return data for the selected set of fields. If provided, only records with data for one or more of the fields are returned, otherwise all fields and records (including empty ones) are returned.
  • :min-key Return records with keys equal to or greater than the marker.
  • :max-key Return records with keys equal to or less than the marker.
  • :reverse (NYI) Reverse the order the keys are returned in.
  • :offset Skip this many records in the output.
  • :limit Return at most this many records.