SQLStrings.jl
SQLStrings.jl copied to clipboard
Syntax for prepared queries
I came across this little package and it's great! Exactly what I was looking for when working with LibPQ, which doesn't provide named parameters.
I would find it more useful to be able to pass parameters as a Dict{Symbol,Any}
, rather than pulling them from the environment with a macro - seems cleaner and safer, and works well if your workflow looks like load SQL query template from file > interpolate variables > run query
. I don't think this package supports that because of the macro approach (correct me if I'm wrong, not a macro wizard here).
So I put that together for myself. Concretely, it's a non-macro equivalent to @sql_str
called something like render(sql::AbstractString, parameters::AbstractDict{Symbol,Any}
, that renders a template given a Dict of parameters. While doing that, I also hacked in a way to reuse parameters if the same parameter appears more than once in the template.
Does that sound like something you'd like me to contribute to this package?