Skip to content

Commit 6b49449

Browse files
committed
build
1 parent 364c3eb commit 6b49449

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

cjs/src/connection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
166166
build(q)
167167
return write(toBuffer(q))
168168
&& !q.describeFirst
169+
&& !q.cursorFn
169170
&& sent.length < max_pipeline
170171
&& (!q.options.onexecute || q.options.onexecute(connection))
171172
} catch (error) {

cjs/tests/index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const crypto = require('crypto')
88
const postgres = require('../src/index.js')
99
const delay = ms => new Promise(r => setTimeout(r, ms))
1010

11-
const rel = x => require('path').join(__dirname, x)
11+
const rel = x => require("path").join(__dirname, x)
1212
const idle_timeout = 1
1313

1414
const login = {
@@ -2477,3 +2477,24 @@ t('Insert array with undefined transform', async() => {
24772477
await sql`drop table test`
24782478
]
24792479
})
2480+
2481+
t('concurrent cursors', async() => {
2482+
const xs = []
2483+
2484+
await Promise.all([...Array(7)].map((x, i) => [
2485+
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
2486+
]).flat())
2487+
2488+
return ['12233445566778', xs.join('')]
2489+
})
2490+
2491+
t('concurrent cursors multiple connections', async() => {
2492+
const sql = postgres({ ...options, max: 2 })
2493+
const xs = []
2494+
2495+
await Promise.all([...Array(7)].map((x, i) => [
2496+
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
2497+
]).flat())
2498+
2499+
return ['12233445566778', xs.sort().join('')]
2500+
})

deno/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,28 @@ If you know what you're doing, you can use `unsafe` to pass any string you'd lik
524524
```js
525525
sql.unsafe('select ' + danger + ' from users where id = ' + dragons)
526526
```
527+
528+
You can also nest `sql.unsafe` within a safe `sql` expression. This is useful if only part of your fraction has unsafe elements.
529+
530+
```js
531+
const triggerName = 'friend_created'
532+
const triggerFnName = 'on_friend_created'
533+
const eventType = 'insert'
534+
const schema_name = 'app'
535+
const table_name = 'friends'
536+
537+
await sql`
538+
create or replace trigger ${sql(triggerName)}
539+
after ${sql.unsafe(eventType)} on ${sql.unsafe(`${schema_name}.${table_name}`)}
540+
for each row
541+
execute function ${sql(triggerFnName)}()
542+
`
543+
544+
await sql`
545+
create role friend_service with login password ${sql.unsafe(`'${password}'`)}
546+
`
547+
```
548+
527549
</details>
528550

529551
## Transactions

deno/src/connection.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
170170
build(q)
171171
return write(toBuffer(q))
172172
&& !q.describeFirst
173+
&& !q.cursorFn
173174
&& sent.length < max_pipeline
174175
&& (!q.options.onexecute || q.options.onexecute(connection))
175176
} catch (error) {

deno/tests/index.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2480,4 +2480,25 @@ t('Insert array with undefined transform', async() => {
24802480
]
24812481
})
24822482

2483-
;window.addEventListener('unload', () => Deno.exit(process.exitCode))
2483+
t('concurrent cursors', async() => {
2484+
const xs = []
2485+
2486+
await Promise.all([...Array(7)].map((x, i) => [
2487+
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
2488+
]).flat())
2489+
2490+
return ['12233445566778', xs.join('')]
2491+
})
2492+
2493+
t('concurrent cursors multiple connections', async() => {
2494+
const sql = postgres({ ...options, max: 2 })
2495+
const xs = []
2496+
2497+
await Promise.all([...Array(7)].map((x, i) => [
2498+
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
2499+
]).flat())
2500+
2501+
return ['12233445566778', xs.sort().join('')]
2502+
})
2503+
2504+
;window.addEventListener("unload", () => Deno.exit(process.exitCode))

0 commit comments

Comments
 (0)