Skip to content

Logflare/ecto3_mnesia

Repository files navigation

pipeline status coverage report

Ecto Mnesia Adapter

This adapter brings the strength of Ecto providing validation, and persistance layer to interact to Mnesia databases.

Mnesia is Distributed Database Management System shipped with Erlang runtime. Be aware of strengths and weaknesses listed in erlang documentation before thinking about using it.

What works

  1. Queries
  • Basic all queries
  • Select queries
  • Simple where queries
  • and/or/in in where clauses
  • Bindings
  • Fragments
  • Limit/Offset queries
  • Sort by one field
  • Sort by multiple fields
  • One level joins
  • Deeper joins
  1. Writing operations
  • insert/insert_all
  • update/update_all
  • delete/delete_all
  • Auto incremented ids
  • Binary ids
  • Delete without primary key
  • Unique constraint

Note: supports only on_conflict: :raise/:update_all

  1. Associations
  • has_one associations
  • has_many associations
  • belongs_to associations
  • many_to_many associations
  1. Transactions
  • Create transactions
  • Rollback transactions

Instalation

You can include ecto3_mnesia in your dependencies as follow:

  defp deps do
    ...
    {:ecto3_mnesia, "~> 0.2.0"},
    ...
  end

Then configure your application repository to use Mnesia adapter as follow:

# ./lib/my_app/repo.ex
defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Mnesia
end

Migrations

Migrations are not supported yet, you can use mnesia abilities to create tables in a script.

# ./priv/repo/mnesia_migration.exs
IO.inspect :mnesia.create_table(:table_name, [
  disc_copies: [node()],
  record_name: MyApp.Context.Schema,
  attributes: [:id, :field, :updated_at, :inserted_at],
  type: :set
])

Then run the script with mix mix run ./priv/repo/mnesia_migration.exs

Notice that the table before MUST be defined according to the corresponding schema

defmodule MyApp.Context.Schema do
  ...
  schema "table_name" do
    field :field, :string

    timestamps()
  end
  ...
end

Tests

You can run the tests as any mix package running

git clone https://gitlab.com/patatoid/ecto3_mnesia.git
cd ecto3_mnesia
mix deps.get
mix test --trace

Thanks

Many thanks to the contributors of ecto_sql and ecto_mnesia for their work on those topics that have inspired some of the design of this library

Contributing

Contributions of any kind are welcome :)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages