46.1.0 • Published 5 months ago
slonik-interceptor-field-name-transformation v46.1.0
slonik-interceptor-field-name-transformation
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
// }
// ]
45.6.0
7 months ago
45.5.0
8 months ago
46.1.0
5 months ago
46.0.1
6 months ago
45.4.1
8 months ago
45.4.0
8 months ago
45.3.0
8 months ago
45.2.0
8 months ago
45.1.0
8 months ago
45.0.0
8 months ago
45.2.1
8 months ago
44.0.0
8 months ago
40.2.5
8 months ago
40.2.4
8 months ago
43.0.8
8 months ago
43.0.7
8 months ago
43.0.6
8 months ago
43.0.5
8 months ago
43.0.4
8 months ago
43.0.3
8 months ago
43.0.2
8 months ago
43.0.1
8 months ago
43.0.0
8 months ago
42.0.0
8 months ago
1.6.5
2 years ago
1.6.4
3 years ago
1.6.3
3 years ago
1.6.2
3 years ago
1.6.1
3 years ago
1.6.0
3 years ago
1.5.3
5 years ago
1.5.2
5 years ago
1.5.1
5 years ago
1.5.0
5 years ago
1.4.2
5 years ago
1.4.1
5 years ago
1.4.0
5 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