stored

Store & retrieve structs against various backends with a simple lightweight API.


Keywords
elixir
License
MIT

Documentation

Stored

Build Status hex.pm version

Store & retrieve structs against various backends with a simple lightweight API.

By default stored ships with an ETS backend. Custom backends can be added by implementing the Stored.Backend behaviour.

Installation

def deps do
  [
    {:stored, "~> 0.0.8"}
  ]
end

Usage

defmodule Person do
  defstruct ~w(first_name last_name)a
end

defimpl Stored.Item, for: Person do
  def key(p), do: "#{p.first_name}_#{p.last_name}"
end

defmodule MyStore do
  use Stored.Store

  def after_backend_create, do: nil
  def after_put(_record), do: nil
end

{:ok, pid_default} = MyStore.start_link()
{:ok, pid_a} = MyStore.start_link(id: :a)

lebron = %Person{first_name: "Lebron", last_name: "James"}

{:ok, {r_lebron_key_default, r_lebron_default}} = MyStore.put(lebron)
{:ok, {r_lebron_key_a, r_lebron_a}} = MyStore.put(lebron, :a)

people_default = MyStore.all()
people_a = MyStore.all(:a)