Skip to content

Commit 2e3652b

Browse files
committed
Fix porsager#188 Support escaping dynamic schemas and tables
1 parent edcb257 commit 2e3652b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function typeHandlers(types) {
6666
}
6767

6868
module.exports.escape = function escape(str) {
69-
return '"' + str.replace(/"/g, '""') + '"'
69+
return '"' + str.replace(/"/g, '""').replace(/\./g, '"."') + '"'
7070
}
7171

7272
const type = {

tests/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -1278,3 +1278,15 @@ t('Multiple hosts', {
12781278

12791279
return ['5432,5433,5432', result.join(',')]
12801280
})
1281+
1282+
t('Escaping supports schemas and tables', async() => {
1283+
await sql`create schema a`
1284+
await sql`create table a.b (c int)`
1285+
await sql`insert into a.b (c) values (1)`
1286+
return [
1287+
1,
1288+
(await sql`select ${ sql('a.b.c') } from a.b`)[0].c,
1289+
await sql`drop table a.b`,
1290+
await sql`drop schema a`
1291+
]
1292+
})

0 commit comments

Comments
 (0)