@cleverbrush/knex-clickhouse 1.1.10 → 1.1.11

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 CHANGED
@@ -1,6 +1,7 @@
1
1
  import Knex from 'knex';
2
- import ClickhouseDriver, { type ClickHouseSettings } from '@clickhouse/client';
2
+ import ClickhouseDriver, { ClickHouseClient, type ClickHouseSettings } from '@clickhouse/client';
3
3
  import { retry } from '@cleverbrush/async';
4
+ export { type ClickHouseClient };
4
5
  type AdditionalClientOptions = {
5
6
  /**
6
7
  * Options for retrying the query,
@@ -19,11 +20,10 @@ export declare class ClickhouseKnexClient extends Knex.Client {
19
20
  _escapeBinding(value: any): any;
20
21
  /**
21
22
  *
22
- * @param {import('@clickhouse/client').ClickHouseClient} connection
23
23
  * @param {import('@clickhouse/client').QueryParams} obj
24
24
  * @returns
25
25
  */
26
- _query(connection: any, obj: any): Promise<any>;
26
+ _query(connection: ClickHouseClient, obj: any): Promise<any>;
27
27
  /**
28
28
  *
29
29
  * @param {import('@clickhouse/client').ResultSet} obj
@@ -38,5 +38,4 @@ export declare class ClickhouseKnexClient extends Knex.Client {
38
38
  *
39
39
  * @returns {import('knex').Knex<any, unknown[]>}
40
40
  */
41
- export declare const getClickhouseConnection: (config?: Knex.Knex.Config<any> & AdditionalClientOptions, clickHouseSettings?: ClickHouseSettings) => Knex.Knex<any, unknown[]>;
42
- export {};
41
+ export declare const getClickhouseConnection: (config?: Knex.Knex.Config<any> & AdditionalClientOptions, clickHouseSettings?: ClickHouseSettings, preQueryCallback?: (connection: ClickHouseClient) => Promise<void>) => Knex.Knex<any, unknown[]>;
package/dist/index.js CHANGED
@@ -101,7 +101,6 @@ export class ClickhouseKnexClient extends Knex.Client {
101
101
  }
102
102
  /**
103
103
  *
104
- * @param {import('@clickhouse/client').ClickHouseClient} connection
105
104
  * @param {import('@clickhouse/client').QueryParams} obj
106
105
  * @returns
107
106
  */
@@ -133,6 +132,10 @@ export class ClickhouseKnexClient extends Knex.Client {
133
132
  format: 'JSONCompact'
134
133
  };
135
134
  obj.finalQuery = query;
135
+ const { preQueryCallback } = this.config;
136
+ if (typeof preQueryCallback === 'function') {
137
+ await Promise.resolve(preQueryCallback(connection));
138
+ }
136
139
  switch (method) {
137
140
  case 'select':
138
141
  case 'first':
@@ -270,12 +273,25 @@ const registerKnexClickhouseExtensions = (knex) => {
270
273
  *
271
274
  * @returns {import('knex').Knex<any, unknown[]>}
272
275
  */
273
- export const getClickhouseConnection = (config = {}, clickHouseSettings) => {
276
+ export const getClickhouseConnection = (config = {}, clickHouseSettings,
277
+ /**
278
+ * If defined, this function will be called before each query
279
+ * and awaited if it returns a promise.
280
+ *
281
+ * Could be useful in some cases. For example you want first to check
282
+ * if the server is not in idle state (for example Clickhouse Cloud have idling options)
283
+ * and if it is, you want to wake it up before sending the query.
284
+ *
285
+ * if the function throws an error this error will not be caught and will propagate to the caller.
286
+ * Therefore the query will not be executed.
287
+ */
288
+ preQueryCallback) => {
274
289
  const connection = Knex({
275
290
  ...config,
276
291
  client: ClickhouseKnexClient,
277
292
  // @ts-ignore
278
- clickHouseSettings
293
+ clickHouseSettings,
294
+ preQueryCallback
279
295
  });
280
296
  registerKnexClickhouseExtensions(connection);
281
297
  return connection;
package/package.json CHANGED
@@ -5,9 +5,9 @@
5
5
  "email": "andrew_zol@cleverbrush.com"
6
6
  },
7
7
  "dependencies": {
8
- "@cleverbrush/async": "^1.1.10",
9
- "@cleverbrush/deep": "^1.1.10",
10
- "@clickhouse/client": "^1.0.1"
8
+ "@cleverbrush/async": "^1.1.11",
9
+ "@cleverbrush/deep": "^1.1.11",
10
+ "@clickhouse/client": "^1.7.0"
11
11
  },
12
12
  "peerDependencies": {
13
13
  "knex": ">=3.1.0"
@@ -37,5 +37,5 @@
37
37
  },
38
38
  "type": "module",
39
39
  "types": "./dist/index.d.ts",
40
- "version": "1.1.10"
40
+ "version": "1.1.11"
41
41
  }