senconscious

senconscious

Package for sorting ecto query

EctoJuno is a package that provides parsing, validation and applying sorting parameters for your ecto queries on models. Currently sorting by joint query is not implemented, as well as custom validators for your parameters. Also you need elixir 1.14 to use this package. Hope this package will help someone not just me ). Looking for a feedback, so if you have any thoughts, please share.

Below is a sample usage of library (assuming you have User ecto schema and Repo module):

alias EctoJuno.Query.Sorting

def list_sorted_users_for_admin(params) do
 User
 |> Sorting.sort_query(User, params)
 |> Repo.all()
end

def list_sorted_users_for_manager(params) do
 User
 |> Sorting.sort_query([:id, :inserted_at], params)
 |> Repo.all()
end

First Post!

senconscious

senconscious

Released v0.2.0 version in which added sorting by joint query.
Let’s assume you have User and Post schemas, Repo module. And users has many posts. If you need sort users by post’s titles than your code will look like:

alias EctoJuno.Query.Sorting

def sort_users_by_posts do
 params = %{"sort_by" => "title", "sort_direction" => "desc"}

 User
 |> join(:left, [u], p in assoc(u, :posts), as: :posts)
 |> Sorting.sort_query(User, params, :posts)
 |> Repo.all()
end

In the next version there’ll be sorting templates: you can define which schema and or binding will be used based on sorting field you passing by

Where Next?

Popular in RFCs Top

pzingg
I took a phx.gen.auth application and added support for storing a user’s cookie consent settings. Created a couple of modal dialogs to ha...
New
adamwight
I’ve written a crude module for retrieving files from a remote server using rsync, since I didn’t see any existing tools already. This c...
New
tmbb
I’ve started working on a toy project to compile extended POSIX-compatible regular expressions into NimbleParsec combinators. These combn...
New
christhekeele
TL;DR: I’m planning on building a library, inspired by Vapor, to make configuring Elixir applications more straight-forward; in an approa...
New
BartOtten
This lib is now published and has a new topic. Once this topic was about PhxAltRoutes. A lib pioneering localized routes for Phoenix. I...
New
Hedgehog-ai
Hello I would like feedback on an experimental neuroevolution (including substrate encoding) library called Bardo based on the amazing wo...
New
blubparadox
Hi all. If you’ve looked on Twitter or YouTube you’ve seen the 1 billion row challenge, usually done in Java. I’ve written an Elixir vers...
New
zachallaun
Hey gang, I’ve been using Req as my primary client for a project I’ve been working on that interacts with a number of APIs, and I quickl...
New
manuel-rubio
There was some time when I started thinking about giving a boost to Lambdapad, the initiative from @garretsmith in Erlang that I loved wa...
New
pknoth
Built on top of boruta | Hex, I am on the way to creating a standalone OAuth 2.0/OpenID Connect server thinking of a lightweight Keycloak...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement