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
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
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
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.
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








