View Source ActiveMemory.Adapters.Ets (ActiveMemory v0.3.2)
An adapter for storing structs in ETS
Link to this section Summary
Functions
Return all structs stored in a table.
Create a table in ETS using an ActiveMemory.Table. This function will take in the ActiveMemory.Table and parse the options for the table. Example Table (without auto generated uuid)
Delete a struct from a table.
Delete all structs from a table.
Find a single struct in a table using either a map query search or ActiveMemory.Query.MatchSpec. using a map query
Find a single struct in a table using either a map query search or ActiveMemory.Query.MatchSpec. using a map query
Save a struct to a table.
Link to this section Functions
Return all structs stored in a table.
iex:> DogStore.all(Dog)
[%Dog{}, %Dog{}]
Create a table in ETS using an ActiveMemory.Table. This function will take in the ActiveMemory.Table and parse the options for the table. Example Table (without auto generated uuid):
defmodule Test.Support.People.Person do
use ActiveMemory.Table,
options: [index: [:last, :cylon?]]
attributes do
...
end
endOnce the ActiveMemory.Table is defined then the in memory table can be created.
iex:> PeopleStore.create_table(Test.Support.People.Person)
:ok
Delete a struct from a table.
iex:> PeopleStore.delete(%Person{}, Person)
:ok
Delete all structs from a table.
iex:> PeopleStore.delete_all(Person)
true
Find a single struct in a table using either a map query search or ActiveMemory.Query.MatchSpec. using a map query
iex:> DogStore.one(%{name: "gem", breed: "Shaggy Black Lab"})
{:ok, %Dog{}}with ActiveMemory.Query.MatchSpec
iex:> DogStore.one(match(:name == "gem" and :breed == "Shaggy Black Lab"))
{:ok, %Dog{}}
Find a single struct in a table using either a map query search or ActiveMemory.Query.MatchSpec. using a map query
iex:> DogStore.select(%{name: "gem", breed: "Shaggy Black Lab"})
{:ok, [%Dog{}, %Dog{}]}with ActiveMemory.Query.MatchSpec
iex:> DogStore.select(match(:name == "gem" and :breed == "Shaggy Black Lab"))
{:ok, [%Dog{}, %Dog{}]}
Save a struct to a table.
iex:> DogStore.write(%Dog{name: "gem", breed: "Shaggy Black Lab"})
{:ok, %Dog{}}