All Projects → Nebo15 → Ecto_mnesia

Nebo15 / Ecto_mnesia

Licence: mit
Ecto adapter for Mnesia Erlang term database.

Programming Languages

elixir
2628 projects
erlang
1774 projects

Projects that are alternatives of or similar to Ecto mnesia

rbmq
Simple API for spawning RabbitMQ Producers and Consumers.
Stars: ✭ 20 (-91.03%)
Mutual labels:  hex, package
ecto commons
Ecto common validators for Date, Time, URLs, Emails, PostalCodes, Phone Numbers, Luhn checks, etc.
Stars: ✭ 33 (-85.2%)
Mutual labels:  hex, ecto
ecto profiler
Project for Ecto DB profiling
Stars: ✭ 16 (-92.83%)
Mutual labels:  hex, ecto
Coherence
Coherence is a full featured, configurable authentication system for Phoenix
Stars: ✭ 1,207 (+441.26%)
Mutual labels:  package, hex
Mssqlex
Microsoft SQL Server Adapter for Elixir
Stars: ✭ 38 (-82.96%)
Mutual labels:  ecto, hex
Confex
Useful helper to read and use application configuration from environment variables.
Stars: ✭ 272 (+21.97%)
Mutual labels:  package, hex
ecto trail
EctoTrail allows to store Ecto changeset changes in a separate audit_log table.
Stars: ✭ 51 (-77.13%)
Mutual labels:  hex, ecto
Cloak
Elixir encryption library designed for Ecto
Stars: ✭ 413 (+85.2%)
Mutual labels:  ecto, hex
Ex admin
ExAdmin is an auto administration package for Elixir and the Phoenix Framework
Stars: ✭ 1,180 (+429.15%)
Mutual labels:  package, hex
Rethinkdb ecto
RethinkDB adapter for Ecto.
Stars: ✭ 112 (-49.78%)
Mutual labels:  ecto, adapter
Blogetc
Easily add a full Laravel blog (with built in admin panel and public views) to your laravel project with this simple package.
Stars: ✭ 198 (-11.21%)
Mutual labels:  package
Progressr
三 R package: An Inclusive, Unifying API for Progress Updates
Stars: ✭ 198 (-11.21%)
Mutual labels:  package
Ex audit
Ecto auditing library that transparently tracks changes and can revert them.
Stars: ✭ 214 (-4.04%)
Mutual labels:  ecto
Please Upgrade Node
💁 Show a message to your users to upgrade Node instead of a stacktrace
Stars: ✭ 219 (-1.79%)
Mutual labels:  package
Multiselectadapter
MultiSelectAdapter可以让你的Adapter快速实现多选和批量操作
Stars: ✭ 195 (-12.56%)
Mutual labels:  adapter
Laravel Multisite
Multiple sites on one codebase
Stars: ✭ 214 (-4.04%)
Mutual labels:  package
Mongodb Adapter
MongoDB adapter for Casbin
Stars: ✭ 194 (-13%)
Mutual labels:  adapter
Npmvet
A simple CLI tool for vetting npm package versions
Stars: ✭ 193 (-13.45%)
Mutual labels:  package
Skeleton Nova Tool
A skeleton repository for Spatie's Nova Packages
Stars: ✭ 191 (-14.35%)
Mutual labels:  package
Commonadapter
一个适用于ListView/GridView/RecyclerView的Adapter库,简化大量重复代码,支持多种布局,可自定义图片加载的实现。
Stars: ✭ 219 (-1.79%)
Mutual labels:  adapter

Ecto adapter for Mnesia Erlang term database

Hex.pm Downloads Latest Version License Build Status Coverage Status Ebert

Ecto 2.X adapter for Mnesia Erlang term database. In most cases it can be used as drop-in replacement for other adapters.

Supported features:

  • Compatible Ecto.Repo API.
  • Automatically converts Ecto.Query structs to Erlang match_spec.
  • Emulated query.select and query.order_bys, select .. in [..]. (Emulating is slow for any large dataset, O(n * log n).)
  • Auto-generated (via sequence table) :id primary keys.
  • Migrations and database setup via Ecto.Migrations.
  • Transactions.
  • Secondary indexes.

Planned features:

  • Native primary key and unique index constraints.
  • Custom primary keys.
  • Other transactional contexts.

Not supported features (create issue and vote if you need them):

  • Type casting. Mnesia can store any data in any field, including strings, numbers, atoms, tuples, floats or even PID's. All types in your migrations will be silently ignored.
  • Mnesia clustering and auto-clustering.
  • Lookups in json fields.
  • Schemaless queries.
  • Composite primary keys.
  • Unique/all other constraints (including associations).
  • JOINs.
  • min, max, avg and other aggregation functions.
  • Intervals.

In general. This adapter is still not passing all Ecto integration tests and in active development. But it already can be helpful in simple use-cases.

Why Mnesia?

We have a production task that needs low read-latency database and our data fits in RAM, so Mnesia is the best choice: it's part of OTP, shares same space as our app does, work fast in RAM and supports transactions (it's critical for fintech projects).

Why do we need an adapter? We don't want to lock us to any specific database, since requirements can change. Ecto allows to switch databases by simply modifying the config, and we might want to go back to Postres or another DB.

Clustering and using Mnesia for your project

If you use Mnesia - you either get a distributed system from day one or a single node with low availability. Very few people really want any of that options. Specifically Mnesia it's neither an AP, nor a CP database; requires you to handle network partitions (split brains) manually; has much less documentation available compared to a more common databases (like PostgreSQL).

Please, pick your tools wisely and think through how you would use them in production.

Mnesia configuration from config.exs

config :ecto_mnesia,
  host: {:system, :atom, "MNESIA_HOST", Kernel.node()},
  storage_type: {:system, :atom, "MNESIA_STORAGE_TYPE", :disc_copies}

config :mnesia,
  dir: 'priv/data/mnesia' # Make sure this directory exists

Notice that {:system, [TYPE], ENV_NAME, default_value} tuples can be replaced with any raw values.

They tell adapter to read configuration from environment in run-time, so you will be able to set MNESIA_HOST and MNESIA_STORAGE_TYPE environment variables, which is very useful when you releasing app in production and don't want to rebuild all code on each config change.

If you want to know more how this tool works take look at Confex package.

Storage Types

  • :disc_copies - store data in both RAM and on disc. Recommended value for most cases.
  • :ram_copies - store data only in RAM. Data will be lost on node restart. Useful when working with large datasets that don't need to be persisted.
  • :disc_only_copies - store data only on disc. This will limit database size to 2GB and affect adapter performance.

Table Types (Engines)

In migrations you can select which kind of table you want to use:

create_if_not_exists table(:my_table, engine: :set) do
  # ...
end

Supported types:

  • :set - expected your records to have at least one unique primary key that should be in first column.
  • :ordered_set - default type. Same as :set, but Mnesia will store data in a table will be ordered by primary key.
  • :bag - expected all records to be unique, but no primary key is required. (Internally, it will use first field as a primary key).
Ordered Set Performance

Ordered set comes in a cost of increased complexity of write operations:

Set

Operation Average Worst Case
Space O(n) O(n)
Search O(1) O(n)
Insert O(1) O(n)
Delete O(1) O(n)

Ordered Set

Operation Average Worst Case
Space O(n) O(n)
Search O(log n) O(n)
Insert O(log n) O(n)
Delete O(log n) O(n)

Installation

It is available in Hex, the package can be installed as:

  1. Add ecto_mnesia to your list of dependencies in mix.exs:
def deps do
  [{:ecto_mnesia, "~> 0.9.0"}]
end
  1. Ensure ecto_mnesia is started before your application:
def application do
  [applications: [:ecto_mnesia]]
end
  1. Use EctoMnesia.Adapter as your Ecto.Repo adapter:
config :my_app, MyRepo,
  adapter: EctoMnesia.Adapter
  1. Optionally set custom Mnesia data dir (don't forget to create it):
config :mnesia, :dir, 'priv/data/mnesia'

The docs can be found at https://hexdocs.pm/ecto_mnesia.

Thanks

We want to thank meh for his Amnesia package that helped a lot in initial Mnesia investigations. Some pieces of code was copied from his repo.

Also big thanks to josevalim for Elixir, Ecto and active help while this adapter was developed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].