Like an ecto, but dynamic. EcDo. Ecto is a domain specific language for writing queries and interacting with databases in Elixir. Ecdo is a dynamic interface for ecto.
Ecdo was build for accessing it from erlang(elixir need to be in path) or simplify building dynamic interface, for example API.
Example of using from erlang:
'Elixir.Ecdo':query({<<"weather">>, 'Elixir.Weather'}, #{<<"where">> => [{'==', <<"weather.id">>, 1}]})
'Elixir.Ecdo':query({<<"weather">>, 'Elixir.Weather'}, #{<<"where">> => <<"weather.id == 1">>})
Example of use from elixir:
Ecdo.query {"weather", Weather}, %{"where" => "weather.id == 1"}
Simple example of building API:
defmodule Weather.Api do
def json(json) do
map = Poison.decode! json
# may be restrict something
Ecdo.query({"weather", Weather}, map) |> Repo.all
end
end
# Example of use:
Weather.Api.json ~S({"where": "weather.temp_lo > 25", "limit": 10})
Due to some direct manipulations with ecto intern AST, ecdo aims to have always close to 100% of test cover.
You need to add both Ecdo and the database adapter as a dependency to your mix.exs
file. The supported databases and their adapters are:
Database | Ecto Adapter | Dependency |
---|---|---|
PostgreSQL | Ecto.Adapters.Postgres | postgrex |
MySQL | Ecto.Adapters.MySQL | mariaex |
MSSQL | Tds.Ecto | tds_ecto |
SQLite3 | Sqlite.Ecto | sqlite_ecto |
For example, if you want to use MySQL, add to your mix.exs
file:
defp deps do
[{:mariaex, ">= 0.0.0"},
{:ecdo, "~> 0.1.0"}]
end
and update your applications list to include both projects:
def application do
[applications: [:mariaex, :ecdo]]
end