46.4.0 • Published 6 months ago

slonik-interceptor-field-name-transformation v46.4.0

Weekly downloads
1,697
License
BSD-3-Clause
Repository
github
Last release
6 months ago

slonik-interceptor-field-name-transformation

NPM version Canonical Code Style Twitter Follow

Transforms Slonik query result field names.

Motivation

This interceptor removes the necessity to alias field names, e.g.

connection.any(sql`
  SELECT
    id,
    full_name "fullName"
  FROM person
`);

Field name transformation uses afterQuery interceptor method to format field names.

API

import {
  createFieldNameTransformationInterceptor
} from 'slonik-interceptor-field-name-transformation';
/**
 * @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

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
//   }
// ]
46.3.0

6 months ago

46.2.0

8 months ago

46.4.0

6 months ago

45.6.0

1 year ago

45.5.0

1 year ago

46.1.0

10 months ago

46.0.1

11 months ago

45.4.1

1 year ago

45.4.0

1 year ago

45.3.0

1 year ago

45.2.0

1 year ago

45.1.0

1 year ago

45.0.0

1 year ago

45.2.1

1 year ago

44.0.0

1 year ago

40.2.5

1 year ago

40.2.4

1 year ago

43.0.8

1 year ago

43.0.7

1 year ago

43.0.6

1 year ago

43.0.5

1 year ago

43.0.4

1 year ago

43.0.3

1 year ago

43.0.2

1 year ago

43.0.1

1 year ago

43.0.0

1 year ago

42.0.0

1 year ago

1.6.5

3 years ago

1.6.4

4 years ago

1.6.3

4 years ago

1.6.2

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.3

5 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago