Programming Ecto: Build Database Apps in Elixir for Scalability and Performance

Darin Wilson, Eric Meadows-Jonsson



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 of the SQL and NoSQL variety. 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.

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. Change your pooling strategy to maximize your database's efficiency. 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 19+ and Elixir 1.4+ installed. The book will guide you through setting up a sample application that integrates Ecto.


語言可能興起和消亡,但關聯式資料庫卻持續存在。學習如何使用 Ecto,這是 Elixir 的頂尖資料庫函式庫,將你的 Elixir 和 Phoenix 應用程式連接到各種 SQL 和 NoSQL 資料庫。通過逐個模組的方式深入了解 Ecto 的基礎知識。然後,進一步探討更高級的主題和最佳實踐建議,並提供一系列的示例,逐步指導應用程式開發人員在常見情境中的操作步驟。這本書由 Ecto 的創作者共同撰寫,提供了使用 Ecto 的所有必要知識。

Elixir 和 Phoenix 正在風靡應用程式開發界,而隨之而來的是 Ecto,這是隨 Phoenix 一同提供的資料庫函式庫。有很多基礎示例可以讓你了解基本知識,但要充分發揮 Ecto 的潛力,你需要從頭開始學習這個函式庫。

這本權威指南從 Ecto 的核心功能開始介紹,包括資料庫存儲庫、查詢、模式、變更集和事務,並逐漸提升難度,透過進行越來越複雜的任務來建立你的知識。在此過程中,你將透過實際操作學習,一個範例應用程式將處理所有樣板代碼,讓你專注於掌握 Ecto。

在掌握核心知識的基礎上,透過一系列的示例進一步擴展你的知識,涵蓋更高級的主題。改變連接池策略以最大化資料庫效能。使用巢狀關聯處理複雜的表關係。添加串流以輕鬆處理大型結果集。這些示例是根據 Ecto 使用者的問題而編寫的,涵蓋了開發人員最常遇到的情況。

無論你是初次接觸 Ecto,還是已經有一個正在運行的應用程式,這本書都將讓你更深入地了解 Ecto 的運作方式,並幫助你使資料庫程式碼更乾淨、更高效。


為了跟隨本書,你應該已經安裝了 Erlang/OTP 19+ 和 Elixir 1.4+。本書將引導你建立一個整合了 Ecto 的範例應用程式。