elixir-ecto/ecto

Name: ecto

Owner: elixir-ecto

Description: A database wrapper and language integrated query for Elixir

Created: 2013-06-12 18:42:06.0

Updated: 2018-01-18 22:04:46.0

Pushed: 2018-01-18 20:34:19.0

Homepage: https://hexdocs.pm/ecto

Size: 10231

Language: Elixir

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Ecto

Build Status Inline docs

Ecto is a domain specific language for writing queries and interacting with databases in Elixir. Here is an example:

 your config/config.exs file
ig :my_app, ecto_repos: [Sample.Repo]

ig :my_app, Sample.Repo,
apter: Ecto.Adapters.Postgres,
tabase: "ecto_simple",
ername: "postgres",
ssword: "postgres",
stname: "localhost",
rt: "5432"

 your application code
odule Sample.Repo do
e Ecto.Repo,
otp_app: :my_app


odule Sample.Weather do
e Ecto.Schema

hema "weather" do
field :city     # Defaults to type :string
field :temp_lo, :integer
field :temp_hi, :integer
field :prcp,    :float, default: 0.0
d


odule Sample.App do
port Ecto.Query
ias Sample.Weather
ias Sample.Repo

f keyword_query do
query = from w in Weather,
     where: w.prcp > 0 or is_nil(w.prcp),
     select: w
Repo.all(query)
d

f pipe_query do
Weather
|> where(city: "Kraków")
|> order_by(:temp_lo)
|> limit(10)
|> Repo.all
d

See the getting started guide and the online documentation.

Also checkout the “What's new in Ecto 2.1” free ebook to learn more about many features since Ecto 2.1 such as many_to_many, schemaless queries, concurrent testing, upsert and more. Note the book still largely applies to Ecto 3.0 as the major change in Ecto 3.0 was the removal of the outdated Ecto datetime types in favor of Elixir's Calendar types.

Usage

You need to add both Ecto and the database adapter as a dependency to your mix.exs file. The supported databases and their adapters are:

Database | Ecto Adapter | Dependency | Ecto 2.0 compatible? :———-| :——————— | :—————————-| :——————- PostgreSQL | Ecto.Adapters.Postgres | postgrex | Yes MySQL | Ecto.Adapters.MySQL | mariaex | Yes MSSQL | MssqlEcto | mssql_ecto | Yes SQLite     | Sqlite.Ecto2   | sqlite_ecto2 | Yes Mnesia     | EctoMnesia.Adapter   | ecto_mnesia   | Yes

For example, if you want to use PostgreSQL, add to your mix.exs file:

 deps do

{:postgrex, ">= 0.0.0"},
{:ecto, "~> 2.1"}


Then run mix deps.get in your shell to fetch the dependencies. If you want to use another database, just choose the proper dependency from the table above.

Finally, in the repository configuration, you will need to specify the adapter: respective to the chosen dependency. For PostgreSQL it is:

ig :my_app, Repo,
apter: Ecto.Adapters.Postgres,
.

We are currently looking for contributions to add support for other SQL databases and folks interested in exploring non-relational databases too.

Supported Versions

| Branch | Support | | —— | ———————— | | v3.0 | In development | | v2.2 | Bug fixes | | v2.1 | Security patches only | | v2.0 | Unsupported from 08/2017 | | v1.1 | Security patches only | | v1.0 | Unsupported from 05/2017 |

Important links
Contributing

Contributions are welcome! In particular, remember to:

Running tests

Clone the repo and fetch its dependencies:

t clone https://github.com/elixir-ecto/ecto.git
 ecto
x deps.get
x test

Besides the unit tests above, it is recommended to run the adapter integration tests too:

n only PostgreSQL tests (PostgreSQL >= 9.5 is preferred for testing all Postgres features)
ENV=pg mix test

n all tests (unit and all adapters)
test.all
Building docs
X_ENV=docs mix docs
Copyright and License

“Ecto” and the Ecto logo are copyright (c) 2012 Plataformatec.

The Ecto logo was designed by Dane Wesolko.

Ecto source code is licensed under the Apache 2 License.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.