Skip to content

Commit 96b09c0

Browse files
authored
grave quotes and double quotes (#269)
fix
1 parent 27c5785 commit 96b09c0

File tree

7 files changed

+210
-1
lines changed

7 files changed

+210
-1
lines changed

src/parser/tag.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ pub fn get_sql_from_expr(
6363
.iter()
6464
.map(|tpl_element| SQL {
6565
var_decl_name: var_decl_name.to_owned(),
66-
query: tpl_element.raw.to_string(),
66+
query: tpl_element
67+
.cooked
68+
.as_ref()
69+
.map(|c| c.to_atom_lossy().to_string())
70+
.unwrap_or_else(|| tpl_element.raw.to_string()),
6771
span: span.clone(),
6872
})
6973
.collect();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export type BacktickTableNameParams = [];
2+
3+
export interface IBacktickTableNameResult {
4+
flavor_text: string | null;
5+
id: number;
6+
inventory_id: number | null;
7+
name: string;
8+
rarity: string | null;
9+
}
10+
11+
export interface IBacktickTableNameQuery {
12+
params: BacktickTableNameParams;
13+
result: IBacktickTableNameResult;
14+
}
15+
16+
export type BacktickQualifiedNameParams = [];
17+
18+
export interface IBacktickQualifiedNameResult {
19+
flavor_text: string | null;
20+
id: number;
21+
inventory_id: number | null;
22+
name: string;
23+
rarity: string | null;
24+
}
25+
26+
export interface IBacktickQualifiedNameQuery {
27+
params: BacktickQualifiedNameParams;
28+
result: IBacktickQualifiedNameResult;
29+
}
30+
31+
export type BacktickColumnNamesParams = [number];
32+
33+
export interface IBacktickColumnNamesResult {
34+
id: number;
35+
name: string;
36+
}
37+
38+
export interface IBacktickColumnNamesQuery {
39+
params: BacktickColumnNamesParams;
40+
result: IBacktickColumnNamesResult;
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export type BacktickTableNameParams = [];
2+
3+
export interface IBacktickTableNameResult {
4+
flavor_text: string | null;
5+
id: number;
6+
inventory_id: number | null;
7+
name: string;
8+
rarity: string | null;
9+
}
10+
11+
export interface IBacktickTableNameQuery {
12+
params: BacktickTableNameParams;
13+
result: IBacktickTableNameResult;
14+
}
15+
16+
export type BacktickQualifiedNameParams = [];
17+
18+
export interface IBacktickQualifiedNameResult {
19+
flavor_text: string | null;
20+
id: number;
21+
inventory_id: number | null;
22+
name: string;
23+
rarity: string | null;
24+
}
25+
26+
export interface IBacktickQualifiedNameQuery {
27+
params: BacktickQualifiedNameParams;
28+
result: IBacktickQualifiedNameResult;
29+
}
30+
31+
export type BacktickColumnNamesParams = [number];
32+
33+
export interface IBacktickColumnNamesResult {
34+
id: number;
35+
name: string;
36+
}
37+
38+
export interface IBacktickColumnNamesQuery {
39+
params: BacktickColumnNamesParams;
40+
result: IBacktickColumnNamesResult;
41+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { sql } from 'sqlx-ts'
2+
3+
// Issue #265: Backtick-escaped table names should work
4+
const backtickTableName = sql`
5+
-- @db: db_mysql
6+
-- @name: backtick table name
7+
SELECT * FROM \`items\`
8+
`
9+
10+
// Issue #265: Backtick-escaped qualified table names (db.table)
11+
const backtickQualifiedName = sql`
12+
-- @db: db_mysql
13+
-- @name: backtick qualified name
14+
SELECT * FROM \`sqlx-ts\`.\`items\`
15+
`
16+
17+
// Issue #265: Backtick-escaped column names
18+
const backtickColumnNames = sql`
19+
-- @db: db_mysql
20+
-- @name: backtick column names
21+
SELECT \`id\`, \`name\` FROM \`items\` WHERE \`id\` = ?
22+
`
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export type DoubleQuoteTableNameParams = [];
2+
3+
export interface IDoubleQuoteTableNameResult {
4+
flavor_text: string | null;
5+
id: number;
6+
inventory_id: number | null;
7+
name: string;
8+
rarity: string | null;
9+
}
10+
11+
export interface IDoubleQuoteTableNameQuery {
12+
params: DoubleQuoteTableNameParams;
13+
result: IDoubleQuoteTableNameResult;
14+
}
15+
16+
export type DoubleQuoteQualifiedNameParams = [];
17+
18+
export interface IDoubleQuoteQualifiedNameResult {
19+
flavor_text: string | null;
20+
id: number;
21+
inventory_id: number | null;
22+
name: string;
23+
rarity: string | null;
24+
}
25+
26+
export interface IDoubleQuoteQualifiedNameQuery {
27+
params: DoubleQuoteQualifiedNameParams;
28+
result: IDoubleQuoteQualifiedNameResult;
29+
}
30+
31+
export type DoubleQuoteColumnNamesParams = [number];
32+
33+
export interface IDoubleQuoteColumnNamesResult {
34+
id: number;
35+
name: string;
36+
}
37+
38+
export interface IDoubleQuoteColumnNamesQuery {
39+
params: DoubleQuoteColumnNamesParams;
40+
result: IDoubleQuoteColumnNamesResult;
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export type DoubleQuoteTableNameParams = [];
2+
3+
export interface IDoubleQuoteTableNameResult {
4+
flavor_text: string | null;
5+
id: number;
6+
inventory_id: number | null;
7+
name: string;
8+
rarity: string | null;
9+
}
10+
11+
export interface IDoubleQuoteTableNameQuery {
12+
params: DoubleQuoteTableNameParams;
13+
result: IDoubleQuoteTableNameResult;
14+
}
15+
16+
export type DoubleQuoteQualifiedNameParams = [];
17+
18+
export interface IDoubleQuoteQualifiedNameResult {
19+
flavor_text: string | null;
20+
id: number;
21+
inventory_id: number | null;
22+
name: string;
23+
rarity: string | null;
24+
}
25+
26+
export interface IDoubleQuoteQualifiedNameQuery {
27+
params: DoubleQuoteQualifiedNameParams;
28+
result: IDoubleQuoteQualifiedNameResult;
29+
}
30+
31+
export type DoubleQuoteColumnNamesParams = [number];
32+
33+
export interface IDoubleQuoteColumnNamesResult {
34+
id: number;
35+
name: string;
36+
}
37+
38+
export interface IDoubleQuoteColumnNamesQuery {
39+
params: DoubleQuoteColumnNamesParams;
40+
result: IDoubleQuoteColumnNamesResult;
41+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { sql } from 'sqlx-ts'
2+
3+
// Issue #265: Double-quoted identifiers should work in PostgreSQL
4+
const doubleQuoteTableName = sql`
5+
-- @name: double quote table name
6+
SELECT * FROM "items"
7+
`
8+
9+
// Double-quoted qualified table names (schema.table)
10+
const doubleQuoteQualifiedName = sql`
11+
-- @name: double quote qualified name
12+
SELECT * FROM "public"."items"
13+
`
14+
15+
// Double-quoted column names with param
16+
const doubleQuoteColumnNames = sql`
17+
-- @name: double quote column names
18+
SELECT "id", "name" FROM "items" WHERE "id" = $1
19+
`

0 commit comments

Comments
 (0)