Skip to content

Commit 4b24333

Browse files
committed
Include actual number
1 parent ad1b002 commit 4b24333

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

README.md

+33-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
- 🚯 1300 LOC - 0 dependencies
55
- 🏷 ES6 Tagged Template Strings at the core
66
- 🏄‍♀️ Simple surface API
7-
- 🧪 No tests! 0% coverage = infinite coverage!
87

98
## Getting started
109

@@ -44,16 +43,25 @@ You can use either a postgres:// url connection string or the options to define
4443
const sql = postgres('postgres://user:pass@host:port/database', {
4544
host : '', // or hostname
4645
port : 5432, // Postgres server port
47-
path : '', // unix socket path (usually /tmp)
46+
path : '', // unix socket path (usually '/tmp')
4847
database : '', // Database to connect to
4948
username : '', // or username
5049
password : '', // or password
51-
ssl : false, // True, or an object with options to tls.connect
50+
ssl : false, // True, or options for tls.connect
5251
max : 10, // Max number of connections
5352
timeout : 0, // Idle connection timeout in seconds
54-
types : [], // Custom types, see section below
55-
onconnect : null, // Runs on each single connection
56-
onnotice : console.log // Any NOTICE the db sends will be posted here
53+
types : [], // Custom types, see more below
54+
onnotice : fn // Any NOTICE the db sends will be posted here
55+
onparameter : fn // Callback with key, value for server params
56+
transform : {
57+
column : fn, // Transforms incoming column names
58+
value : fn, // Transforms incoming row values
59+
row : fn // Transforms entire rows
60+
},
61+
connection : {
62+
application_name : 'postgres.js', // Default application_name
63+
... // Other connection parameters
64+
}
5765
})
5866

5967
```
@@ -224,13 +232,9 @@ const [{ json }] = await sql`
224232
// json = { hello: 'postgres' }
225233
```
226234

227-
## Unsafe
228-
229-
230-
231-
## File
232-
235+
## File query
233236

237+
Using a file to query
234238

235239
## Transactions
236240

@@ -355,6 +359,18 @@ prexit(async () => {
355359

356360
```
357361

362+
363+
## Unsafe
364+
365+
If you know what you're doing, you can use `unsafe` to pass any string you'd like to postgres.
366+
367+
```js
368+
369+
sql
370+
371+
```
372+
373+
358374
## Errors
359375

360376
Errors are all thrown to related queries and never globally. Errors comming from Postgres itself are always in the [native Postgres format](https://www.postgresql.org/docs/current/errcodes-appendix.html), and the same goes for any [Node.js errors](https://nodejs.org/api/errors.html#errors_common_system_errors) eg. coming from the underlying connection.
@@ -366,6 +382,11 @@ There are also the following errors specifically for this library.
366382
367383
Whenever a message is received from Postgres which is not supported by this library. Feel free to file an issue if you think something is missing.
368384

385+
##### MAX_PARAMETERS_EXCEEDED
386+
> Max number of parameters (65534) exceeded
387+
388+
The postgres protocol doesn't allow more than 65534 (16bit) parameters. If you run into this issue there are various workarounds such as using `sql([...])` to escape values instead of passing them as parameters.
389+
369390
##### SASL_SIGNATURE_MISMATCH
370391
> Message type X not supported
371392

lib/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ function Postgres(url, options) {
426426
, i = types.push(type-type)
427427

428428
if (i > 65534)
429-
throw errors.generic({ message: 'Max number of parameters exceeded', code: 'MAX_PARAMETERS_EXCEEDED' })
429+
throw errors.generic({ message: 'Max number of parameters (65534) exceeded', code: 'MAX_PARAMETERS_EXCEEDED' })
430430

431431
xargs.push(type)
432432
return '$' + i

0 commit comments

Comments
 (0)