by beders · 3y ago · 0 comments
The majority of your SQL will not require building dynamic where clauses or (dog forbid) dynamic joins.
Having your SQL as plain statements with simple placeholders (to create safe prepared statements) is the saner approach.
Not only can you pluck them into your favorite SQL tools and analyzers, but you will not be surprised by terribly performing queries, because you created them dynamically without understanding their complexity.
We've learned the hard lessons decades ago by misusing ORMs. While using alternative SQL syntax builders is avoiding many of those pitfalls, you will still inherit complexity by translating a SQL dialect to the builder pattern.
It is not worth it IMHO.
Projects writing raw SQL eventually end up implementing their own query building functionality. Which adds another thing to maintain and understand - that's also lacking in features and is not as type-safe.
Just use a well adopted query builder.
1) db.execute("select name, tel from person where id={?}",personId);
2) const sqlText="select name, tel from person where id={?}";
db.execute(sqlText, personId);
3) as 2), but put sqlText in another file,
continues to be productive in django