https://github.com/joshnuss/ecto_preloader
Preload your data efficiently with joins
https://github.com/joshnuss/ecto_preloader
ecto elixir
Last synced: about 1 year ago
JSON representation
Preload your data efficiently with joins
- Host: GitHub
- URL: https://github.com/joshnuss/ecto_preloader
- Owner: joshnuss
- Created: 2019-11-08T06:04:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-08T07:03:33.000Z (over 6 years ago)
- Last Synced: 2025-04-11T21:52:31.240Z (about 1 year ago)
- Topics: ecto, elixir
- Language: Elixir
- Homepage:
- Size: 15.6 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ecto.Preloader
Preload your associations efficiently with joins.
You can do this with Ecto alone, it just requires more code. This package makes it a one liner.
Full documentation: [https://hexdocs.pm/ecto_preloader](https://hexdocs.pm/ecto_preloader).
## Example usage:
```elixir
import Ecto.Preloader
Invoice
|> preload_join(:customer)
|> preload_join(:lines)
|> Repo.all()
```
### Example using Ecto directly:
Without Ecto.Preloader it gets a bit repetitive:
```elixir
Invoice
|> join(:left, [i], assoc(i, :customer), as: :customer)
|> join(:left, [i], assoc(i, :lines), as: :lines)
|> preload([lines: l, customers: c], lines: l, customer: c)
|> Repo.all()
```
## Installation
The package can be installed by adding `ecto_preloader` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:ecto_preloader, "~> 0.1.0"}
]
end
```
## License
WTFPL