Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cf/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -769,15 +769,17 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose

async function fetchArrayTypes() {
needsTypes = false
const types = await new Query([`
const query = new Query([`
select b.oid, b.typarray
from pg_catalog.pg_type a
left join pg_catalog.pg_type b on b.oid = a.typelem
where a.typcategory = 'A'
group by b.oid, b.typarray
order by b.oid
`], [], execute)
types.forEach(({ oid, typarray }) => addArrayType(oid, typarray))
const resolve = query.resolve
query.resolve = types => (types.forEach(({ oid, typarray }) => addArrayType(oid, typarray)), resolve(types))
await query
}

function addArrayType(oid, typarray) {
Expand Down
6 changes: 4 additions & 2 deletions cjs/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,15 +767,17 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose

async function fetchArrayTypes() {
needsTypes = false
const types = await new Query([`
const query = new Query([`
select b.oid, b.typarray
from pg_catalog.pg_type a
left join pg_catalog.pg_type b on b.oid = a.typelem
where a.typcategory = 'A'
group by b.oid, b.typarray
order by b.oid
`], [], execute)
types.forEach(({ oid, typarray }) => addArrayType(oid, typarray))
const resolve = query.resolve
query.resolve = types => (types.forEach(({ oid, typarray }) => addArrayType(oid, typarray)), resolve(types))
await query
}

function addArrayType(oid, typarray) {
Expand Down
7 changes: 7 additions & 0 deletions cjs/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ t('Escape in arrays', async() =>
['Hello "you",c:\\windows', (await sql`select ${ sql.array(['Hello "you"', 'c:\\windows']) } as x`)[0].x.join(',')]
)

t('Array in first query of new client', async() => {
const sql = postgres(options)
const x = (await sql`select ${ sql.array([1, 2]) }::int[] as x`)[0].x
await sql.end()
return ['1,2', x.join()]
})

t('Escapes', async() => {
return ['hej"hej', Object.keys((await sql`select 1 as ${ sql('hej"hej') }`)[0])[0]]
})
Expand Down
6 changes: 4 additions & 2 deletions deno/src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -770,15 +770,17 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose

async function fetchArrayTypes() {
needsTypes = false
const types = await new Query([`
const query = new Query([`
select b.oid, b.typarray
from pg_catalog.pg_type a
left join pg_catalog.pg_type b on b.oid = a.typelem
where a.typcategory = 'A'
group by b.oid, b.typarray
order by b.oid
`], [], execute)
types.forEach(({ oid, typarray }) => addArrayType(oid, typarray))
const resolve = query.resolve
query.resolve = types => (types.forEach(({ oid, typarray }) => addArrayType(oid, typarray)), resolve(types))
await query
}

function addArrayType(oid, typarray) {
Expand Down
7 changes: 7 additions & 0 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ t('Escape in arrays', async() =>
['Hello "you",c:\\windows', (await sql`select ${ sql.array(['Hello "you"', 'c:\\windows']) } as x`)[0].x.join(',')]
)

t('Array in first query of new client', async() => {
const sql = postgres(options)
const x = (await sql`select ${ sql.array([1, 2]) }::int[] as x`)[0].x
await sql.end()
return ['1,2', x.join()]
})

t('Escapes', async() => {
return ['hej"hej', Object.keys((await sql`select 1 as ${ sql('hej"hej') }`)[0])[0]]
})
Expand Down
6 changes: 4 additions & 2 deletions src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,15 +767,17 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose

async function fetchArrayTypes() {
needsTypes = false
const types = await new Query([`
const query = new Query([`
select b.oid, b.typarray
from pg_catalog.pg_type a
left join pg_catalog.pg_type b on b.oid = a.typelem
where a.typcategory = 'A'
group by b.oid, b.typarray
order by b.oid
`], [], execute)
types.forEach(({ oid, typarray }) => addArrayType(oid, typarray))
const resolve = query.resolve
query.resolve = types => (types.forEach(({ oid, typarray }) => addArrayType(oid, typarray)), resolve(types))
await query
}

function addArrayType(oid, typarray) {
Expand Down
7 changes: 7 additions & 0 deletions tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ t('Escape in arrays', async() =>
['Hello "you",c:\\windows', (await sql`select ${ sql.array(['Hello "you"', 'c:\\windows']) } as x`)[0].x.join(',')]
)

t('Array in first query of new client', async() => {
const sql = postgres(options)
const x = (await sql`select ${ sql.array([1, 2]) }::int[] as x`)[0].x
await sql.end()
return ['1,2', x.join()]
})

t('Escapes', async() => {
return ['hej"hej', Object.keys((await sql`select 1 as ${ sql('hej"hej') }`)[0])[0]]
})
Expand Down