Comparing version 3.0.0-rc.1 to 3.0.0-rc.2
@@ -538,5 +538,7 @@ const net = require('net') | ||
connection.reserved | ||
? x[5] === 73 | ||
? ending && terminate() | ||
: connection.reserved() // I | ||
? x[5] === 73 // I | ||
? ending | ||
? terminate() | ||
: (connection.reserved = null, onopen(connection)) | ||
: connection.reserved() | ||
: ending | ||
@@ -543,0 +545,0 @@ ? terminate() |
@@ -196,7 +196,2 @@ const os = require('os') | ||
throw error | ||
} finally { | ||
if (connection) { | ||
connection.reserved = null | ||
onopen(connection) | ||
} | ||
} | ||
@@ -203,0 +198,0 @@ |
{ | ||
"name": "postgres", | ||
"version": "3.0.0-rc.1", | ||
"version": "3.0.0-rc.2", | ||
"description": "Fastest full featured PostgreSQL client for Node.js", | ||
@@ -5,0 +5,0 @@ "type": "module", |
109
README.md
@@ -1,2 +0,2 @@ | ||
<img align="left" width="440" height="180" alt="Fastest full PostgreSQL nodejs client" src="https://raw.githubusercontent.com/porsager/postgres/master/postgresjs.svg?sanitize=true" /> | ||
<img align="left" width="440" height="180" alt="Fastest full PostgreSQL nodejs client" src="https://raw.githubusercontent.com/porsager/postgres/master/postgresjs.svg?sanitize=true"> | ||
@@ -14,3 +14,3 @@ - [🚀 Fastest full-featured node & deno client](https://github.com/porsager/postgres-benchmarks#results) | ||
<br> | ||
<img height="220" alt="Good UX with Postgres.js" src="https://raw.githubusercontent.com/porsager/postgres/master/demo.gif" /> | ||
<img height="220" alt="Good UX with Postgres.js" src="https://raw.githubusercontent.com/porsager/postgres/master/demo.gif"> | ||
<br> | ||
@@ -41,5 +41,5 @@ | ||
const users = await sql` | ||
select | ||
select | ||
name, | ||
age | ||
age | ||
from users | ||
@@ -55,5 +55,5 @@ where age > ${ age } | ||
const users = sql` | ||
insert into users | ||
(name, age) | ||
values | ||
insert into users | ||
(name, age) | ||
values | ||
(${ name }, ${ age }) | ||
@@ -65,4 +65,2 @@ returning name, age | ||
} | ||
``` | ||
@@ -113,3 +111,3 @@ | ||
1. **Enforcing** safe query generation | ||
2. Giving the `sql`` ` function powerful [utility](#dynamic-inserts) and [query building](#building-queries) features. | ||
2. Giving the ` sql`` ` function powerful [utility](#dynamic-inserts) and [query building](#building-queries) features. | ||
@@ -121,3 +119,2 @@ Any generic value will be serialized according to an inferred type, and replaced by a PostgreSQL protocol placeholder `$1, $2, ...`. The parameters are then sent separately to the database which handles escaping & casting. | ||
```js | ||
const xs = await sql` | ||
@@ -166,4 +163,4 @@ insert into users ( | ||
sql` | ||
select | ||
${ sql(columns) } | ||
select | ||
${ sql(columns) } | ||
from users | ||
@@ -204,3 +201,3 @@ ` | ||
garbage: 'ignore' | ||
}, | ||
}, | ||
{ | ||
@@ -224,3 +221,3 @@ name: 'Walter', | ||
### Dynamic columns in updates | ||
This is also useful for update queries | ||
This is also useful for update queries | ||
```js | ||
@@ -236,3 +233,3 @@ const user = { | ||
sql(user, 'name', 'age') | ||
} | ||
} | ||
where user_id = ${ user.id } | ||
@@ -245,3 +242,3 @@ ` | ||
### Dyanmic values and `where in` | ||
### Dynamic values and `where in` | ||
Value lists can also be created dynamically, making `where in` queries simple too. | ||
@@ -257,8 +254,9 @@ ```js | ||
or | ||
or | ||
```js | ||
const [{ a, b, c }] => await sql` | ||
select | ||
* | ||
select | ||
* | ||
from (values ${ sql(['a', 'b', 'c']) }) as x(a, b, c) | ||
` | ||
``` | ||
@@ -280,3 +278,3 @@ | ||
* | ||
from users | ||
from users | ||
where name is not null ${ | ||
@@ -296,7 +294,7 @@ filterAge | ||
```js | ||
sql` | ||
sql` | ||
select | ||
* | ||
from users ${ | ||
id | ||
id | ||
? sql`where user_id = ${ id }` | ||
@@ -318,3 +316,3 @@ : sql`` | ||
sql` | ||
sql` | ||
update users set updated_at = ${ date || sql`now()` } | ||
@@ -352,4 +350,4 @@ ` | ||
await sql` | ||
select | ||
* | ||
select | ||
* | ||
from generate_series(1,4) as x | ||
@@ -376,4 +374,4 @@ `.cursor(async([row]) => { | ||
await sql` | ||
select | ||
* | ||
select | ||
* | ||
from generate_series(1,1000) as x | ||
@@ -393,9 +391,7 @@ `.cursor(10, async rows => { | ||
```js | ||
await sql` | ||
select * from generate_series(1,1000) as x | ||
`.cursor(row => { | ||
return Math.random() > 0.9 && sql.END | ||
return Math.random() > 0.9 && sql.CLOSE // or sql.END | ||
}) | ||
``` | ||
@@ -409,3 +405,2 @@ | ||
```js | ||
await sql` | ||
@@ -420,3 +415,3 @@ select created_at, name from events | ||
### describe | ||
### describe | ||
#### ```await sql``.describe([rows = 1], fn) -> Result[]``` | ||
@@ -441,5 +436,3 @@ | ||
```js | ||
const result = await sql.file('query.sql', ['Murray', 68]) | ||
``` | ||
@@ -452,7 +445,5 @@ | ||
```js | ||
const query = sql`select pg_sleep 100`.execute() | ||
setTimeout(() => query.cancel(), 100) | ||
const result = await query | ||
``` | ||
@@ -467,8 +458,6 @@ | ||
If you know what you're doing, you can use `unsafe` to pass any string you'd like to postgres. Please note that this can lead to sql injection if you're not careful. | ||
If you know what you're doing, you can use `unsafe` to pass any string you'd like to postgres. Please note that this can lead to SQL injection if you're not careful. | ||
```js | ||
sql.unsafe('select ' + danger + ' from users where id = ' + dragons) | ||
``` | ||
@@ -486,3 +475,2 @@ </details> | ||
```js | ||
const [user, account] = await sql.begin(async sql => { | ||
@@ -507,3 +495,2 @@ const [user] = await sql` | ||
}) | ||
``` | ||
@@ -514,3 +501,2 @@ | ||
```js | ||
const result = await sql.begin(sql => [ | ||
@@ -521,3 +507,2 @@ sql`update ...`, | ||
]) | ||
``` | ||
@@ -528,3 +513,2 @@ | ||
```js | ||
sql.begin('read write', async sql => { | ||
@@ -539,3 +523,3 @@ const [user] = await sql` | ||
const [account] = (await sql.savepoint(sql => | ||
const [account] = (await sql.savepoint(sql => | ||
sql` | ||
@@ -560,3 +544,2 @@ insert into accounts ( | ||
}) | ||
``` | ||
@@ -573,3 +556,2 @@ | ||
```js | ||
await sql.listen('news', payload => { | ||
@@ -579,10 +561,7 @@ const json = JSON.parse(payload) | ||
}) | ||
``` | ||
Notify can be done as usual in sql, or by using the `sql.notify` method. | ||
Notify can be done as usual in SQL, or by using the `sql.notify` method. | ||
```js | ||
sql.notify('news', JSON.stringify({ no: 'this', is: 'news' })) | ||
``` | ||
@@ -620,3 +599,3 @@ | ||
**`schema`** defaults to `public.` | ||
**`schema`** defaults to `public` | ||
@@ -641,3 +620,3 @@ **`table`** is a specific table name and defaults to `*` | ||
Since Node.js v10.4 we can use [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) to match the PostgreSQL type `bigint` which is returned for eg. `count(*)`. Unfortunately, it doesn't work with `JSON.stringify` out of the box, so Postgres.js will return it as a string. | ||
Since Node.js v10.4 we can use [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) to match the PostgreSQL type `bigint` which is returned for eg. `count(*)`. Unfortunately, it doesn't work with `JSON.stringify` out of the box, so Postgres.js will return it as a string. | ||
@@ -654,3 +633,3 @@ If you want to use `BigInt` you can add this custom type: | ||
There is currently no guaranteed way to handle `numeric / decimal` types in native Javascript. **These [and similar] types will be returned as a `string`**. The best way in this case is to use [custom types](#custom-types). | ||
There is currently no guaranteed way to handle `numeric` / `decimal` types in native Javascript. **These [and similar] types will be returned as a `string`**. The best way in this case is to use [custom types](#custom-types). | ||
@@ -664,3 +643,3 @@ | ||
const sql = postgres('postgres://username:password@host:port/database', { | ||
host : '', // Postgres ip address[s] or domain name[s] | ||
host : '', // Postgres ip address[es] or domain name[s] | ||
port : 5432, // Postgres server port[s] | ||
@@ -690,3 +669,3 @@ path : '', // unix socket path (usually '/tmp') | ||
}, | ||
target_session_attrs : null, // Use 'read-write' with multiple hosts to | ||
target_session_attrs : null, // Use 'read-write' with multiple hosts to | ||
// ensure only connecting to primary | ||
@@ -718,3 +697,3 @@ fetch_types : true, // Automatically fetches types on connect | ||
Multiple connection strings can be passed to `postgres()` in the form of `postgres('postgres://localhost:5432,localhost:5433', ...)`. This works the same as native the `psql` command. Read more at [multiple host uris](https://www.postgresql.org/docs/13/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS) | ||
Multiple connection strings can be passed to `postgres()` in the form of `postgres('postgres://localhost:5432,localhost:5433', ...)`. This works the same as native the `psql` command. Read more at [multiple host URIs](https://www.postgresql.org/docs/13/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS). | ||
@@ -727,5 +706,5 @@ Connections will be attempted in order of the specified hosts/ports. On a successful connection, all retries will be reset. This ensures that hosts can come up and down seamlessly. | ||
Connections are created lazily once a query is created. This means that simply doing const `sql = postgres(...)` won't have any effect other than instantiating a new `sql` instance. | ||
Connections are created lazily once a query is created. This means that simply doing const `sql = postgres(...)` won't have any effect other than instantiating a new `sql` instance. | ||
> No connection will be made until a query is made. | ||
> No connection will be made until a query is made. | ||
@@ -761,5 +740,5 @@ This means that we get a much simpler story for error handling and reconnections. Queries will be sent over the wire immediately on the next available connection in the pool. Connections are automatically taken out of the pool if you start a transaction using `sql.begin()`, and automatically returned to the pool once your transaction is done. | ||
Postgres.js will automatically fetch table/array-type information when it first connects to a database. | ||
Postgres.js will automatically fetch table/array-type information when it first connects to a database. | ||
If you have revoked access to `pg_catalog` this feature will no longer work and will need to be disabled. | ||
If you have revoked access to `pg_catalog` this feature will no longer work and will need to be disabled. | ||
@@ -840,3 +819,2 @@ You can disable this feature by setting `fetch_types` to `false`. | ||
```js | ||
import prexit from 'prexit' | ||
@@ -848,3 +826,2 @@ | ||
}) | ||
``` | ||
@@ -941,3 +918,3 @@ | ||
You can also prefer destructuring when you only care about a fixed number of rows. | ||
In this case, we recommand you to prefer using tuples to handle `undefined` properly: | ||
In this case, we recommend you to prefer using tuples to handle `undefined` properly: | ||
```ts | ||
@@ -954,3 +931,3 @@ const [user]: [User?] = await sql`SELECT * FROM users WHERE id = ${id}` | ||
We do our best to type all the public API, however types are not always updated when features are added ou changed. Feel free to open an issue if you have trouble with types. | ||
We do our best to type all the public API, however types are not always updated when features are added or changed. Feel free to open an issue if you have trouble with types. | ||
@@ -957,0 +934,0 @@ ## Migration tools |
@@ -538,5 +538,7 @@ import net from 'net' | ||
connection.reserved | ||
? x[5] === 73 | ||
? ending && terminate() | ||
: connection.reserved() // I | ||
? x[5] === 73 // I | ||
? ending | ||
? terminate() | ||
: (connection.reserved = null, onopen(connection)) | ||
: connection.reserved() | ||
: ending | ||
@@ -543,0 +545,0 @@ ? terminate() |
@@ -196,7 +196,2 @@ import os from 'os' | ||
throw error | ||
} finally { | ||
if (connection) { | ||
connection.reserved = null | ||
onopen(connection) | ||
} | ||
} | ||
@@ -203,0 +198,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4
182423
4655
904