alexdesousa / ayesql

Library for using raw SQL in Elixir
MIT License
135 stars 13 forks source link

Are you considering different arity functions ? #31

Closed dkuku closed 1 year ago

dkuku commented 1 year ago

Interesting project - I'm trying to port the https://github.com/dbcli/pgspecial/blob/main/pgspecial/dbcommands.py python module to elixir using it to get a better feel. But I'm hitting some walls and I wonder if this can be solved or should I just move to ecto ? it's may be somewhat connected to #7 let's say I define the same function twice with different params:

-- name: foo
select * from bar

--- name: foo
select * from bar where baz = :baz

knowing this definitions the code can generate something like:

def name(%{baz: baz}), do: "select * from bar where baz = #{baz}"
def name(%{}), do: "select * from bar"

The crucial part may be the map instead of keyword list because it will work with multiple arguments without caring for the order

In the dbcommands.py file I linked the functions accept 2 params: pattern and verbose Knowing that we can generate 4 queries with 4 heads all with the same name:

list_databases(%{verbose: true, pattern: pattern}, do: sql1
list_databases(%{verbose: true}, do: sql2
list_databases(%{pattern: pattern}, do: sql3
list_databases(%{}, do: sql4