Things You Might Not Have Tried with Ecto

Things You Might Not Have Tried with Ecto

If you're only using Ecto for schema modules, changeset functions, inserts, and updates, you're missing out on some great features.

Without a database: Ecto.Types can be used to convert stringly-typed data from any source to native Elixir.

Ecto migrations can represent primary keys that aren't integers and more closely reflect unique identifiers in your domain; join tables that use composite primary keys that represent what’s unique about the join instead of an arbitrary id column; accurately represent the difference between time keeping in the database and in your Ecto schemas using different timestamp configs.

The full power of Postgres is available through Ecto constraints: unique constraints can be tuned to specific conditions; exclusion constraints make ranges and scheduling easy; and check constraints are even more general and allow modeling complete validation logic in the database. Constraints ensure that different code paths can't corrupt your data and violate business rules. Leaning on the database constraints is crucial when doing bulk operations in concurrent ETL pipelines, but Luke will show how you don't need to abandon changeset and validations just because insert_all doesn't support inserting changesets.

F9a5574c99bf9d531ec99e5c5a1231cf?s=128

Luke Imhoff

March 01, 2019
Tweet