https://github.com/gajus/slonik-interceptor-preset
Slonik interceptor preset.
https://github.com/gajus/slonik-interceptor-preset
slonik
Last synced: 4 months ago
JSON representation
Slonik interceptor preset.
- Host: GitHub
- URL: https://github.com/gajus/slonik-interceptor-preset
- Owner: gajus
- License: other
- Created: 2019-02-26T12:00:01.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-11-18T14:43:24.000Z (almost 3 years ago)
- Last Synced: 2025-03-29T01:23:52.272Z (7 months ago)
- Topics: slonik
- Language: JavaScript
- Size: 13.7 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slonik-interceptor-preset
[](https://travis-ci.org/gajus/slonik-interceptor-preset)
[](https://www.npmjs.org/package/slonik-interceptor-preset)
[](https://github.com/gajus/canonical)
[](https://twitter.com/kuizinas)
[Slonik](https://github.com/gajus/slonik) interceptor preset.
## Motivation
Slonik functionality is extendable using interceptors. Each interceptor is contained in a separate package. Installing and configuring each interceptor becomes a tedious task when using Slonik across multiple projects. `slonik-interceptor-preset` provides a factory function (`createInterceptors`) for constructing a collection of selected interceptors.
`slonik-interceptor-preset` installs these presets:
|Name|Description|
|---|---|
|[`slonik-interceptor-field-name-transformation`](https://github.com/gajus/slonik-interceptor-field-name-transformation)|Transforms Slonik query result field names.|
|[`slonik-interceptor-query-benchmarking`](https://github.com/gajus/slonik-interceptor-query-benchmarking)|Benchmarks Slonik queries.|
|[`slonik-interceptor-query-logging`](https://github.com/gajus/slonik-interceptor-query-logging)|Logs Slonik queries.|
|[`slonik-interceptor-query-normalisation`](https://github.com/gajus/slonik-interceptor-query-normalisation)|Normalises Slonik queries.|
Each interceptor can be selectively enabled/ disabled (see [API](#api)).
## API
```js
import {
createInterceptors
} from 'slonik-interceptor-preset';
```
```js
/**
* @property benchmarkQueries Dictates whether to enable the [query benchmarking interceptor](https://github.com/gajus/slonik-interceptor-query-benchmarking). (Default: false)
* @property logQueries Dictates whether to enable the [query logging interceptor](https://github.com/gajus/slonik-interceptor-query-logging). (Default: true)
* @property normaliseQueries Dictates whether to enable the [query normalisation interceptor](https://github.com/gajus/slonik-interceptor-query-normalisation). (Default: true)
* @property transformFieldNames Dictates whether to enable the [field name transformation interceptor](https://github.com/gajus/slonik-interceptor-field-name-transformation). (Default: true)
*/
type UserConfigurationType = {|
+benchmarkQueries: boolean,
+logQueries: boolean,
+normaliseQueries: boolean,
+transformFieldNames: boolean
|};
(userConfiguration: UserConfigurationType) => $ReadOnlyArray;
```
## Example usage
```js
import {
createPool
} from 'slonik';
import {
createInterceptors
} from 'slonik-interceptor-preset';
const connection = createPool('postgres://', {
interceptors: [
...createInterceptors()
]
});
```