bluzky

bluzky

A small library to build Ecto query from map

I have just released a small library that help to build query from a map with structure similar to Mongo DB filter like this:

Filtery.apply(Post, %{name: {:like, "elixir"}, is_draft: false, tags: {:has, "ecto"} })

Here is the repo:

It’s quite simple and supports filtering on a single table only.
It supports basic operators eq, :gt, :gte, :in, :lt, :lte, :ne, :nin, :and, :or and some other helpful operators. And you can define your own operators too.

Please try and leave your feedback. Thank you.

Update v0.2.0

I have added a special operator ref to join multiple table

query = Filtery.apply(Post, %{comments: {:ref, %{
                                    approved: true,
                                    content: {:like, "filtery"}
                                 }}})

comments field must be the association name in your Post schema

Most Liked

mathieuprog

mathieuprog

This looks similar to my library QueryBuilder :grin:
It’s possible to have joins.

Possible to make a query out of a keyword list with QueryBuilder.from_list/2.

marciol

marciol

It’s really nice to have ways of building queries using a more data-driven approach. It’s really awesome

bluzky

bluzky

I have added new operator for querying join table. Please check update above.

subbu

subbu

This is neat. It will work well for simple use cases. Its also good in way that you can build filters progressively as its a map. But its use will be limited as most production use-cases will involve multi-table filtering.

bluzky

bluzky

Filtery.apply return a query so you can chain as many time as you want like this

Post
|> Filtery.apply(%{title: {:not, {:like, "elixir"}}})
|> Filtery.apply(%{is_draft: false, comment_count: {:gt, 10}})
|> Repo.all()

I have been thinking of a simple specification to define a join filter but there is not good enough solution.
Do you have any suggestion?

Where Next?

Popular in Libraries Top

RobertDober
Earmark is a pure-Elixir Markdown converter. It is intended to be used as a library (just call Earmark.as_html), but can also be used as...
239 11851 134
New
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
New
OvermindDL1
Been making an MLElixir thing (not released yet…) for fun in spare time in the past day. I’m just trying to see how much I can get an ML...
132 13487 106
New
arkgil
Hi all! I’m happy to announce that Telemetry v0.3.0 is out! This release marks the conversion from Elixir to Erlang so that all the libr...
New
michalmuskala
Another small library today. PersistentEts Hex: persistent_ets | Hex GitHub: GitHub - michalmuskala/persistent_ets Ets table backed by...
New
riverrun
I’ve just released version 3 of Comeonin, a password hashing library. The following small changes have been made: changes to the NIF c...
New
mbuhot
EctoJob A transactional job queue built with Ecto, PostgreSQL and GenStage Available on Hex.pm: ecto_job | Hex Docs: API Reference — ec...
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_or...
New
Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Th...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

Sub Categories:

We're in Beta

About us Mission Statement