When writing a query that uses graves/backticks (`) for segmenting identifiers, the SQL parser to extract the strings adds in extra backslashes to escape the graves.
The following Typescript code currently passes:
const rawSql = sql`SELECT * FROM \`sqlx-ts\`.\`tests\``;
expect(rawSql).toBe("SELECT * FROM `sqlx-ts`.`tests`");
However, when printing out the parsed SQL statement when running through sqlx-ts (probed at core/execute.rs:22 and read sql.query), we get:
SELECT * FROM \\`sqlx-ts\\`.\\`tests\\`
This leads sqlx-ts to failing due to a so-called compiler error even though the query is valid SQL. The following was generated using cargo test -- demo_happy_path with the SQL with graves inserted into qualified_table_names:
error: internal compiler error: syntax error at or near \"\\\"
--> /home/nydauron/Git/sqlx-ts/tests/demo/select/qualified_table_names.ts:52:1
|
52 | const rawSql = sql`SELECT * FROM \\`sqlx-ts\\`.\\`tests\\``;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: sql parser error: Expected: identifier, found: \\ at Line: 1, Column: 15
Location:
src/ts_generator/generator.rs:130:17
It is worth noting the observation that ``, "", and '' all get escaped with single backslashes.