Introducing “Programming Ecto”: Your Tour Guide for the Ecto Database Library

Darin Wilson
Red Shift
Published in
5 min readApr 22, 2019

--

I am pleased and proud to announce that Programming Ecto, the book I co-authored with Eric Meadows-Jönsson, is officially complete and available through Pragmatic Bookshelf!

Wondering what’s it all about? Read on to find out how the book came to be, and what you can expect to find inside.

Where It All Began

Ecto is a database library for the Elixir programming language. It’s included with the Phoenix web development framework, so that’s where a lot of developers (including me) first encounter it, but it’s independent of Phoenix and you can use it in any Elixir application that needs to access a relational database.

When I first starting learning Ecto, I felt like there was a gap in the learning materials I found at the time. There were some talks online, but they were high-level and talked about Ecto’s capabilities in a general way.

I started reading through the excellent documentation that ships with Ecto, but looking over the alphabetical listing of modules, I couldn’t quite figure out the best place to start.

I realized I was looking for something in between: something that gave me the rooftop view of how all the pieces fit together, and guided me toward using Ecto in the most optimal way.

As I started to wrap my head around Ecto, I decided to try to help fill that gap. Armed with my 20/20 hindsight, I gave a talk at ElixirConf that presented the learning path I had taken, in the hopes that other folks might find it useful.

Apparently, it worked. After the talk, I got an email from Bruce Tate, the series editor for the Elixir books at Pragmatic Bookshelf, asking if I might be interested in expanding the talk out to a book.

I was bowled over, and, to be honest, a little intimidated. But I decided to give it a shot, and I set a goal: to try to produce the book that I would have wanted to read when I first started learning Ecto.

The Newbie And The Expert

I was nervous about trying to write the book on my own, so Bruce very wisely suggested that we invite Eric Meadows-Jönsson, the creator of Ecto and member of the Elixir core team, to come onboard as co-author. I was excited and relieved when Eric said yes, and the two of us chatted over video calls to work out a book structure we could pitch to Pragmatic.

Eric and I had widely different experiences with Ecto at that point, but in retrospect I think those differences helped the book immensely.

I brought the newcomer’s perspective, as the memory of trying to learn Ecto was still fresh in my mind. Eric, on the other hand, had been working on Ecto since the beginning, so he had deep knowledge of all the nooks and crannies, and how they were designed to work.

He brought another important insight: he had been providing support for Ecto through Github issues, mailing list questions, forum posts and the like, so he knew what kinds of things developers usually tripped over, and the questions that got asked most often.

With those two perspectives put together, we got to work.

What’s Inside

We eventually settled on a two-part structure. Part 1 is all about giving you a solid foundation in Ecto’s fundamentals. We walk you through each of the major modules one-by-one and explain what they’re for, how they work, and how they fit together.

  • Repo
  • Query
  • Schema
  • Changeset
  • Transactions and Multi
  • Migration

Each chapter builds on the previous one, and we build up your knowledge piece by piece.

We start with the Repo module and show what can be done with just that module alone. Then we add the Query module, and work with just those two. We then integrate the rest of the modules one at a time, so you can see how the pieces fit together without having to keep too many new things in your head at once.

Every step of the way, you’re learning in the most effective way possible: by writing code yourself. The book comes with a sample application that works right out of the box and tons of code examples you can type right into IEx while you read. This helps you get Ecto’s API into your fingers right from the get-go.

And if you’ve used Ecto before, some of this might feel like review, but many of our beta readers mentioned that they picked up some new tricks reading through this section, so you might be surprised!

Part 2 is, as one reviewer put it, a “choose your own adventure”. We look at number of different use cases that often come up in database programming and show you how to take the tools you learned in Part 1 to make these use cases work.

We look at things like asynchronous testing, custom database types, polymorphic associations, working with JSON columns, Phoenix integration, and many others (see the table of contents for a complete list).

This section is much less sequential than Part 1, so you can skip around and tackle the problems that are most relevant to what you’re working on right now.

But, why not just read the docs?

A number of people have asked me this over the course of the project, and it’s a fair question, given that the docs for Ecto are about as good as you’ll find anywhere.

I think that answer has to do with what the docs are focused on, as well as the sheer size of Ecto. The docs are great at answering the question “What does this function do?” but not necessarily “Where do I start?” or “How does this all fit together?”

If we were to compare learning Ecto to learning your way around a new city, the docs are sort of like a phone book: very useful, but not necessarily the first thing you’d reach for when you arrived on your first day.

Programming Ecto is more like a tour guide: someone who can show you around, explain how everything is laid out, and help you get the most out of your time spent there.

And once you’ve acquired all of that knowledge, the phone book starts to be a lot more useful.

Check It Out

The book is available for sale now at the PragProg website, and Amazon.

And if you’d like to get more details, head over to the book’s web page. There you’ll find a detailed chapter listing, reviews, and some excerpts from the book that you can download and read for yourself.

If you have any questions, you can find Eric and me on Twitter, and there’s a dedicated topic page for the book on the Elixir Forum web site.

Whether you’re brand new to Ecto, or you’d just like to learn how to use it more effectively, we’re hoping that Programming Ecto will give you what you need to take your Ecto skills to the next level.

--

--

Web & mobile developer at @Infinite_Red, Ruby enthusiast, jazz pianist. Not always in that order.