package
Transforms Slonik query result field names.
npm install slonik-interceptor-field-name-transformationGitHub-flavored package documentation.
Across all versions, last 30 days.
68,434 in 30 days
Runtime metadata.
Tagged topics.
Estimated unpacked size across 2 packages.
59.8 kB
Includes dependencies.
Transforms Slonik query result field names into camelCase.
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 the transformRow interceptor method to format field names. Rows are copied by a function that is compiled once per set of fields, and rows whose field names do not need to be transformed are returned as they are.
npm install slonik-interceptor-field-name-transformationYou can configure which fields should be transformed by providing a test function to createFieldNameTransformationInterceptor
/**
* @property test Tests whether the field should be formatted.
* All fields that pass this test will have their names converted to camelCase.
*/
type ConfigurationType = {
test: (field: FieldType) => boolean;
};
(configuration: ConfigurationType) => InterceptorType;import { createPool } from "slonik";
import { createFieldNameTransformationInterceptor } from "slonik-interceptor-field-name-transformation";
const interceptors = [
createFieldNameTransformationInterceptor({
test: (field) => {
return field.name !== "__typename" && /^[\d_a-z]+$/u.test(field.name);
},
}),
];
const connection = createPool("postgres://", {
interceptors,
});
connection.any(sql`
SELECT
id,
full_name,