Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
porsager committed May 16, 2023
1 parent 364c3eb commit 6b49449
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions cjs/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
build(q)
return write(toBuffer(q))
&& !q.describeFirst
&& !q.cursorFn
&& sent.length < max_pipeline
&& (!q.options.onexecute || q.options.onexecute(connection))
} catch (error) {
Expand Down
23 changes: 22 additions & 1 deletion cjs/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const crypto = require('crypto')
const postgres = require('../src/index.js')
const delay = ms => new Promise(r => setTimeout(r, ms))

const rel = x => require('path').join(__dirname, x)
const rel = x => require("path").join(__dirname, x)
const idle_timeout = 1

const login = {
Expand Down Expand Up @@ -2477,3 +2477,24 @@ t('Insert array with undefined transform', async() => {
await sql`drop table test`
]
})

t('concurrent cursors', async() => {
const xs = []

await Promise.all([...Array(7)].map((x, i) => [
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
]).flat())

return ['12233445566778', xs.join('')]
})

t('concurrent cursors multiple connections', async() => {
const sql = postgres({ ...options, max: 2 })
const xs = []

await Promise.all([...Array(7)].map((x, i) => [
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
]).flat())

return ['12233445566778', xs.sort().join('')]
})
22 changes: 22 additions & 0 deletions deno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,28 @@ If you know what you're doing, you can use `unsafe` to pass any string you'd lik
```js
sql.unsafe('select ' + danger + ' from users where id = ' + dragons)
```

You can also nest `sql.unsafe` within a safe `sql` expression. This is useful if only part of your fraction has unsafe elements.

```js
const triggerName = 'friend_created'
const triggerFnName = 'on_friend_created'
const eventType = 'insert'
const schema_name = 'app'
const table_name = 'friends'

await sql`
create or replace trigger ${sql(triggerName)}
after ${sql.unsafe(eventType)} on ${sql.unsafe(`${schema_name}.${table_name}`)}
for each row
execute function ${sql(triggerFnName)}()
`

await sql`
create role friend_service with login password ${sql.unsafe(`'${password}'`)}
`
```

</details>

## Transactions
Expand Down
1 change: 1 addition & 0 deletions deno/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
build(q)
return write(toBuffer(q))
&& !q.describeFirst
&& !q.cursorFn
&& sent.length < max_pipeline
&& (!q.options.onexecute || q.options.onexecute(connection))
} catch (error) {
Expand Down
23 changes: 22 additions & 1 deletion deno/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2480,4 +2480,25 @@ t('Insert array with undefined transform', async() => {
]
})

;window.addEventListener('unload', () => Deno.exit(process.exitCode))
t('concurrent cursors', async() => {
const xs = []

await Promise.all([...Array(7)].map((x, i) => [
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
]).flat())

return ['12233445566778', xs.join('')]
})

t('concurrent cursors multiple connections', async() => {
const sql = postgres({ ...options, max: 2 })
const xs = []

await Promise.all([...Array(7)].map((x, i) => [
sql`select ${ i }::int as a, generate_series(1, 2) as x`.cursor(([x]) => xs.push(x.a + x.x))
]).flat())

return ['12233445566778', xs.sort().join('')]
})

;window.addEventListener("unload", () => Deno.exit(process.exitCode))

0 comments on commit 6b49449

Please sign in to comment.