Closed gevera closed 3 months ago
@gevera Thanks for your interest in this project and sorry for the late reply to your issue!
The defqueries
macro can be called several times in the same file as long as the queries' names do not clash e.g. given the following query files:
-- file `./all.sql`
-- name: get_hostnames
SELECT hostname FROM server;
and
-- file `./by_hostname.sql`
-- name: get_server_by_hostname
-- docs: Simple query
SELECT * FROM server WHERE hostname = :hostname;
then you can define an AyeSQL module as follows:
defmodule MyQueries do
use AyeSQL
defqueries("all.sql")
defqueries("by_hostname.sql")
end
Note: Elixir will fail the compilation if the
name:
of the queries between the files clash.defqueries("sql/*/.sql")
This approach you've suggested:
defqueries("sql/**/*.sql")
looks like a nice improvement to the macro! :+1:
I hope this answer doesn't come extremely late and it's been useful :grin:
Thanks for the reply. No worries, event if it's late. AyeSQL its a great library that brings me closer to SQL in Elixir. And, yeah, i think calling just once
defqueries("sql/**/*.sql")
instead of multiple
defqueries("all.sql")
defqueries("by_hostname.sql")
is cleaner
Anyways, I'm keepimg an eye on the projects and updates. Cheers
@gevera I'll close this issue for now. I'm not going to implement the wildcard definition for now. However, if you or someone else is willing to implement it, I'll be happy to review it and merge it :smile:
I have multiple entities, in separate folders, with their own sql queries.
I would like to have a single entry for AyeSQL and pass it an array of sql files like so
or better yet, somehow AyeSQL to be able to read all the sql files in subfolders
Is it even possibe?