alexdesousa / ayesql

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

Bugfix: Function cannot be called by name #11

Closed alexdesousa closed 4 years ago

alexdesousa commented 4 years ago

This PR fixes a bug that prevented running functions by name e.g. given the following file included in the module Myapp.Server:

-- file: lib/servers.sql

-- name: get
-- docs: Gets servers.
SELECT hostname, ip_address
  FROM servers
:_where

-- name: by_hostname
WHERE hostname = :hostname

The following call would produce an error:

iex(1)> Myapp.Server.get(_where: :by_hostname, hostname: "my_server")
{:error, ...}

while the query should be equivalent to the following:

iex(2)> Myapp.Server.get(_where: &Myapp.Server.by_hostname/2, hostname: "my_server")
{:ok, [...]}