From 08320fa6fa724f176ee53aa355f9fdd529ecfd8f Mon Sep 17 00:00:00 2001 From: Hector Ayala Date: Fri, 16 Feb 2024 10:45:30 -0400 Subject: [PATCH] fix: use camel case for camelCase option (#466) --- docs/README.md | 8 ++++---- query/query.ts | 14 +++++++------- tests/query_client_test.ts | 14 +++++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/README.md b/docs/README.md index 528c2d2..f9c7559 100644 --- a/docs/README.md +++ b/docs/README.md @@ -856,14 +856,14 @@ for that such as aliasing every query field that is done to the database, one easy built-in solution allows developers to transform the incoming query names into the casing of their preference without any extra steps -##### Camelcase +##### Camel case -To transform a query result into camelcase, you only need to provide the -`camelcase` option on your query call +To transform a query result into camel case, you only need to provide the +`camelCase` option on your query call ```ts const { rows: result } = await client.queryObject({ - camelcase: true, + camelCase: true, text: "SELECT FIELD_X, FIELD_Y FROM MY_TABLE", }); diff --git a/query/query.ts b/query/query.ts index 0bb39d7..5897745 100644 --- a/query/query.ts +++ b/query/query.ts @@ -132,19 +132,19 @@ export interface QueryObjectOptions extends QueryOptions { // TODO // Support multiple case options /** - * Enabling camelcase will transform any snake case field names coming from the database into camel case ones + * Enabling camel case will transform any snake case field names coming from the database into camel case ones * * Ex: `SELECT 1 AS my_field` will return `{ myField: 1 }` * * This won't have any effect if you explicitly set the field names with the `fields` parameter */ - camelcase?: boolean; + camelCase?: boolean; /** * This parameter supersedes query column names coming from the databases in the order they were provided. * Fields must be unique and be in the range of (a-zA-Z0-9_), otherwise the query will throw before execution. * A field can not start with a number, just like JavaScript variables * - * This setting overrides the camelcase option + * This setting overrides the camel case option * * Ex: `SELECT 'A', 'B' AS my_field` with fields `["field_1", "field_2"]` will return `{ field_1: "A", field_2: "B" }` */ @@ -324,7 +324,7 @@ export class QueryObjectResult< this.columns = this.query.fields; } else { let column_names: string[]; - if (this.query.camelcase) { + if (this.query.camelCase) { column_names = this.rowDescription.columns.map((column) => snakecaseToCamelcase(column.name) ); @@ -380,7 +380,7 @@ export class QueryObjectResult< */ export class Query { public args: EncodedArg[]; - public camelcase?: boolean; + public camelCase?: boolean; /** * The explicitly set fields for the query result, they have been validated beforehand * for duplicates and invalid names @@ -408,7 +408,7 @@ export class Query { this.text = config_or_text; this.args = args.map(encodeArgument); } else { - const { camelcase, encoder = encodeArgument, fields } = config_or_text; + const { camelCase, encoder = encodeArgument, fields } = config_or_text; let { args = [], text } = config_or_text; // Check that the fields passed are valid and can be used to map @@ -432,7 +432,7 @@ export class Query { this.fields = fields; } - this.camelcase = camelcase; + this.camelCase = camelCase; if (!Array.isArray(args)) { [text, args] = objectQueryToQueryArgs(text, args); diff --git a/tests/query_client_test.ts b/tests/query_client_test.ts index 84e05f9..9def424 100644 --- a/tests/query_client_test.ts +++ b/tests/query_client_test.ts @@ -796,7 +796,7 @@ Deno.test( ); Deno.test( - "Object query field names aren't transformed when camelcase is disabled", + "Object query field names aren't transformed when camel case is disabled", withClient(async (client) => { const record = { pos_x: "100", @@ -806,7 +806,7 @@ Deno.test( const { rows: result } = await client.queryObject({ args: [record.pos_x, record.pos_y, record.prefix_name_suffix], - camelcase: false, + camelCase: false, text: "SELECT $1 AS POS_X, $2 AS POS_Y, $3 AS PREFIX_NAME_SUFFIX", }); @@ -815,7 +815,7 @@ Deno.test( ); Deno.test( - "Object query field names are transformed when camelcase is enabled", + "Object query field names are transformed when camel case is enabled", withClient(async (client) => { const record = { posX: "100", @@ -825,7 +825,7 @@ Deno.test( const { rows: result } = await client.queryObject({ args: [record.posX, record.posY, record.prefixNameSuffix], - camelcase: true, + camelCase: true, text: "SELECT $1 AS POS_X, $2 AS POS_Y, $3 AS PREFIX_NAME_SUFFIX", }); @@ -846,13 +846,13 @@ Deno.test( ); Deno.test( - "Object query explicit fields override camelcase", + "Object query explicit fields override camel case", withClient(async (client) => { const record = { field_1: "A", field_2: "B", field_3: "C" }; const { rows: result } = await client.queryObject({ args: [record.field_1, record.field_2, record.field_3], - camelcase: true, + camelCase: true, fields: ["field_1", "field_2", "field_3"], text: "SELECT $1 AS POS_X, $2 AS POS_Y, $3 AS PREFIX_NAME_SUFFIX", }); @@ -888,7 +888,7 @@ Deno.test( await assertRejects( () => client.queryObject({ - camelcase: true, + camelCase: true, text: `SELECT 1 AS "fieldX", 2 AS field_x`, }), Error,