Skip to content

Commit 1a4c766

Browse files
committed
Add simple() - fixes #472
1 parent 7fc785c commit 1a4c766

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/query.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,20 @@ export class Query extends Promise {
5454
return this.canceller && (this.canceller(this), this.canceller = null)
5555
}
5656

57-
async readable() {
57+
simple() {
5858
this.options.simple = true
5959
this.options.prepare = false
60+
return this
61+
}
62+
63+
async readable() {
64+
this.simple()
6065
this.streaming = true
6166
return this
6267
}
6368

6469
async writable() {
65-
this.options.simple = true
66-
this.options.prepare = false
70+
this.simple()
6771
this.streaming = true
6872
return this
6973
}

tests/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,20 @@ t('unsafe describe', async() => {
629629
]
630630
})
631631

632+
t('simple query using unsafe with multiple statements', async() => {
633+
return [
634+
'1,2',
635+
(await sql.unsafe('select 1 as x;select 2 as x')).map(x => x[0].x).join()
636+
]
637+
})
638+
639+
t('simple query using simple() with multiple statements', async() => {
640+
return [
641+
'1,2',
642+
(await sql`select 1 as x;select 2 as x`.simple()).map(x => x[0].x).join()
643+
]
644+
})
645+
632646
t('listen and notify', async() => {
633647
const sql = postgres(options)
634648
const channel = 'hello'

0 commit comments

Comments
 (0)