Generating forms with your schema? Check! Need casting or validation errors? Check! Validate one and multiple associations? Check that one too! Working with Changesets and Phoenix forms. It’s a straightforward chapter that teaches how to add Ecto to an Elixir project and put your Repo module under your application’s supervision tree. The question “how can I use Ecto without Phoenix?” is one we get more often than you imagine. At first, this can bring out some reactions along the lines of “what does a Web framework have to do with a database library?” Well, if you don’t know, Phoenix is the most popular Web framework in Elixir, and it comes integrated with Ecto by default, without any additional code from the developers. I’ll give my impressions on these chapters in the same order they appear in the book:Īdding Ecto to an Elixir Application Without Phoenix. You can do that without any fear of feeling lost due to missing other chapters in the second part. It means you can just pick whatever topic is more appealing to you at the moment. The second part is split into independent topics that give the reader the flexibility to read them in any order. It’s important to get everyone on the same page so we can move on to the second part. The first part of the book is a guided introduction to Ecto. Finally, the authors wrap up the first part of the book by showing you how to make changes to the database structure by using Ecto migrations. The highlight here is how to wrap database and non-database operations in the same database transaction. In Chapter 5, the authors dive into database transactions with Ecto and how to write clean transaction code by using Multi. The book makes it clear that schema or schemaless approaches are achievable with Ecto. They also show how to glue your database schema and associations with your validation process. They show you how to validate data without going through a schema that represents your database. Changesets are a powerful Ecto feature that allows you to cast and validate parameters from external input (either from a user or external systems). In Chapter 3, the book shows you can easily cut down on tons of query code by using Ecto schema structs and associations.Īfter playing with a lot of repositories and queries, Darin and Eric show you how to work with changesets in Chapter 4. You’ll play with many queries without using any Ecto schema structs, which just emphasizes how Ecto is flexible and how it does not force you into a single way of doing things. It really feels like the union of two worlds has been accomplished: you have a query syntax that is very close to SQL but still is Elixir. In the following chapter, the authors move on by showing how you can query your database by running the most common SQL query expressions using the Ecto query macros. Then, the authors end the first chapter showing you how Ecto is organized, how the Repository pattern works, and how you can use the Repo module. Or, using the author’s words: it’s a suite of tools for databases. We can say confidently that Ecto is battle-tested.ĭarin and Eric start the book displaying what the core principles of Ecto are by showing how it borrowed a lot of great ideas from other database libraries and repacked them in a consistent, explicit, flexible and very Elixir-like style. It means this library has had years of development, testing, and running in real-world applications. Another reason for the current Ecto popularity: it was one of the first libraries to show up. For instance, even José Valim, the creator of Elixir, has active participation in it. This is due to the excellent support Ecto has received from the developer community. It will be hard to find an Elixir project that touches a database that doesn’t use Ecto. If you’re not aware, Ecto is the database library to go with Elixir. Today I want to share my impressions about the book and help you decide if Programming Ecto is for you. Recently, I got the final printed version, and I reread it. It took me a few days to read it through and add all my comments, and I can spoil this: it’s a great book. Hello, my beloved readers! Last year I was granted an opportunity to review the Programming Ecto book, published by The Pragmatic Bookshelf, and written by Darin Wilson and Eric Meadows-Jönsson (note: Eric is the creator of Ecto and an Elixir core member).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |