j0sh / ocaml-gensqlite

OCaml ppx preprocessor to generate SQLite3 prepared statements and query functions
Other
12 stars 2 forks source link

Discuss syntax for placeholders #4

Open foretspaisibles opened 8 years ago

foretspaisibles commented 8 years ago

I see you started working on a replacement for sigils. Do you mind if I propose a syntax I like?

It is interesting or desirable to use familiar idioms, like the ${…} string interpolation. Some widespread languages (the shell, BSD Make at least) use a suffix introduced by a semicolon to add pepper and salt to a variable, such as default values or various transformations. Here are the various SQL statements found in sample.ml with a proposal for another syntax:

This also use the @ vs % convention for formatting input and output fields, as sqlexpr does.

I am currently giving gensqlite a try and it looks very promising, thanks for writing it!

j0sh commented 8 years ago

Hi,

The sigils have been replaced with sqlexpr style format strings -- the only thing that hasn't been updated yet is the README, sorry. If I remember, one of the 'new' things that came with this rewrite is support for un-labelled/anonymous function arguments. The printf-style %s, %d, etc is a natural way to express that. While ${:%s} would still work, it's syntactically heavier. Still, it is worth considering other approaches. I am actually fond of how shell assigns default values -- and default values for function arguments would be a nice feature to have for gensqlite.

There is also a pull request adding ppx support to sqlexpr: https://github.com/mfp/ocaml-sqlexpr/pull/6. If I can also figure out a nice way to get labelled arguments into sqlexpr, then I might deprecate gensqlite, since sqlexpr has a lot of nice features (auto-finalization, transactions, concurrency, streamable results). Implementing those features would converge gensqlite to the same basic design as sqlexpr, and there is no reason to duplicate work.

foretspaisibles commented 8 years ago

Thank you for your great answer! :)