@tmlmobilidade/databases 20260423.1140.30 → 20260424.1050.20
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* * */
|
|
2
|
-
import { createClient } from '@clickhouse/client';
|
|
2
|
+
import { ClickHouseLogLevel, createClient } from '@clickhouse/client';
|
|
3
3
|
import { Logger } from '@tmlmobilidade/logger';
|
|
4
4
|
import { SshTunnelService } from '@tmlmobilidade/ssh';
|
|
5
5
|
import { readFileSync } from 'node:fs';
|
|
@@ -45,6 +45,10 @@ export class GOClickHouseClient {
|
|
|
45
45
|
const connectionString = await this.getConnectionString();
|
|
46
46
|
this.client = createClient({
|
|
47
47
|
keep_alive: { enabled: false },
|
|
48
|
+
log: {
|
|
49
|
+
level: ClickHouseLogLevel.OFF,
|
|
50
|
+
},
|
|
51
|
+
request_timeout: 360 * 1000,
|
|
48
52
|
url: connectionString,
|
|
49
53
|
});
|
|
50
54
|
}
|
|
@@ -3,6 +3,7 @@ import { preparePositionalQueryParams } from '../utils/clickhouse/prepare-positi
|
|
|
3
3
|
import { queryFromFile } from '../utils/clickhouse/query-from-file.js';
|
|
4
4
|
import { queryFromString } from '../utils/clickhouse/query-from-string.js';
|
|
5
5
|
import { validateSqlParam } from '../utils/clickhouse/validate-sql-param.js';
|
|
6
|
+
import { ClickHouseError } from '@clickhouse/client';
|
|
6
7
|
import { Logger } from '@tmlmobilidade/logger';
|
|
7
8
|
/* * */
|
|
8
9
|
export class ClickHouseInterfaceTemplate {
|
|
@@ -206,8 +207,28 @@ export class ClickHouseInterfaceTemplate {
|
|
|
206
207
|
Logger.info(`CLICKHOUSE [${this.tableName}]: Table created.`);
|
|
207
208
|
}
|
|
208
209
|
catch (error) {
|
|
209
|
-
|
|
210
|
-
|
|
210
|
+
// If the error is not an ACCESS_DENIED, throw it right away
|
|
211
|
+
if (!(error instanceof ClickHouseError) || error.code !== '497') {
|
|
212
|
+
Logger.error(`CLICKHOUSE [${this.tableName}]: Error @ createTable(): ${error.message}`);
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
// If the error is an ACCESS_DENIED, check if the table exists
|
|
216
|
+
try {
|
|
217
|
+
const resultSet = await this.client.query({
|
|
218
|
+
format: 'JSONEachRow',
|
|
219
|
+
query: `SHOW TABLES FROM "${this.databaseName}" LIKE '${this.tableName}'`,
|
|
220
|
+
});
|
|
221
|
+
const tables = await resultSet.json();
|
|
222
|
+
if (Array.isArray(tables) && tables.length > 0)
|
|
223
|
+
return;
|
|
224
|
+
Logger.error(`CLICKHOUSE [${this.tableName}]: ACCESS_DENIED and table does not exist. ${error.message}`);
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
catch (verifyError) {
|
|
228
|
+
//
|
|
229
|
+
Logger.error(`CLICKHOUSE [${this.tableName}]: Failed to verify table existence after ACCESS_DENIED: ${verifyError.message}`);
|
|
230
|
+
throw verifyError;
|
|
231
|
+
}
|
|
211
232
|
}
|
|
212
233
|
}
|
|
213
234
|
/**
|