News for hackers. Stuff that matters.
Re:Show HN: PugSQL, a Python Port of HugSQL by phaer on Wednesday May 29, 2019 @02:00PM (#20043359)
I haven't used PugSQL yet, but I like the principle because it allows to keep SQL and Python code in separate files, which makes it easier to use linters or even just proper syntax highlighters for the SQL compared to strings embedded into python or other programming languages.
Re:Show HN: PugSQL, a Python Port of HugSQL by sametmax on Wednesday May 29, 2019 @02:12PM (#20043484)
First, good linters and syntax highlighters are supposed to work in embedded code. It works for HTML, JS, CSS. It works for docstring in Python, regex or f-strings. But the tooling state of SQL is quite terrible.

Secondly, you can do that with Path.read_text() and pass it to SQLalchemy-core if a query is so complex you want to (although you would lose many other architectural benefits by doing so, it is sometime necessary).

But writing your entire program like that seems very slow, SQL being verbose, and you having to write additional wrappers on top of it anyway.

Re:Show HN: PugSQL, a Python Port of HugSQL by phaer on Wednesday May 29, 2019 @03:08PM (#20044119)
> First, good linters and syntax highlighters are supposed to work in embedded code. It works for HTML, JS, CSS. It works for docstring in Python, regex or f-strings. But the tooling state of SQL is quite terrible.

As you write, in practice it sucks for SQL. Formatting is another issue, can become quite awkward in embedded code

> Secondly, you can do that with Path.read_text() and pass it to SQLalchemy-core if a query is so complex you want to

Yes, if you use one file per query. Otherwise you'd need something similar to the naming-scheme of PugSQL, just implemented by your self.

> But writing your entire program like that seems very slow, SQL being verbose, and you having to write additional wrappers on top of it anyway.

This depends entirely on your program and/or problem domain. It might be overkill for simple CRUD applications with a few INSERT/UPDATE/SELECT queries, but might make a lot of sense if you use more advanced SQL features.