https://github.com/fremantle-industries/stored
Store & retrieve structs against various backends with a simple lightweight API
https://github.com/fremantle-industries/stored
elixir
Last synced: 2 months ago
JSON representation
Store & retrieve structs against various backends with a simple lightweight API
- Host: GitHub
- URL: https://github.com/fremantle-industries/stored
- Owner: fremantle-industries
- License: mit
- Created: 2019-08-30T21:11:04.000Z (almost 7 years ago)
- Default Branch: main
- Last Pushed: 2023-03-01T16:57:50.000Z (over 3 years ago)
- Last Synced: 2026-03-14T22:22:11.644Z (3 months ago)
- Topics: elixir
- Language: Elixir
- Homepage:
- Size: 91.8 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stored
[](https://github.com/rupurt/stored/actions?query=workflow%3Atest)
[](https://hex.pm/packages/stored)
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
```elixir
def deps do
[
{:stored, "~> 0.0.8"}
]
end
```
## Usage
```elixir
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)
```