Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gajus/slonik-interceptor-field-name-transformation
Transforms Slonik query result field names.
https://github.com/gajus/slonik-interceptor-field-name-transformation
postgresql slonik
Last synced: 29 days ago
JSON representation
Transforms Slonik query result field names.
- Host: GitHub
- URL: https://github.com/gajus/slonik-interceptor-field-name-transformation
- Owner: gajus
- License: other
- Created: 2019-02-22T14:56:39.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-07T18:29:58.000Z (6 months ago)
- Last Synced: 2024-09-27T20:21:15.208Z (about 1 month ago)
- Topics: postgresql, slonik
- Language: TypeScript
- Size: 2.59 MB
- Stars: 10
- Watchers: 2
- Forks: 3
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slonik-interceptor-field-name-transformation
[![Travis build status](http://img.shields.io/travis/gajus/slonik-interceptor-field-name-transformation/master.svg?style=flat-square)](https://travis-ci.com/github/gajus/slonik-interceptor-field-name-transformation)
[![Coveralls](https://img.shields.io/coveralls/gajus/slonik-interceptor-field-name-transformation.svg?style=flat-square)](https://coveralls.io/github/gajus/slonik-interceptor-field-name-transformation)
[![NPM version](http://img.shields.io/npm/v/slonik-interceptor-field-name-transformation.svg?style=flat-square)](https://www.npmjs.org/package/slonik-interceptor-field-name-transformation)
[![Canonical Code Style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
[![Twitter Follow](https://img.shields.io/twitter/follow/kuizinas.svg?style=social&label=Follow)](https://twitter.com/kuizinas)Transforms [Slonik](https://github.com/gajus/slonik) query result field names.
> [!WARNING]
> Deprecated in favor of https://github.com/gajus/slonik monorepo.## Motivation
This interceptor removes the necessity to alias field names, e.g.
```ts
connection.any(sql`
SELECT
id,
full_name "fullName"
FROM person
`);
```Field name transformation uses `afterQuery` interceptor method to format field names.
## API
```ts
import {
createFieldNameTransformationInterceptor
} from 'slonik-interceptor-field-name-transformation';
``````ts
/**
* @property format The only supported format is CAMEL_CASE.
* @property test Tests whether the field should be formatted. The default behaviour is to include all fields that match ^[a-z0-9_]+$ regex.
*/
type ConfigurationType = {|
+format: 'CAMEL_CASE',
+test: (field: FieldType) => boolean
|};(configuration: ConfigurationType) => InterceptorType;
```## Example usage
```ts
import {
createPool
} from 'slonik';
import {
createFieldNameTransformationInterceptor
} from 'slonik-interceptor-field-name-transformation';const interceptors = [
createFieldNameTransformationInterceptor({
format: 'CAMEL_CASE'
})
];const connection = createPool('postgres://', {
interceptors
});connection.any(sql`
SELECT
id,
full_name
FROM person
`);// [
// {
// id: 1,
// fullName: 1
// }
// ]
```