Need help with ecto?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

5.3K Stars 1.2K Forks Apache License 2.0 5.2K Commits 11 Opened issues


A toolkit for data mapping and language integrated query.

Services available


Need anything else?

Contributors list


Build Status

Ecto is a toolkit for data mapping and language integrated query for Elixir. Here is an example:

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

config :my_app, Sample.Repo, database: "ecto_simple", username: "postgres", password: "postgres", hostname: "localhost", port: "5432"

In your application code

defmodule Sample.Repo do use Ecto.Repo, otp_app: :my_app, adapter: Ecto.Adapters.Postgres end

defmodule Sample.Weather do use Ecto.Schema

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

defmodule Sample.App do import Ecto.Query alias Sample.{Weather, Repo}

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



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

Ecto is commonly used to interact with databases, such as Postgres and MySQL via Ecto.Adapters.SQL (source code). Ecto is also commonly used to map data from any source into Elixir structs, whether they are backed by a database or not.

See the getting started guide and the online documentation for more information. Other resources available are:

  • Programming Ecto, by Darin Wilson and Eric Meadows-Jönsson, which guides you from fundamentals up to advanced concepts

  • The Little Ecto Cookbook, a free ebook by Dashbit, which is a curation of the existing Ecto guides with some extra contents


You need to add both Ecto and the database adapter as a dependency to your

file. The supported databases and their adapters are:


Ecto Adapter Dependencies
PostgreSQL Ecto.Adapters.Postgres ecto_sql (requires Ecto v3.0+) + postgrex
MySQL Ecto.Adapters.MyXQL ecto_sql (requires Ecto v3.3+) + myxql
MSSQL Ecto.Adapters.Tds ecto_sql (requires Ecto v3.4+) + tds
SQLite3 Ecto.Adapters.SQLite3 ecto_sql (requires Ecto v3.5+) + ecto_sqlite3
ETS Etso ecto + etso

For example, if you want to use PostgreSQL, add to your

defp deps do
    {:ecto_sql, "~> 3.0"},
    {:postgrex, ">= 0.0.0"}

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 definition, you will need to specify the

respective to the chosen dependency. For PostgreSQL it is:
defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres,

Supported Versions

| Branch | Support | | ------ | ------------------------ | | v3.3 | Bug fixes | | v3.2 | Security patches only | | v3.1 | Unsupported from 02/2020 | | v3.0 | Unsupported from 02/2020 | | v2.2 | Security patches only | | v2.1 | Unsupported from 10/2018 | | v2.0 | Unsupported from 08/2017 | | v1.1 | Unsupported from 03/2018 | | v1.0 | Unsupported from 05/2017 |

With the version 3.0, Ecto has become API stable. This means our main focus is on providing bug fixes and updates.

Important links

Running tests

Clone the repo and fetch its dependencies:

$ git clone
$ cd ecto
$ mix deps.get
$ mix test

Note that

mix test
does not run the tests in the
folder. To run integration tests, you can clone
in a sibling directory and then run its integration tests with the
environment variable pointing to your Ecto checkout:
$ cd ..
$ git clone
$ cd ecto_sql
$ mix deps.get
$ ECTO_PATH=../ecto mix test.all

Running containerized tests

It is also possible to run the integration tests under a containerized environment using earthly:

$ earthly -P +all

You can also use this to interactively debug any failing integration tests using:

$ earthly -P -i --build-arg ELIXIR_BASE=1.8.2-erlang- +integration-test

Then once you enter the containerized shell, you can inspect the underlying databases with the respective commands:

PGPASSWORD=postgres psql -h -U postgres -d postgres ecto_test
MYSQL_PASSWORD=root mysql -h -uroot -proot ecto_test
sqlcmd -U sa -P 'some!Password'


"Ecto" and the Ecto logo are Copyright (c) 2020 Dashbit.

The Ecto logo was designed by Dane Wesolko.


Copyright (c) 2013 Plataformatec \ Copyright (c) 2020 Dashbit

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.