Skip to content

Commit e1a21ad

Browse files
committed
Add simple() - fixes porsager#472
1 parent 65dcf0d commit e1a21ad

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/query.js

+7-3
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

+14
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,20 @@ t('unsafe describe', async() => {
628628
]
629629
})
630630

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

0 commit comments

Comments
 (0)