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, ...

Get Functional Programming: A PragPub Anthology now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.