Skip to content

Commit 08320fa

Browse files
authored
fix: use camel case for camelCase option (denodrivers#466)
1 parent 37f41f5 commit 08320fa

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

docs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,14 +856,14 @@ for that such as aliasing every query field that is done to the database, one
856856
easy built-in solution allows developers to transform the incoming query names
857857
into the casing of their preference without any extra steps
858858

859-
##### Camelcase
859+
##### Camel case
860860

861-
To transform a query result into camelcase, you only need to provide the
862-
`camelcase` option on your query call
861+
To transform a query result into camel case, you only need to provide the
862+
`camelCase` option on your query call
863863

864864
```ts
865865
const { rows: result } = await client.queryObject({
866-
camelcase: true,
866+
camelCase: true,
867867
text: "SELECT FIELD_X, FIELD_Y FROM MY_TABLE",
868868
});
869869

query/query.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,19 +132,19 @@ export interface QueryObjectOptions extends QueryOptions {
132132
// TODO
133133
// Support multiple case options
134134
/**
135-
* Enabling camelcase will transform any snake case field names coming from the database into camel case ones
135+
* Enabling camel case will transform any snake case field names coming from the database into camel case ones
136136
*
137137
* Ex: `SELECT 1 AS my_field` will return `{ myField: 1 }`
138138
*
139139
* This won't have any effect if you explicitly set the field names with the `fields` parameter
140140
*/
141-
camelcase?: boolean;
141+
camelCase?: boolean;
142142
/**
143143
* This parameter supersedes query column names coming from the databases in the order they were provided.
144144
* Fields must be unique and be in the range of (a-zA-Z0-9_), otherwise the query will throw before execution.
145145
* A field can not start with a number, just like JavaScript variables
146146
*
147-
* This setting overrides the camelcase option
147+
* This setting overrides the camel case option
148148
*
149149
* Ex: `SELECT 'A', 'B' AS my_field` with fields `["field_1", "field_2"]` will return `{ field_1: "A", field_2: "B" }`
150150
*/
@@ -324,7 +324,7 @@ export class QueryObjectResult<
324324
this.columns = this.query.fields;
325325
} else {
326326
let column_names: string[];
327-
if (this.query.camelcase) {
327+
if (this.query.camelCase) {
328328
column_names = this.rowDescription.columns.map((column) =>
329329
snakecaseToCamelcase(column.name)
330330
);
@@ -380,7 +380,7 @@ export class QueryObjectResult<
380380
*/
381381
export class Query<T extends ResultType> {
382382
public args: EncodedArg[];
383-
public camelcase?: boolean;
383+
public camelCase?: boolean;
384384
/**
385385
* The explicitly set fields for the query result, they have been validated beforehand
386386
* for duplicates and invalid names
@@ -408,7 +408,7 @@ export class Query<T extends ResultType> {
408408
this.text = config_or_text;
409409
this.args = args.map(encodeArgument);
410410
} else {
411-
const { camelcase, encoder = encodeArgument, fields } = config_or_text;
411+
const { camelCase, encoder = encodeArgument, fields } = config_or_text;
412412
let { args = [], text } = config_or_text;
413413

414414
// Check that the fields passed are valid and can be used to map
@@ -432,7 +432,7 @@ export class Query<T extends ResultType> {
432432
this.fields = fields;
433433
}
434434

435-
this.camelcase = camelcase;
435+
this.camelCase = camelCase;
436436

437437
if (!Array.isArray(args)) {
438438
[text, args] = objectQueryToQueryArgs(text, args);

tests/query_client_test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ Deno.test(
796796
);
797797

798798
Deno.test(
799-
"Object query field names aren't transformed when camelcase is disabled",
799+
"Object query field names aren't transformed when camel case is disabled",
800800
withClient(async (client) => {
801801
const record = {
802802
pos_x: "100",
@@ -806,7 +806,7 @@ Deno.test(
806806

807807
const { rows: result } = await client.queryObject({
808808
args: [record.pos_x, record.pos_y, record.prefix_name_suffix],
809-
camelcase: false,
809+
camelCase: false,
810810
text: "SELECT $1 AS POS_X, $2 AS POS_Y, $3 AS PREFIX_NAME_SUFFIX",
811811
});
812812

@@ -815,7 +815,7 @@ Deno.test(
815815
);
816816

817817
Deno.test(
818-
"Object query field names are transformed when camelcase is enabled",
818+
"Object query field names are transformed when camel case is enabled",
819819
withClient(async (client) => {
820820
const record = {
821821
posX: "100",
@@ -825,7 +825,7 @@ Deno.test(
825825

826826
const { rows: result } = await client.queryObject({
827827
args: [record.posX, record.posY, record.prefixNameSuffix],
828-
camelcase: true,
828+
camelCase: true,
829829
text: "SELECT $1 AS POS_X, $2 AS POS_Y, $3 AS PREFIX_NAME_SUFFIX",
830830
});
831831

@@ -846,13 +846,13 @@ Deno.test(
846846
);
847847

848848
Deno.test(
849-
"Object query explicit fields override camelcase",
849+
"Object query explicit fields override camel case",
850850
withClient(async (client) => {
851851
const record = { field_1: "A", field_2: "B", field_3: "C" };
852852

853853
const { rows: result } = await client.queryObject({
854854
args: [record.field_1, record.field_2, record.field_3],
855-
camelcase: true,
855+
camelCase: true,
856856
fields: ["field_1", "field_2", "field_3"],
857857
text: "SELECT $1 AS POS_X, $2 AS POS_Y, $3 AS PREFIX_NAME_SUFFIX",
858858
});
@@ -888,7 +888,7 @@ Deno.test(
888888
await assertRejects(
889889
() =>
890890
client.queryObject({
891-
camelcase: true,
891+
camelCase: true,
892892
text: `SELECT 1 AS "fieldX", 2 AS field_x`,
893893
}),
894894
Error,

0 commit comments

Comments
 (0)