Subaru.Store.Behaviour behaviour (subaru v0.1.0)

View Source

Common contract for any Subaru key-value storage backend. This behaviour comes from the vision.md design document and is the foundation for plugging different datastores.

Summary

Callbacks

Persist all stored data to the given path.

Clear all data from the storage backend.

Dump all vertices and edges currently in the store.

Initialize the storage backend with the given options.

Returns a lazy enumerable of {key, value} tuples for all keys with the given prefix.

Restore data previously persisted via backup/1.

Executes the given function inside a read-only snapshot if the backend supports snapshots. Defaults to just running the function.

Stop the storage backend.

Types

key()

@type key() :: binary()

opts()

@type opts() :: keyword()

value()

@type value() :: binary()

Callbacks

backup(t)

@callback backup(String.t()) :: :ok | {:error, term()}

Persist all stored data to the given path.

clear(nodes)

@callback clear(nodes :: [atom()]) :: :ok

Clear all data from the storage backend.

export()

@callback export() :: {:ok, map()} | {:error, term()}

Dump all vertices and edges currently in the store.

get_edges(src_id, etype)

@callback get_edges(src_id :: any(), etype :: atom()) :: {:ok, [map()]} | {:error, term()}

get_vertex(id)

@callback get_vertex(id :: any()) :: {:ok, map()} | :not_found

init(opts)

@callback init(opts()) :: :ok | {:error, term()}

Initialize the storage backend with the given options.

iterate(prefix, opts)

@callback iterate(prefix :: binary(), opts()) :: Enumerable.t()

Returns a lazy enumerable of {key, value} tuples for all keys with the given prefix.

put_edge(src_id, etype, dst_id, map)

@callback put_edge(src_id :: any(), etype :: atom(), dst_id :: any(), map()) :: :ok

put_vertex(id, map)

@callback put_vertex(id :: any(), map()) :: :ok

restore(t)

@callback restore(String.t()) :: :ok | {:error, term()}

Restore data previously persisted via backup/1.

snapshot(function)

@callback snapshot((-> any())) :: any()

Executes the given function inside a read-only snapshot if the backend supports snapshots. Defaults to just running the function.

stop()

@callback stop() :: :ok

Stop the storage backend.

transaction(function)

@callback transaction((... -> any())) :: any()

write_batch(list)

@callback write_batch([{:put | :del, key(), value()}]) :: :ok