Skip to content

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

License

Notifications You must be signed in to change notification settings

fremantle-industries/stored

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages