About This Title

Pages: 242
Published: April 2019
ISBN: 9781680502824
In Print

Skill Level Meter

Programming Ecto

Build Database Apps in Elixir for Scalability and Performance

by Darin Wilson and Eric Meadows-Jönsson

Languages may come and go, but the relational database endures. Learn how to use Ecto, the premier database library for Elixir, to connect your Elixir and Phoenix apps to databases. Get a firm handle on Ecto fundamentals with a module-by-module tour of the critical parts of Ecto. Then move on to more advanced topics and advice on best practices with a series of recipes that provide clear, step-by-step instructions on scenarios commonly encountered by app developers. Co-authored by the creator of Ecto, this title provides all the essentials you need to use Ecto effectively.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $29.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.


Elixir and Phoenix are taking the application development world by storm, and Ecto, the database library that ships with Phoenix, is going right along with them. There are plenty of examples that show you the basics, but to use Ecto to its full potential, you need to learn the library from the ground up.

This definitive guide starts with a tour of the core features of Ecto—repos, queries, schemas, changesets, transactions—gradually building your knowledge with tasks of ever-increasing complexity. Along the way, you’ll be learning by doing—a sample application handles all the boilerplate so you can focus on getting Ecto into your fingers.

Build on that core knowledge with a series of recipes featuring more advanced topics. Speed up your test suite by running database tests concurrently. Use nested associations to handle complex table relationships. Add streams to handle large result sets with ease. Based on questions from Ecto users, these recipes cover the most common situations developers run into.

Whether you’re new to Ecto, or already have an app in production, this title will give you a deeper understanding of how Ecto works, and help make your database code cleaner and more efficient.

What You Need

To follow along with the book, you should have Erlang/OTP 20+ and Elixir 1.5+ installed, along with either PostgreSQL (preferred) or MySQL. The book will guide you through setting up a sample application that integrates Ecto.

Resources

Releases:

  • P1.0 2019/04/08
  • B8.0 2019/03/22
  • B7.0 2019/02/07
  • B6.0 2019/01/24

Contents & Extracts

  • Introduction
  • Ecto Fundamentals
    • Getting Started with Repo
      • Ecto and Elixir
      • Ecto Modules
      • How Ecto Is Organized
      • Setting Up the Sample App
      • The Repository Pattern
      • The Repo Module
      • Putting Our Repo to Work
      • Customizing Your Repo
      • Wrapping Up
    • Querying Your Database
      • Query Basics
      • Refining Our Results with where
      • Working with Joins
      • Composing Queries
      • Other Ways to Use Queries
      • Wrapping Up
    • Connecting Your Tables to Elixir Structs with Schemas
      • Creating Schemas
      • Writing Queries with Schemas
      • Inserting and Deleting with Schemas
      • Adding Associations to Schemas
      • Working with Associations in Queries
      • Optimizing Associations with Embedded Schemas
      • Deleting Records with Associations
      • Using Schemas to Seed a Database
      • Wrapping Up
    • Making Changes with Changesets excerpt
      • Introducing Changesets
      • Casting and Filtering
      • Validating Your Data
      • Capturing Errors
      • Using Changesets Without Schemas
      • Working with Associations
      • Wrapping Up
    • Making Multiple Changes with Transactions and Multi
      • Running Transactions with Functions
      • Running Transactions with Ecto.Multi excerpt
      • Wrapping Up
    • Making Changes to Your Database
      • Introducing Migrations
      • Your First Migration
      • Running Migrations
      • Rolling Back Migrations
      • Adding Indexes
      • Changing Data and Table Structure Together
      • Specifying Up and Down Operations
      • Changing Default Behaviors
      • Wrapping Up
  • Ecto Applied
    • Adding Ecto to an Elixir Application Without Phoenix
      • Creating a New Project
      • Adding Ecto’s Dependencies
      • Creating Your Repo Module
      • Adding Ecto to the Supervision Tree
      • Using Multiple Ecto Repos
      • Starting Your App
      • Wrapping Up
    • Working with Changesets and Phoenix Forms
      • Generating a Form for a Single Schema
      • Displaying Changeset Errors
      • Creating a Form with an Association
      • Creating a Form with Multiple Associations
      • Wrapping Up
    • Testing With Sandboxes
      • Setting Up an Async Test
      • Changing the Ownership Mode
      • Safely Sharing Connections with Allowances
      • Wrapping Up
    • Creating and Using Custom Types
      • Building on Top of Ecto’s Types
      • Adding Custom Types Without the Built-In Types
      • Wrapping Up
    • Inserting and Updating with Upserts
      • Performing Upserts Without Schemas
      • Performing Upserts with Schemas
      • Wrapping Up
    • Optimizing Your Application Design
      • Separating the Pure from the Impure
      • Working with Contexts
      • Working with Umbrella Applications
      • Wrapping Up
    • Working with Embedded Schemas
      • Creating Embedded Schemas
      • Adding Embeds to Another Schema
      • Making Changes
      • Choosing Between Embedded Schemas and Associations
      • Wrapping Up
    • Creating Polymorphic Associations
      • Polymorphism in Other Frameworks
      • Approach #1: Multiple Foreign Keys
      • Approach #2: Using an Abstract Schema
      • Approach #3: Using many_to_many
      • Wrapping Up
    • Optimizing IEx for Ecto
      • Adding Imports and Aliases
      • Adding Helper Functions
      • Wrapping Up
    • Using Schemas Without Tables
      • Downsides to Locking Schemas to Tables
      • Breaking Up the Artist Schema
      • Creating Table-less Schemas
      • Saving the Table-less Structs
      • Wrapping Up
    • Tuning for Performance
      • Preparing to Optimize
      • Optimizing Queries
      • Executing Bulk Operations
      • Fetching Large Datasets with Streams
      • Wrapping Up

Author

Darin Wilson has been coding professionally since the days when you got help with coding problems by posting a message to a BBS over a 300-baud modem. Over the years, he’s developed apps for banking, education, television, social media, and robotic arms. He is currently a principal software engineer at Infinite Red, a web and mobile application development company.

Eric Meadows-Jönsson is a member of the Elixir core team and the creator of Ecto. He is a passionate open source developer and is heavily involved in the Elixir community.

eBook Formats:

  • PDF for desktop/tablets

  • epub for Apple Books, e-readers

  • mobi for Kindle readers

Get all eBook formats here for $29.95 (USD)

Add to Cart we accept visa, mastercard, amex, discover, paypal


Paperback Formats:

Please support indie bookstores!
Find indie bookstores in the U.S. Find indie bookstores around the world.

Related Titles:

Skill Level Meter

About This Title

Pages: 242
Published: April 2019
ISBN: 9781680502824
Edition: 1
In Print