amnesia v0.2.2 Amnesia.Database

Summary

Macros

Define a table in the database with the given name, attributes and options

Macros

deftable(name, attributes \\ nil, opts \\ [], do_block \\ [])

Specs

deftable(term, atom, [atom | {atom, any}], Keyword.t, Keyword.t) :: none

Define a table in the database with the given name, attributes and options.

If only a name is given, it will forward declare a table.

The created table will actually be a record, so you can define functions on it like you would normally do for a record, various helper methods are added by default.

Options

  • :indices specifies a list of additional indices to use instead of the first attribute.
  • :type specifies the type of the table, it can be :set, :ordered_set and :bag, the default is :set
  • :mode specifies the access mode, it can be :both and :read!, the default is :both
  • :majority specifies the majority of the table, the default is false
  • :priority specifies the load priority of the table
  • :local specifies if the table is local, default is false

Example

use Amnesia

defdatabase Foo do
  deftable Bar, [:id, :a], type: :bag

  deftable Baz, [:id, :a, :b] do
    def foo(self)
      42
    end
  end
end