Skip to content

Commit 22c7029

Browse files
committed
build
1 parent 0dac913 commit 22c7029

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

cjs/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ function Postgres(a, b) {
7575
PostgresError,
7676
options,
7777
listen,
78-
notify,
7978
begin,
8079
close,
8180
end
@@ -95,6 +94,7 @@ function Postgres(a, b) {
9594
types: typed,
9695
typed,
9796
unsafe,
97+
notify,
9898
array,
9999
json,
100100
file

cjs/src/types.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ const builders = Object.entries({
159159
select,
160160
as: select,
161161
returning: select,
162+
'\\(': select,
162163

163164
update(first, rest, parameters, types, options) {
164165
return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
@@ -200,8 +201,10 @@ const mergeUserTypes = module.exports.mergeUserTypes = function(types) {
200201
function typeHandlers(types) {
201202
return Object.keys(types).reduce((acc, k) => {
202203
types[k].from && [].concat(types[k].from).forEach(x => acc.parsers[x] = types[k].parse)
203-
acc.serializers[types[k].to] = types[k].serialize
204-
types[k].from && [].concat(types[k].from).forEach(x => acc.serializers[x] = types[k].serialize)
204+
if (types[k].serialize) {
205+
acc.serializers[types[k].to] = types[k].serialize
206+
types[k].from && [].concat(types[k].from).forEach(x => acc.serializers[x] = types[k].serialize)
207+
}
205208
return acc
206209
}, { parsers: {}, serializers: {} })
207210
}

deno/README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ const users = [
238238
]
239239

240240
sql`
241-
update users set name = update_data.name, age = update_data.age
241+
update users set name = update_data.name, (age = update_data.age)::int
242242
from (values ${sql(users)}) as update_data (id, name, age)
243-
where users.id = update_data.id
243+
where users.id = (update_data.id)::int
244+
returning users.id, users.name, users.age
244245
`
245246
```
246247

@@ -449,6 +450,11 @@ Using a file for a query is also supported with optional parameters to use if th
449450
const result = await sql.file('query.sql', ['Murray', 68])
450451
```
451452

453+
### Multiple statements in one query
454+
#### `await sql`select 1;select 2`.simple()
455+
456+
The postgres wire protocol supports "simple" and "extended" queries. "simple" queries supports multiple statements, but does not support any dynamic parameters. "extended" queries support parameters but only one statement. To use "simple" queries you can use sql``.simple(). That will create it as a simple query.
457+
452458
### Copy to/from as Streams
453459

454460
Postgres.js supports [`COPY ...`](https://www.postgresql.org/docs/14/sql-copy.html) queries, which are exposed as [Node.js streams](https://nodejs.org/api/stream.html).

deno/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ function Postgres(a, b) {
7676
PostgresError,
7777
options,
7878
listen,
79-
notify,
8079
begin,
8180
close,
8281
end
@@ -96,6 +95,7 @@ function Postgres(a, b) {
9695
types: typed,
9796
typed,
9897
unsafe,
98+
notify,
9999
array,
100100
json,
101101
file

deno/src/types.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ const builders = Object.entries({
160160
select,
161161
as: select,
162162
returning: select,
163+
'\\(': select,
163164

164165
update(first, rest, parameters, types, options) {
165166
return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
@@ -201,8 +202,10 @@ export const mergeUserTypes = function(types) {
201202
function typeHandlers(types) {
202203
return Object.keys(types).reduce((acc, k) => {
203204
types[k].from && [].concat(types[k].from).forEach(x => acc.parsers[x] = types[k].parse)
204-
acc.serializers[types[k].to] = types[k].serialize
205-
types[k].from && [].concat(types[k].from).forEach(x => acc.serializers[x] = types[k].serialize)
205+
if (types[k].serialize) {
206+
acc.serializers[types[k].to] = types[k].serialize
207+
types[k].from && [].concat(types[k].from).forEach(x => acc.serializers[x] = types[k].serialize)
208+
}
206209
return acc
207210
}, { parsers: {}, serializers: {} })
208211
}

deno/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ declare namespace postgres {
638638
type ParameterOrFragment<T> =
639639
| SerializableParameter<T>
640640
| Fragment
641+
| Fragment[]
641642

642643
interface Sql<TTypes extends Record<string, unknown> = {}> {
643644
/**

0 commit comments

Comments
 (0)