@koralium/base-client 1.3.0-alpha6 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import { QueryOptions, QueryResult } from ".";
2
2
  export interface KoraliumClient {
3
- queryScalar(sql: string, parameters?: {} | null, headers?: {}): Promise<any>;
3
+ queryScalar(sql: string, queryOptions?: QueryOptions): Promise<any>;
4
4
  query(sql: string, queryOptions?: QueryOptions): Promise<QueryResult>;
5
5
  }
@@ -32,7 +32,7 @@ class ParameterBuilder {
32
32
  getParameters() {
33
33
  const output = {};
34
34
  for (let [key, value] of Object.entries(this.valuesToParameters)) {
35
- output[value] = key;
35
+ output[value] = encodeURIComponent(key);
36
36
  }
37
37
  return output;
38
38
  }
@@ -1 +1 @@
1
- {"version":3,"file":"parameterBuilder.js","sourceRoot":"","sources":["../src/parameterBuilder.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAa,gBAAgB;IAA7B;QACE,uBAAkB,GAA6B,EAAE,CAAA;QACjD,YAAO,GAAW,CAAC,CAAC;IAoBtB,CAAC;IAlBC,gBAAgB,CAAC,KAAsB;QACnC,IAAI,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE;YAC9C,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;SACzC;aACI;YACD,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC;YAC9C,OAAO,YAAY,CAAC;SACvB;IACL,CAAC;IAED,aAAa;QACX,MAAM,MAAM,GAA6B,EAAE,CAAC;QAC5C,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE;YAChE,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC;SACrB;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAtBD,4CAsBC"}
1
+ {"version":3,"file":"parameterBuilder.js","sourceRoot":"","sources":["../src/parameterBuilder.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAa,gBAAgB;IAA7B;QACE,uBAAkB,GAA6B,EAAE,CAAA;QACjD,YAAO,GAAW,CAAC,CAAC;IAoBtB,CAAC;IAlBC,gBAAgB,CAAC,KAAsB;QACnC,IAAI,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,KAAK,SAAS,EAAE;YAC9C,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;SACzC;aACI;YACD,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;YAC1C,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC;YAC9C,OAAO,YAAY,CAAC;SACvB;IACL,CAAC;IAED,aAAa;QACX,MAAM,MAAM,GAA6B,EAAE,CAAC;QAC5C,KAAK,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE;YAChE,MAAM,CAAC,KAAK,CAAC,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC;SACzC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAtBD,4CAsBC"}
@@ -2,8 +2,10 @@ export declare class Metadata {
2
2
  customMetadata: {};
3
3
  constructor(customMetadata: {});
4
4
  }
5
- export declare class QueryResult {
6
- rows: Array<{}>;
5
+ export declare class QueryResult<T extends {
6
+ [key: string]: any;
7
+ } = any> {
8
+ rows: Array<T>;
7
9
  metadata: Metadata;
8
- constructor(rows: Array<{}>, metadata: Metadata);
10
+ constructor(rows: Array<T>, metadata: Metadata);
9
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"queryResult.js","sourceRoot":"","sources":["../src/queryResult.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAa,QAAQ;IAGnB,YAAY,cAAkB;QAC5B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;CACF;AAND,4BAMC;AAED,MAAa,WAAW;IAItB,YAAY,IAAe,EAAE,QAAkB;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AARD,kCAQC"}
1
+ {"version":3,"file":"queryResult.js","sourceRoot":"","sources":["../src/queryResult.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACH,MAAa,QAAQ;IAGnB,YAAY,cAAkB;QAC5B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;CACF;AAND,4BAMC;AAED,MAAa,WAAW;IAItB,YAAY,IAAc,EAAE,QAAkB;QAC5C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AARD,kCAQC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koralium/base-client",
3
- "version": "1.3.0-alpha6",
3
+ "version": "1.3.1",
4
4
  "main": "./lib/index.js",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -28,5 +28,5 @@
28
28
  "ts-node": "^8.10.2",
29
29
  "typescript": "^3.2.2"
30
30
  },
31
- "gitHead": "f4c208a65e77cd1d4e9dabcc7f5c3e0c3e3a02a4"
31
+ "gitHead": "865598af01038cca8d14da8e4ba0a54fab170ff2"
32
32
  }
@@ -14,6 +14,6 @@
14
14
  import { QueryOptions, QueryResult } from ".";
15
15
 
16
16
  export interface KoraliumClient {
17
- queryScalar(sql: string, parameters?: {} | null, headers?: {}): Promise<any>
17
+ queryScalar(sql: string, queryOptions?: QueryOptions): Promise<any>
18
18
  query(sql: string, queryOptions?: QueryOptions): Promise<QueryResult>;
19
19
  }
@@ -29,7 +29,7 @@ export class ParameterBuilder {
29
29
  getParameters(): {} {
30
30
  const output: {[key: string]: string;} = {};
31
31
  for (let [key, value] of Object.entries(this.valuesToParameters)) {
32
- output[value] = key;
32
+ output[value] = encodeURIComponent(key);
33
33
  }
34
34
  return output;
35
35
  }
@@ -19,11 +19,11 @@ export class Metadata {
19
19
  }
20
20
  }
21
21
 
22
- export class QueryResult {
23
- rows: Array<{}>;
22
+ export class QueryResult<T extends { [key: string]: any; } = any> {
23
+ rows: Array<T>;
24
24
  metadata: Metadata;
25
25
 
26
- constructor(rows: Array<{}>, metadata: Metadata) {
26
+ constructor(rows: Array<T>, metadata: Metadata) {
27
27
  this.rows = rows;
28
28
  this.metadata = metadata;
29
29
  }
package/test-report.xml CHANGED
@@ -1,24 +1,25 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <testExecutions version="1">
3
3
  <file path="C:\Users\seosal\source\repos\Koralium\new\Koralium\typescript-client\base-client\tests\queryBuilder.test.ts">
4
- <testCase name="count with filter" duration="3"/>
4
+ <testCase name="count with filter" duration="8"/>
5
5
  <testCase name="Select same column" duration="1"/>
6
- <testCase name="Select with limit and offset" duration="0"/>
7
- <testCase name="Select multiple columns, filter, limit, offset" duration="0"/>
8
- <testCase name="Object mapper" duration="1"/>
9
- <testCase name="Object mapper, missing mapping" duration="0"/>
10
- <testCase name="Filter builder equals" duration="1"/>
11
- <testCase name="test in predicate for numbers" duration="1"/>
6
+ <testCase name="Select with limit and offset" duration="1"/>
7
+ <testCase name="Select multiple columns, filter, limit, offset" duration="1"/>
8
+ <testCase name="Object mapper" duration="2"/>
9
+ <testCase name="Object mapper, missing mapping" duration="1"/>
10
+ <testCase name="Filter builder equals" duration="3"/>
11
+ <testCase name="test in predicate for numbers" duration="0"/>
12
12
  <testCase name="test in predicate for strings" duration="0"/>
13
13
  <testCase name="Order by with object ascending" duration="1"/>
14
14
  <testCase name="Order by with object descending" duration="0"/>
15
- <testCase name="Empty filter string" duration="0"/>
16
- <testCase name="Empty filter object" duration="1"/>
17
- <testCase name="Search filter all fields" duration="0"/>
15
+ <testCase name="Empty filter string" duration="1"/>
16
+ <testCase name="Empty filter object" duration="0"/>
17
+ <testCase name="Search filter all fields" duration="1"/>
18
18
  <testCase name="Search filter two fields" duration="1"/>
19
- <testCase name="Boolean filter" duration="0"/>
19
+ <testCase name="Boolean filter" duration="1"/>
20
20
  <testCase name="IN filter with strings" duration="1"/>
21
- <testCase name="IN filter with numbers" duration="0"/>
22
- <testCase name="IN filter with booleans" duration="1"/>
21
+ <testCase name="IN filter with numbers" duration="2"/>
22
+ <testCase name="IN filter with booleans" duration="2"/>
23
+ <testCase name="filter with åäö" duration="1"/>
23
24
  </file>
24
25
  </testExecutions>
@@ -306,4 +306,24 @@ test("IN filter with booleans", () => {
306
306
  .buildQuery();
307
307
 
308
308
  expect(result).toEqual(expected);
309
- });
309
+ });
310
+
311
+ test("filter with åäö", () => {
312
+ const expected = "SELECT count(*) FROM testtable WHERE (name IN (@P0))"
313
+
314
+ const queryBuilder = new QueryBuilder("testtable");
315
+ const result = queryBuilder
316
+ .addSelectElement("count(*)")
317
+ .addFilter({
318
+ name: {in: ["åäö"]}
319
+ })
320
+ .buildQuery();
321
+
322
+ const parametersResult = queryBuilder.getParameters();
323
+ const expectedParameters = {
324
+ P0: encodeURIComponent("åäö")
325
+ };
326
+
327
+ expect(result).toEqual(expected);
328
+ expect(parametersResult).toEqual(expectedParameters);
329
+ })