O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Customizing Persistence

If you want to create persistent entities, you need to show Blacksmith how to save single entities and lists of entities. For example, you might want to save records using Ecto, a persistence engine for Elixir. Here’s how you’d go about it. Let’s say you’re starting with an Ecto schema, like this:

 ~~~
 defmodule User do
  use Ecto.Model
 
  schema "users" do
  field :first_name, :string
  field :last_name, :string
  field :email, :string
  end
 end
 ~~~

We’re creating a simple database-backed entity. The database schema and model will both have corresponding fields.

Next, we create a Forge. Our Forge will specify the User struct for Ecto, as well as a couple of functions that Ecto could use to save one or many entities, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required