View Source ActiveMemory.Adapters.Mnesia (ActiveMemory v0.3.1)

An adapter for storing structs in Mnesia

Link to this section Summary

Functions

Return all structs stored in a table.

Create a table in Mnesia 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

@spec all(atom()) :: [map()]

Return all structs stored in a table.

  iex:> DogStore.all(Dog)
  [%Dog{}, %Dog{}]
@spec create_table(atom()) :: :ok | {:error, any()}

Create a table in Mnesia 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
  end

Once the ActiveMemory.Table is defined then the in memory table can be created.

  iex:> PeopleStore.create_table(Test.Support.People.Person)
  :ok
@spec delete(map(), atom()) :: :ok | {:error, any()}

Delete a struct from a table.

  iex:> PeopleStore.delete(%Person{}, Person)
  :ok
@spec delete_all(atom()) :: true | any()

Delete all structs from a table.

  iex:> PeopleStore.delete_all(Person)
  true
@spec one(map() | tuple(), atom()) :: {:ok, map()} | {:error, any()}

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{}}
Link to this function

select(query_map, table)

View Source
@spec select(map() | tuple(), atom()) :: {:ok, [map()]} | {:error, any()}

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{}]}
@spec write(map(), atom()) :: {:ok, map()} | {:error, any()}

Save a struct to a table.

  iex:> DogStore.write(%Dog{name: "gem", breed: "Shaggy Black Lab"})
  {:ok, %Dog{}}