View Source ActiveMemory.Store (ActiveMemory v0.3.1)
The Store
store-api
Store API
Store.all/0Get all records storedStore.delete/1Delete the record providedStore.delete_all/0Delete all records storedStore.one/1Get one record matching either an attributes search ormatchqueryStore.select/1Get all records matching either an attributes search ormatchqueryStore.withdraw/1Get one record matching either an attributes search ormatchquery, delete the record and return itStore.write/1Write 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 a map as such:
%{started_at: "date time when first started", table_name: MyApp.People.Person}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. The method must return {:ok, new_state}.
defmodule MyApp.People.Store do
use ActiveMemory.Store,
table: MyApp.People.Person,
initial_state: {:initial_state_method, ["arg1", "arg2", ...]}
end