1.6.5 • Published 2 years ago
slonik-interceptor-field-name-transformation v1.6.5
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
// }
// ]
1.6.5
2 years ago
1.6.4
2 years ago
1.6.3
2 years ago
1.6.2
2 years ago
1.6.1
2 years ago
1.6.0
2 years ago
1.5.3
4 years ago
1.5.2
4 years ago
1.5.1
4 years ago
1.5.0
4 years ago
1.4.2
5 years ago
1.4.1
5 years ago
1.4.0
5 years ago
1.3.2
5 years ago
1.3.1
5 years ago
1.3.0
5 years ago
1.2.0
5 years ago
1.1.0
5 years ago
1.0.0
5 years ago