fazibear

fazibear

Defql: create Elixir functions with SQL as a body

The module that provides macros to create functions with SQL as a body.

Blog post about the library: https://blog.fazibear.me/sql-queries-as-elixir-functions-5f8b1d67169e

Github repo: GitHub - fazibear/defql: Create elixir functions with SQL as a body. · GitHub

Most Liked

madeinussr

madeinussr

Thank you @fazibear for such interesting library.

I have a question: what are cases make the table: :table_name definition worthy to be duplicated?

In your example:

defmodule UserQuery do
  use Defql

  defselect get(conds), table: :users
  definsert add(params), table: :users
  defupdate update(params, conds), table: :users
  defdelete delete(conds), table: :users

  defquery get_by_name(name, limit) do
    "SELECT * FROM users WHERE name = $name LIMIT $limit"
  end
end

Maybe you consider (architecturally) the possibility to have get/add/etc. queries to different tables within one xQuery module?

fazibear

fazibear

Yea! That could be possible. It’s worth considering. Maybe with syntax like this:

defmodule UserQuery do
  use Defql, table: :users

  defselect get(conds)
  definsert add(params)
  defupdate update(params, conds)
  defdelete delete(conds)
end
fazibear

fazibear

The table name is not duplicated. When you write the whole query with defquery you type table name inside a query string. But if you want to use other macros with are some kind of shortcuts for common queries, you have to provide a table name, but you don’t type any SQL.

Where Next?

Popular in Announcing Top

zorbash
I created Kitto a framework for dashboards inspired by Dashing. The distributed characteristics of Elixir and the low memory footprint...
New
Crowdhailer
Experimenting with this code. OK.try do user <- fetch_user(1) cart <- fetch_cart(1) order = checkout(cart, user) save_orde...
New
josevalim
Yes, yet another parser combinator library! Most of the parser combinators in the ecosystem are either compile-time, often using AST tra...
159 19951 141
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
mindok
What is ContEx? A pure Elixir server-side data plotting/charting library outputting SVG. It has nice barcharts in particular and works g...
New
dominicletz
Hi, I thought I had posted my library before but seems I hadn’t. The project is still in early stages but it’s growing and so I think it...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement