Ecto3 Mnesia v0.2.1 Ecto.Adapters.Mnesia View Source
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
- Queries
- [x] Basic all queries
- [x] Select queries
- [x] Simple where queries
- [x] and/or/in in where clauses
- [x] Bindings
- [ ] Fragments
- [x] Limit/Offset queries
- [x] Sort by one field
- [ ] Sort by multiple fields
- [x] One level joins
- [ ] Deeper joins
- Writing operations
- [x] insert/insert_all
- [x] update/update_all
- [x] delete/delete_all
- [x] Auto incremented ids
- [x] Binary ids
Note: supports only on_conflict: :raise/:update_all
- Associations
- [x] has_one associations
- [x] has_many associations
- [x] belongs_to associations
- [ ] many_to_many associations
- Transactions
- [x] Create transactions
- [x] Rollback transactions
Instalation
You can include ecto3_mnesia in your dependencies as follow:
defp deps do
...
{:ecto3_mnesia, "~> 0.1.0"}, # not released yet
...
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