Socket
Socket
Sign inDemoInstall

slonik

Package Overview
Dependencies
Maintainers
1
Versions
395
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slonik - npm Package Compare versions

Comparing version 5.9.0 to 5.10.0

2

package.json

@@ -91,3 +91,3 @@ {

},
"version": "5.9.0"
"version": "5.10.0"
}

@@ -14,2 +14,6 @@ <a name="slonik"></a>

* [Usage](#slonik-usage)
* [Configuration](#slonik-usage-configuration)
* [Interceptors](#slonik-interceptors)
* [`beforeQuery`](#slonik-interceptors-beforequery)
* [`afterQuery`](#slonik-interceptors-afterquery)
* [Non-standard behaviour](#slonik-non-standard-behaviour)

@@ -56,2 +60,24 @@ * [Conventions](#slonik-conventions)

Example:
```js
import {
createPool
} from 'slonik';
const connection = createPool({
host: '127.0.0.1'
});
await connection.query('SELECT 1');
```
The API of the query method is equivalent to that of [`pg`](https://travis-ci.org/brianc/node-postgres).
Refer to [query methods](#slonik-query-methods) for documentation of Slonik-specific query methods.
<a name="slonik-usage-configuration"></a>
### Configuration
Both functions accept the same parameters:

@@ -84,9 +110,21 @@

The API of the query method is equivalent to that of [`pg`](https://travis-ci.org/brianc/node-postgres).
Refer to [query methods](#slonik-query-methods) for documentation of Slonik-specific query methods.
<a name="slonik-interceptors"></a>
## Interceptors
Example:
Functionality can be added to Slonik client by adding interceptors.
Each interceptor can implement several functions which can be used to change the behaviour of the database client.
```js
type InterceptorType = {|
+beforeQuery?: (query: QueryType) => Promise<QueryResultType<QueryResultRowType>> | Promise<void> | QueryResultType<QueryResultRowType> | void,
+afterQuery?: (query: QueryType, result: QueryResultType<QueryResultRowType>) => Promise<void> | void
|};
```
Interceptors are configured using [client configuration](#slonik-usage-configuration), e.g.
```js
import {

@@ -96,11 +134,30 @@ createPool

const connection = createPool({
host: '127.0.0.1'
const interceptors = [];
const connection = createPool('postgres://', {
interceptors
});
await connection.query('SELECT 1');
```
There are 2 functions that an interceptor can implement:
* beforeQuery
* afterQuery
Interceptors are executed in the order they are added.
<a name="slonik-interceptors-beforequery"></a>
### <code>beforeQuery</code>
`beforeQuery` is the first interceptor function executed.
This function can optionally return a direct result of the query which will cause the actual query never to be executed.
<a name="slonik-interceptors-afterquery"></a>
### <code>afterQuery</code>
`afterQuery` is the last interceptor function executed.
<a name="slonik-non-standard-behaviour"></a>

@@ -107,0 +164,0 @@ ## Non-standard behaviour

@@ -38,2 +38,3 @@ // @flow

InternalQueryAnyFunctionType,
InternalQueryFunctionType,
InternalQueryManyFirstFunctionType,

@@ -45,3 +46,2 @@ InternalQueryManyFunctionType,

InternalQueryOneFunctionType,
InternalQueryFunctionType,
InternalTransactionFunctionType,

@@ -87,3 +87,4 @@ TaggledTemplateLiteralInvocationType

DatabasePoolType,
DatabaseSingleConnectionType
DatabaseSingleConnectionType,
InterceptorType
} from './types';

@@ -90,0 +91,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc