Your library looks great. But a tangential rant about t-strings, using lexical scope for placeholder lookup is just a terrible, terrible design. It should be explicitly passed in a dictionary. I'm not sure why they made this decision.
Show HN: SQL-tString a t-string SQL builder in Python
11–20 of 43 posts
Re: Show HN: SQL-tString a t-string SQL builder in Python
#12Just took a quick look, and it seams like the parser is hand written which is great, but you probably want to build a lexer and parser based on the BNF grammar take a look at how I do it here https://github.com/elixir-dbvisor/sql/tree/main/lib and do conformance testing with https://github.com/elliotchance/sqltest
Thanks, do you have a reference for SQL grammar - I've had no success finding an official source.
Re: Show HN: SQL-tString a t-string SQL builder in Python
#13How does the SQL parsing work for the rewrites like removing expressions? I have a project using some non-standard SQL features and we have quite complex queries going on, so the rewriting makes me a bit nervous. The great thing about tstrings for sql is that it’s a total escape from “magick” creating ineffable and unknown sql replacing with very straightforward what you see is what you get sql right in the source co…
> Do you support templating a sql tstring into an sql tstring for composition?
Yep
Re: Show HN: SQL-tString a t-string SQL builder in Python
#14Re: Show HN: SQL-tString a t-string SQL builder in Python
#15Your library looks great. But a tangential rant about t-strings, using lexical scope for placeholder lookup is just a terrible, terrible design. It should be explicitly passed in a dictionary. I'm not sure why they made this decision.
If they’re gonna do that why bother making a new concept? You could already build(normalString, someDict) Like why make me state “A goes here, also the value of A is 1” when I can just say “1 goes here”? When I build an array or map, I just write the expression { key1: value1 } I don’t need to write build({ key1, value1 }, { “key1”: key1, “value1”: value1 }) Why should an sql literal be any different from an array or…
Re: Show HN: SQL-tString a t-string SQL builder in Python
#16With Java the manifold project achieves this via compiler plugin. The manifold-sql[1] module provides inline, type safe, native SQL.
1.https://github.com/manifold-systems/manifold/blob/master/man...
Re: Show HN: SQL-tString a t-string SQL builder in Python
#17Languages should strive to type safely inline SQL and other structured data. With Java the manifold project achieves this via compiler plugin. The manifold-sql[1] module provides inline, type safe, native SQL. 1. https://github.com/manifold-systems/manifold/blob/master/man...
Re: Show HN: SQL-tString a t-string SQL builder in Python
#18Languages should strive to type safely inline SQL and other structured data. With Java the manifold project achieves this via compiler plugin. The manifold-sql[1] module provides inline, type safe, native SQL. 1. https://github.com/manifold-systems/manifold/blob/master/man...
Re: Show HN: SQL-tString a t-string SQL builder in Python
#19Technically this enforces parameterized queries since all it does is basically return the parameterized query in the given db client dialect and the list of parameters. It could be useful for building a unified interface for all sql db clients for example (instead of having to remember whether parameters are %s or ? or {param}, etc). On the other hand, db clients can utilize t-strings to directly allow you to safely…
Re: Show HN: SQL-tString a t-string SQL builder in Python
#20I can imagine the behavior takes some trial and error to figure out, but it looks like you can write a search() query that contains fully-loaded sql statement as if all facets were provided, yet you can make each facet optional and those expressions will get removed from the statement.
That would be much nicer than the traditional route of building up a where clause with a bunch of if-statements where it's very hard to understand what the final where clause might look like without print(statement).
I'd rather write the whole SQL statement upfront which this seems to let you do.