3 ms·
I'm of the opposite opinion. Let's set the prefixes free! from sql import sql query = sql"SELECT user_id, user_name FROM {user_table_versioned} WHERE
by wodenokoto 2y ago
I'm of the opposite opinion. Let's set the prefixes free!
from sql import sql
query = sql"SELECT user_id, user_name FROM {user_table_versioned} WHERE user_name = {user_name}"
- dmurray 2y agoHow would this be different from a function sql() that operates on one of these new t-strings? The syntactic sugar of changing it from sql(t"...") doesn't seem particularly valuable. The novel thing about t-strings is that they change the parsing at compile-time.
- stavros 2y agoIt wouldn't be different, but it would be more convenient because we no longer have to count the number of %s, you'd put the variable inline.
- Timwi 2y ago> The syntactic sugar of changing it from sql(t"...") doesn't seem particularly valuable. It's valuable because: - IDEs could then syntax-highlight SQL inside of SQL strings and HTML inside of HTML strings - You can't accidentally pass an HTML string to your SQL library
- wodenokoto 2y agoIt’s different from a function the same way f”” is different from f(“”) and t”” is different from t(“”) There’s nothing stopping you from building a Python function that parses a string looking for {} and then searching globals for those variables. And you can extend that to also do some code execution and formatting. To me the real sugar of f-strings is that the editor knows that it’s a template and not just a string. Expanding this to having SQL and regex syntax highlighting, linting and code formatting inside my Python code is a pretty cool prospect.
- mcintyre1994 2y agoThis is how JavaScript does it with tagged template literals. Your sql there would just be a function that receives the array of strings/values and returns whatever.
- masklinn 2y agoThis was considered and rejected: https://peps.python.org/pep-0750/#arbitrary-string-literal-prefixes https://peps.python.org/pep-0750/#arbitrary-string-literal-p...
- dsego 2y agoThis is what JS does with tagged template literals. https://github.com/dsego/sql_tag https://github.com/dsego/sql_tag