ygrek / sqlgg

SQL Guided (code) Generator
https://ygrek.org/p/sqlgg/
GNU General Public License v2.0
62 stars 20 forks source link

Named parameters in callbacks #40

Closed andrenth closed 5 years ago

andrenth commented 8 years ago

Hi

In my general SQL usage, queries generally have a large number of results. I think having support for named parameters in callbacks would avoid the trouble of having to keep the parameter list in the same order as specified in the query.

I'm not familiar with the code yet, but I managed to get this working with this simple change:

--- a/src/gen_caml.ml
+++ b/src/gen_caml.ml
@@ -36,7 +36,8 @@ module L = struct
 end

 let get_column index attr =
-  sprintf "(T.get_column_%s stmt %u)"
+  sprintf "~%s:(T.get_column_%s stmt %u)"
+    attr.name
     (L.as_lang_type attr.domain)
     index

Would you be interested in adding this? Maybe the behavior could be selected via a command-line flag. Some validation would also have to be added to make sure the column name or alias are valid OCaml parameter name. If you're interested I could start working on a proper pull request.

Thanks, Andre

ygrek commented 7 years ago

Sorry, I missed this one :] Yes, this is something I was planning to do. Another idea was to generate records for callbacks, see #18 And probably need a command line flag indeed, to not break code, though named parameters better be a default in future..