Open foretspaisibles opened 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.
Thank you for your great answer! :)
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 insample.ml
with a proposal for another syntax:insert into users(name) values(>@name)
–>INSERT INTO users(name) values(${name:%s})
select <:id, <@name, strftime('%s', <?created) from users where name = >@name
–>SELECT ${id:@d}, ${name:@s}, strftime('%s', ${created:@h}) FROM users WHERE name = ${name:%s}
This also use the
@
vs%
convention for formatting input and output fields, assqlexpr
does.I am currently giving
gensqlite
a try and it looks very promising, thanks for writing it!