- the query sintax was inspired by LINQ in the .NET framework.
- migrations and relation syntax feel a lot lke ActiveRecord.
- Ecto is explicit, ecto avoid the magic.
- Ecto is flexible. ecto is a suite of tools for database.
- Ecto core functionality is contained in six main modules.
- Repo is the heart and acts as a kind of proxy.
- The query module contains ectos powerful but elegat API for writing queries.
- A schema is a kind of map, from database tables to your code. The schema module contails tools to help you create. these maps with ease.
- Changeset a data structure that captures all aspects of making a change to your data. The changeset module provides functions for creating and manipulating changeset.
- the transaction function works great for simple cases, but the multi module can handle even very complex cases.
- Migration helps you coordinate these changes so that everyone stays in sync.
- ecto is actaully to separate packages: ecto and ecto_sql.
- the ecto package contains some of the core data manipulation features that are useful even if your not in a relational db, these incluse Repo, Query, Schema and Changeset.
- ecto_sql contains modules needed to communicate with relational database, ecto_sql includes ecto as a dependendy so if you work with relational db you just need to include ecto_sql.
- to work with no relational db, you might include only ecto.
- the main characteristic of this pattern is the presence of a single module or class, called the Repository, through with all communications with the databases passes
- The repository acts as a stand in for your database, and its the single point of contact, if you want to talk to a database, talk to the repository.
- With the Repository pattern, the database is front and center, and is a great fit, for a language like Elixir wich decouple data and behavior, and favors explicit behavior over implicit.
- The repo module is the heart of Ecto, and just about everything you do will touch Repo, you can permor all the classic CRUD operations using just Repo module alone. The other modules in Ecto make these operations easier, but there a lot you can do with just Repo.
-
Repo is the gateway to our database, and most of the functions in Repo map directly to standard CRUD operations, its one job is sending payloads back and forth to the database.
-
Repo exposes a number of functions that allow us to interact with our database at a low leve, even before we start setting up schemas. These functios are easy to spot because they end with "all", inset_all, update_all delete_all, and just plain all for queries.
- Repo module contains everything you need, but may times when we need to call specific behavior over and over and oer we can modify by adding a custom behavior. Thats is possible adding Repo aggregate
The query module uses Elixir macros to create a DSL that sits right in your Elixir code. The DSL syntax feels a lot like Elixir, but it's a little more fluid and makes writing queries feel more natural.