You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, thanks for this excellent library. It's a refreshing alternative to ORM's.
There is however one issue which seems to come up very often with mysql, and that's escaping back ticks. As I'm sure you know, Mysql uses them around field names, to avoid clashing with reserved words. However escaping them for use in tagged template literals is just plain ugly.
For my queries I've been aliasing the table to a single letter, then prefixing my fields, if a field name has a dot in it, you don't need back ticks, but that isn't always possible
eg.
db.query(sql` Select * from settings as s where s.key = "sitename" `)
The text was updated successfully, but these errors were encountered:
As an update, it would seem js doesn't have any easy work around for this. But according to the mysql documentation.
If the ANSI_QUOTES SQL mode is enabled, it is also permissible to quote identifiers within double quotation marks:
The ANSI_QUOTES mode causes the server to interpret double-quoted strings as identifiers. Consequently, when this mode is enabled, string literals must be enclosed within single quotation marks. They cannot be enclosed within double quotation marks. The server SQL mode is controlled as described in Section 5.1.11, “Server SQL Modes”.
I don't think this issue makes sense to address. It's normally not necessary to quote your identifiers, and in the rare cases where you do it is possible to work around the issue either using escaping via \ or using the sql.ident helper.
First of all, thanks for this excellent library. It's a refreshing alternative to ORM's.
There is however one issue which seems to come up very often with mysql, and that's escaping back ticks. As I'm sure you know, Mysql uses them around field names, to avoid clashing with reserved words. However escaping them for use in tagged template literals is just plain ugly.
eg.
Any ideas on how to improve this?
For my queries I've been aliasing the table to a single letter, then prefixing my fields, if a field name has a dot in it, you don't need back ticks, but that isn't always possible
eg.
The text was updated successfully, but these errors were encountered: