@cleverbrush/knex-clickhouse 1.1.7 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +15 -2
- package/dist/index.js +19 -2
- package/package.json +3 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import Knex from 'knex';
|
|
2
2
|
import ClickhouseDriver, { type ClickHouseSettings } from '@clickhouse/client';
|
|
3
|
+
import { retry } from '@cleverbrush/async';
|
|
4
|
+
type AdditionalClientOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Options for retrying the query,
|
|
7
|
+
* by default it will retry 10 times with a delay factor of 2 and a minimum delay of
|
|
8
|
+
* 100ms and delay randomization of 10%.
|
|
9
|
+
* and will retry only if the error code is 'ECONNRESET',
|
|
10
|
+
* you can override this behavior by passing your own options.
|
|
11
|
+
* If this option is set to `null` then the query will not be retried.
|
|
12
|
+
*/
|
|
13
|
+
retry?: Parameters<typeof retry>[1];
|
|
14
|
+
};
|
|
3
15
|
export declare class ClickhouseKnexClient extends Knex.Client {
|
|
4
16
|
#private;
|
|
5
17
|
_driver(): typeof ClickhouseDriver;
|
|
6
|
-
constructor(config?:
|
|
18
|
+
constructor(config?: Knex.Knex.Config<any> & AdditionalClientOptions);
|
|
7
19
|
_escapeBinding(value: any): any;
|
|
8
20
|
/**
|
|
9
21
|
*
|
|
@@ -26,4 +38,5 @@ export declare class ClickhouseKnexClient extends Knex.Client {
|
|
|
26
38
|
*
|
|
27
39
|
* @returns {import('knex').Knex<any, unknown[]>}
|
|
28
40
|
*/
|
|
29
|
-
export declare const getClickhouseConnection: (config?: Knex.Knex.Config<any
|
|
41
|
+
export declare const getClickhouseConnection: (config?: Knex.Knex.Config<any> & AdditionalClientOptions, clickHouseSettings?: ClickHouseSettings) => Knex.Knex<any, unknown[]>;
|
|
42
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Knex from 'knex';
|
|
2
2
|
import ClickhouseDriver from '@clickhouse/client';
|
|
3
|
+
import { retry } from '@cleverbrush/async';
|
|
4
|
+
import { deepExtend } from '@cleverbrush/deep';
|
|
3
5
|
import { makeEscape } from './makeEscape.js';
|
|
4
6
|
const parseDate = (value) => new Date(Date.parse(value));
|
|
5
7
|
// this function is taken from knex npm package
|
|
@@ -28,8 +30,19 @@ export class ClickhouseKnexClient extends Knex.Client {
|
|
|
28
30
|
_driver() {
|
|
29
31
|
return ClickhouseDriver;
|
|
30
32
|
}
|
|
33
|
+
#retryOptions;
|
|
31
34
|
constructor(config = {}) {
|
|
35
|
+
const { retry: retryOptions } = config;
|
|
32
36
|
super(config);
|
|
37
|
+
this.#retryOptions = retryOptions
|
|
38
|
+
? deepExtend({
|
|
39
|
+
maxRetries: 10,
|
|
40
|
+
delayFactor: 2,
|
|
41
|
+
minDelay: 100,
|
|
42
|
+
delayRandomizationPercent: 0.1,
|
|
43
|
+
shouldRetry: (error) => error.code === 'ECONNRESET'
|
|
44
|
+
}, retryOptions)
|
|
45
|
+
: null;
|
|
33
46
|
}
|
|
34
47
|
#typeParsers = {
|
|
35
48
|
Date: parseDate,
|
|
@@ -125,14 +138,18 @@ export class ClickhouseKnexClient extends Knex.Client {
|
|
|
125
138
|
case 'first':
|
|
126
139
|
case 'pluck':
|
|
127
140
|
{
|
|
128
|
-
const p = await
|
|
141
|
+
const p = (await (this.#retryOptions
|
|
142
|
+
? retry(() => connection.query(queryParams), this.#retryOptions)
|
|
143
|
+
: connection.query(queryParams)));
|
|
129
144
|
response = await p.json();
|
|
130
145
|
const { data, meta, ...rest } = response;
|
|
131
146
|
obj.response = [data, meta, { ...rest }];
|
|
132
147
|
}
|
|
133
148
|
break;
|
|
134
149
|
default:
|
|
135
|
-
response = await
|
|
150
|
+
response = await (this.#retryOptions
|
|
151
|
+
? retry(() => connection.exec(queryParams), this.#retryOptions)
|
|
152
|
+
: connection.exec(queryParams));
|
|
136
153
|
}
|
|
137
154
|
return obj;
|
|
138
155
|
}
|
package/package.json
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
"email": "andrew_zol@cleverbrush.com"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@cleverbrush/async": "^1.1.8",
|
|
9
|
+
"@cleverbrush/deep": "^1.1.8",
|
|
8
10
|
"@clickhouse/client": "^1.0.1"
|
|
9
11
|
},
|
|
10
12
|
"peerDependencies": {
|
|
@@ -35,5 +37,5 @@
|
|
|
35
37
|
},
|
|
36
38
|
"type": "module",
|
|
37
39
|
"types": "./dist/index.d.ts",
|
|
38
|
-
"version": "1.1.
|
|
40
|
+
"version": "1.1.8"
|
|
39
41
|
}
|