Central to the Elixir world is Ecto, self described as “a toolkit for database mapping”, similar to ActiveRecord in the Ruby world but Ecto is not an ORM per se.

Ecto comes with a component called Schema which is how you structure a database, it’s here that you write validations and changesets for your data. Again you can think of this sort of like the Model in Ruby on Rails. Today I learned that Ecto also has an embedded_schema function which allows you to create Ecto changesets and validations without a database table. This is handy for making sure that data is valid even if it is not going to be persisted into a database. For example if you were planning to submit form data in an API call you would want to make sure the data was valid even if you weren’t going to save it.

I’ve used this in one of my current projects to validate data on a daily email report before sending it. For more info on Ecto schemas check out the Ecto docs.

Photo by: Jan Huber