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: https://github.com/fazibear/defql

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.

madeinussr

madeinussr

Yes, I’m talking about shortcut-macros. I wonder: what if define table :table_name once in xQuery module, for all shortcut macros? Any downsides?

sztosz

sztosz

I can see use case where one table name per module has downsides. For example module

defmodule QueryHelpers do
  use Defql
  
  defselect get_users(conds), table: :users
  defselect get_accounts(conds), table: :accounts
  definsert add_user(params), table: :users
  definsert add_account(params), table: :accounts
 
  ...
end

Im not saying it’s a good solution, but having one table name per module, you would enforce programmer to write module per database table. I understand convenience, but rather advise against such restriction.

Where Next?

Popular in Libraries Top

Qqwy
TypeCheck: Fast and flexible runtime type-checking for your Elixir projects. Core ideas Type- and function specifications are const...
336 13801 100
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
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
benlime
I created a new library GitHub - benvp/ex_cva: Class Variance Authority for Elixir which aims to make it very easy to define different va...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
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 18262 141
New
bryanjos
Hi, I just published version 0.23.0 of Elixirscript. Most of the changes are around JavaScript interop now that Elixirscript uses the ...
New
mtrudel
Bandit is an HTTP server for Plug and WebSock apps. Bandit is written entirely in Elixir and is built atop Thousand Island. It can serve...
New
gjaldon
As the title states, EctoEnum has just been updated after some time of hardly any activity in the repo. Here’s the latest release: https:...
New
New

Other popular topics Top

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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
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
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
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

Sub Categories:

We're in Beta

About us Mission Statement