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

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
KristerV
I got fed up with removing unused aliases manually so made a package for it: GitHub - KristerV/remove_unused_ex: Remove unused aliases an...
New
c4710n
This package is a simple wrapper of beam-telemetry packages. It provides a modular approach for using beam-telemetry packages. The basi...
New
borodark
Hey folks, I’m building Zed (not editor) a declarative BEAM deploy tool for FreeBSD and illumos that uses ZFS user properties as the stat...
New
bluzky
Hi everyone, I would like to introduce my new project OrangeCMS, it’s an application that help you to create/edit content post for your ...
New
tmbb
I’ve started working on a toy project to compile extended POSIX-compatible regular expressions into NimbleParsec combinators. These combn...
New
miolini
Hi :waving_hand: I’ve been working on CanvasCraft, a 2D drawing library for Elixir built on top of Skia via Rustler. It provides a decla...
New
felix-starman
I’ve noticed that often when I find myself needing to manually set content-disposition - [MDN] the advice is usually to use URI.encode_ww...
New
jarlah
Hi! I have recently created, after having tried to get in touch with the creator of excontainers for quite some time, a new library call...
New
sodapopcan
EDIT: I forgot to link the repo, ha: GitHub - sodapopcan/vials: Tweak your mix generators · GitHub This project is not quite ready for p...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement