代码之家  ›  专栏  ›  技术社区  ›  Farshid Ashouri

如何在长生不老药中创建记忆表?

  •  1
  • Farshid Ashouri  · 技术社区  · 6 年前

    如何创建 :mnesia 有没有办法在创建时添加索引?

    例如,我想创建一个属性很少的用户表。

    2 回复  |  直到 6 年前
        1
  •  2
  •   Sheharyar    6 年前

    在Elixir中使用Erlang的Mnesia接口很快就会变得很烦人。另一种选择是使用类似 Memento , Amnesia EctoMnesia .

    下面是如何在Memento中定义表:

    defmodule MyApp.User do
      use Memento.Table, attributes: [:id, :name, :email], index: [:email]
    ennd
    

    Memento.Table.create!(MyApp.User)
    

    完全披露: 我是这本书的作者 Memento .

        2
  •  2
  •   Farshid Ashouri    6 年前

    :mnesia.start
    :mnesia.create_table(
        User, 
       [{:disc_copies, [node()]}, 
         attributes: [:id, :name, :job], 
         index: [:name, :job]
       ])
    

    注意,默认情况下第一个属性将被索引。 elixirschool.com/en/lessons/specifics/mnesia/#starting-mnesia

    您还需要在创建表之前创建模式。