Packages

The typed, attribute-queryable in-memory store for ETS and Mnesia. A simple ORM with record expiry (TTL), crash resilience, and atomic take-once reads.

Current section

Files

Jump to
active_memory lib adapters helpers.ex
Raw

lib/adapters/helpers.ex

defmodule ActiveMemory.Adapter.Helpers do
@moduledoc false
alias ActiveMemory.Adapters.{Ets, Mnesia}
alias ActiveMemory.Adapters.Ets.Helpers, as: EtsHelpers
alias ActiveMemory.Adapters.Mnesia.Helpers, as: MnesiaHelpers
def build_match_head(query_map, _table_name, :ets) do
EtsHelpers.build_match_head(query_map)
end
def build_match_head(query_map, table_name, :mnesia) do
MnesiaHelpers.build_match_head(query_map, table_name)
end
def build_options(options, :ets), do: EtsHelpers.build_options(options)
def build_options(options, :mnesia), do: MnesiaHelpers.build_options(options)
def build_query_map(struct_attrs) do
Enum.with_index(struct_attrs, fn element, index ->
{strip_defaults(element), :"$#{index + 1}"}
end)
end
def build_struct_keys(struct_attrs) do
Enum.into(struct_attrs, [], fn element -> strip_defaults(element) end)
end
def set_adapter(:ets), do: Ets
def set_adapter(:mnesia), do: Mnesia
defp strip_defaults(element) when is_atom(element), do: element
defp strip_defaults({element, _defaults}) when is_atom(element), do: element
end