View Source ActiveMemory.Store (ActiveMemory v0.2.0)
The Store
store-api
Store API
Store.all/0
Get all records storedStore.delete/1
Delete the record providedStore.delete_all/0
Delete all records storedStore.one/1
Get one record matching either an attributes search ormatch
queryStore.select/1
Get all records matching either an attributes search ormatch
queryStore.withdraw/1
Get one record matching either an attributes search ormatch
query, delete the record and return itStore.write/1
Write a record into the memmory table
seeding
Seeding
When starting a Store
there is an option to provide a valid seed file and have the Store
auto load seeds contained in the file.
defmodule MyApp.People.Store do
use ActiveMemory.Store,
table: MyApp.People.Person,
seed_file: Path.expand("person_seeds.exs", __DIR__)
end
before-init
Before init
All stores are GenServers
and have init
functions. While those are abstracted you can still specify methods to run during the init
phase of the GenServer startup. Use the before_init
keyword and add the methods as tuples with the arguments.
defmodule MyApp.People.Store do
use ActiveMemory.Store,
table: MyApp.People.Person,
before_init: [{:run_me, ["arg1", "arg2", ...]}, {:run_me_too, []}]
end
initial-state
Initial State
All stores are GenServers
and thus have a state. The default state is an array as such:
%{started_at: "date time when first started", table: MyApp.People.Store}
This default state can be overwritten with a new state structure or values by supplying a method and arguments as a tuple to the keyword initial_state
.
defmodule MyApp.People.Store do
use ActiveMemory.Store,
table: MyApp.People.Person,
initial_state: {:initial_state_method, ["arg1", "arg2", ...]}
end