Changesets and updating work

In Elixir, Ecto is the tool you'd most likely use to work with a database.

changesets and updating work-70changesets and updating work-89

Where Active Record returns a model in all cases, Ecto returns either {:ok, model} or {:error, changeset}. To understand why, let's take a peek under the hood.Ecto uses the changeset to perform validations, rather than deal with validations inside the model. For now, let's find, update, and delete our post: ; those familiar with Active Record will correctly guess that these act differently by raising exceptions for their error cases. Typical ruby applications using Active Record are single threaded, and when you query the database, your process is blocked until you receive a response from the database.When using Ruby on Rails, this works out - you typically can't respond to a web request until you've got all the data, and you can start multiple ruby processes to handle requests concurrently.The repository provides an interface to execute queries against a database.Functions like , with the caveat that Active Record methods are executed within the model class or instance, while Ecto expects you to pass a model, query, or changeset to its functions.

Let's create a simple post model to explore further.

First, create a migration using This exposes a difference between the two libraries.

When using Elixir, it's clear that a lot of attention has been paid to productivity - given their age, tools like mix and iex are incredibly mature.

However, tools are only a part of the story; a big piece of the productivity of a language is the amount and quality of the libraries that are available for it.

Like the majority of Rails developers, I use Active Record to work with databases.

Although I have my fair share of gripes, it's still invaluable in building web applications.