@tmlmobilidade/go-interfaces-labdb 20260726.1208.42 → 20260726.1412.44

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,54 +1,2 @@
1
- import { ClickHouseClient, queryFromFile, queryFromString } from '@tmlmobilidade/go-clients-clickhouse';
2
- import { OperationDatabase } from './databases/operation.js';
3
- import { PerformanceDatabase } from './databases/performance.js';
4
- import { SimplifiedApexDatabase } from './databases/simplified-apex.js';
5
- declare class LabDbClass {
6
- private static _instance;
7
- readonly operation: OperationDatabase;
8
- readonly performance: PerformanceDatabase;
9
- readonly simplifiedApex: SimplifiedApexDatabase;
10
- private readonly clickhouseClient;
11
- private constructor();
12
- /**
13
- * Returns the singleton instance.
14
- * Concurrent callers share the same initialization promise so schema setup runs once.
15
- */
16
- static getInstance(): Promise<LabDbClass>;
17
- /**
18
- * Returns the ClickHouse client.
19
- * @returns The ClickHouse client.
20
- * @deprecated Avoid using this method directly. Find alternative ways
21
- * to query the database using the database-specific methods instead.
22
- */
23
- getClient(): Promise<ClickHouseClient>;
24
- private init;
25
- /**
26
- * Executes a query from a .sql file with optional parameter substitutions.
27
- * @param filePath Absolute or relative path to the .sql file.
28
- * @param params Optional key-value substitutions applied to the query (replaces {key} placeholders).
29
- * @returns Query result rows typed as `T`.
30
- * @example
31
- * // Given a SQL file "get_users.sql" with the content:
32
- * // SELECT * FROM users WHERE created_at >= {start_date} AND created_at <= {end_date}
33
- * const users = await clickhouseService.queryFromFile<User>('get_users.sql', {
34
- * start_date: '2024-01-01',
35
- * end_date: '2024-12-31',
36
- * });
37
- */
38
- queryFromFile<T>(filePath: string, params?: Record<string, number | string>): ReturnType<typeof queryFromFile<T>>;
39
- /**
40
- * Executes a query from a string.
41
- * @param client The ClickHouse client to use for executing the query.
42
- * @param query The SQL query to execute, with optional {key} placeholders for parameters.
43
- * @param params Optional key-value substitutions applied to the query (replaces {key} placeholders).
44
- * @returns Query result rows typed as `T`.
45
- * @example
46
- * const users = await queryFromString<User>(clickhouseClient,
47
- * 'SELECT * FROM users WHERE created_at >= {start_date} AND created_at <= {end_date}',
48
- * { start_date: '2024-01-01', end_date: '2024-12-31' }
49
- * );
50
- */
51
- queryFromString<T>(query: string, params?: Record<string, number | string>): ReturnType<typeof queryFromString<T>>;
52
- }
53
- export declare const labDb: LabDbClass;
54
- export {};
1
+ export * from './interface.js';
2
+ export * from './interface.template.js';
package/dist/index.js CHANGED
@@ -1,87 +1,2 @@
1
- /* * */
2
- import { ClickHouseDatabaseClient, queryFromFile, queryFromString } from '@tmlmobilidade/go-clients-clickhouse';
3
- import { asyncSingletonProxy } from '@tmlmobilidade/utils';
4
- import { OperationDatabase } from './databases/operation.js';
5
- import { PerformanceDatabase } from './databases/performance.js';
6
- import { SimplifiedApexDatabase } from './databases/simplified-apex.js';
7
- /* * */
8
- class LabDbClass {
9
- //
10
- static _instance = null;
11
- operation;
12
- performance;
13
- simplifiedApex;
14
- clickhouseClient;
15
- constructor(client) {
16
- this.clickhouseClient = client;
17
- this.operation = new OperationDatabase(this.clickhouseClient);
18
- this.performance = new PerformanceDatabase(this.clickhouseClient);
19
- this.simplifiedApex = new SimplifiedApexDatabase(this.clickhouseClient);
20
- }
21
- /**
22
- * Returns the singleton instance.
23
- * Concurrent callers share the same initialization promise so schema setup runs once.
24
- */
25
- static async getInstance() {
26
- if (!LabDbClass._instance) {
27
- LabDbClass._instance = (async () => {
28
- const clickhouseClient = await ClickHouseDatabaseClient.getClient({ prefix: 'LABDB', tunnelType: 'GO' });
29
- const instance = new LabDbClass(clickhouseClient);
30
- // Behaves like an async constructor: create DBs/tables before the proxy exposes the instance.
31
- await instance.init();
32
- return instance;
33
- })();
34
- }
35
- return await LabDbClass._instance;
36
- }
37
- /**
38
- * Returns the ClickHouse client.
39
- * @returns The ClickHouse client.
40
- * @deprecated Avoid using this method directly. Find alternative ways
41
- * to query the database using the database-specific methods instead.
42
- */
43
- async getClient() {
44
- const instance = await LabDbClass.getInstance();
45
- return instance.clickhouseClient;
46
- }
47
- async init() {
48
- await Promise.all([
49
- this.operation.init(),
50
- this.performance.init(),
51
- this.simplifiedApex.init(),
52
- ]);
53
- }
54
- /**
55
- * Executes a query from a .sql file with optional parameter substitutions.
56
- * @param filePath Absolute or relative path to the .sql file.
57
- * @param params Optional key-value substitutions applied to the query (replaces {key} placeholders).
58
- * @returns Query result rows typed as `T`.
59
- * @example
60
- * // Given a SQL file "get_users.sql" with the content:
61
- * // SELECT * FROM users WHERE created_at >= {start_date} AND created_at <= {end_date}
62
- * const users = await clickhouseService.queryFromFile<User>('get_users.sql', {
63
- * start_date: '2024-01-01',
64
- * end_date: '2024-12-31',
65
- * });
66
- */
67
- async queryFromFile(filePath, params) {
68
- return await queryFromFile(this.clickhouseClient, filePath, params);
69
- }
70
- /**
71
- * Executes a query from a string.
72
- * @param client The ClickHouse client to use for executing the query.
73
- * @param query The SQL query to execute, with optional {key} placeholders for parameters.
74
- * @param params Optional key-value substitutions applied to the query (replaces {key} placeholders).
75
- * @returns Query result rows typed as `T`.
76
- * @example
77
- * const users = await queryFromString<User>(clickhouseClient,
78
- * 'SELECT * FROM users WHERE created_at >= {start_date} AND created_at <= {end_date}',
79
- * { start_date: '2024-01-01', end_date: '2024-12-31' }
80
- * );
81
- */
82
- async queryFromString(query, params) {
83
- return await queryFromString(this.clickhouseClient, query, params);
84
- }
85
- }
86
- /* * */
87
- export const labDb = asyncSingletonProxy(LabDbClass);
1
+ export * from './interface.js';
2
+ export * from './interface.template.js';
@@ -0,0 +1,54 @@
1
+ import { ClickHouseClient, queryFromFile, queryFromString } from '@tmlmobilidade/go-clients-clickhouse';
2
+ import { OperationDatabase } from './databases/operation.js';
3
+ import { PerformanceDatabase } from './databases/performance.js';
4
+ import { SimplifiedApexDatabase } from './databases/simplified-apex.js';
5
+ declare class LabDbClass {
6
+ private static _instance;
7
+ readonly operation: OperationDatabase;
8
+ readonly performance: PerformanceDatabase;
9
+ readonly simplifiedApex: SimplifiedApexDatabase;
10
+ private readonly clickhouseClient;
11
+ private constructor();
12
+ /**
13
+ * Returns the singleton instance.
14
+ * Concurrent callers share the same initialization promise so schema setup runs once.
15
+ */
16
+ static getInstance(): Promise<LabDbClass>;
17
+ /**
18
+ * Returns the ClickHouse client.
19
+ * @returns The ClickHouse client.
20
+ * @deprecated Avoid using this method directly. Find alternative ways
21
+ * to query the database using the database-specific methods instead.
22
+ */
23
+ getClient(): Promise<ClickHouseClient>;
24
+ private init;
25
+ /**
26
+ * Executes a query from a .sql file with optional parameter substitutions.
27
+ * @param filePath Absolute or relative path to the .sql file.
28
+ * @param params Optional key-value substitutions applied to the query (replaces {key} placeholders).
29
+ * @returns Query result rows typed as `T`.
30
+ * @example
31
+ * // Given a SQL file "get_users.sql" with the content:
32
+ * // SELECT * FROM users WHERE created_at >= {start_date} AND created_at <= {end_date}
33
+ * const users = await clickhouseService.queryFromFile<User>('get_users.sql', {
34
+ * start_date: '2024-01-01',
35
+ * end_date: '2024-12-31',
36
+ * });
37
+ */
38
+ queryFromFile<T>(filePath: string, params?: Record<string, number | string>): ReturnType<typeof queryFromFile<T>>;
39
+ /**
40
+ * Executes a query from a string.
41
+ * @param client The ClickHouse client to use for executing the query.
42
+ * @param query The SQL query to execute, with optional {key} placeholders for parameters.
43
+ * @param params Optional key-value substitutions applied to the query (replaces {key} placeholders).
44
+ * @returns Query result rows typed as `T`.
45
+ * @example
46
+ * const users = await queryFromString<User>(clickhouseClient,
47
+ * 'SELECT * FROM users WHERE created_at >= {start_date} AND created_at <= {end_date}',
48
+ * { start_date: '2024-01-01', end_date: '2024-12-31' }
49
+ * );
50
+ */
51
+ queryFromString<T>(query: string, params?: Record<string, number | string>): ReturnType<typeof queryFromString<T>>;
52
+ }
53
+ export declare const labDb: LabDbClass;
54
+ export {};
@@ -0,0 +1,87 @@
1
+ /* * */
2
+ import { ClickHouseDatabaseClient, queryFromFile, queryFromString } from '@tmlmobilidade/go-clients-clickhouse';
3
+ import { asyncSingletonProxy } from '@tmlmobilidade/utils';
4
+ import { OperationDatabase } from './databases/operation.js';
5
+ import { PerformanceDatabase } from './databases/performance.js';
6
+ import { SimplifiedApexDatabase } from './databases/simplified-apex.js';
7
+ /* * */
8
+ class LabDbClass {
9
+ //
10
+ static _instance = null;
11
+ operation;
12
+ performance;
13
+ simplifiedApex;
14
+ clickhouseClient;
15
+ constructor(client) {
16
+ this.clickhouseClient = client;
17
+ this.operation = new OperationDatabase(this.clickhouseClient);
18
+ this.performance = new PerformanceDatabase(this.clickhouseClient);
19
+ this.simplifiedApex = new SimplifiedApexDatabase(this.clickhouseClient);
20
+ }
21
+ /**
22
+ * Returns the singleton instance.
23
+ * Concurrent callers share the same initialization promise so schema setup runs once.
24
+ */
25
+ static async getInstance() {
26
+ if (!LabDbClass._instance) {
27
+ LabDbClass._instance = (async () => {
28
+ const clickhouseClient = await ClickHouseDatabaseClient.getClient({ prefix: 'LABDB', tunnelType: 'GO' });
29
+ const instance = new LabDbClass(clickhouseClient);
30
+ // Behaves like an async constructor: create DBs/tables before the proxy exposes the instance.
31
+ await instance.init();
32
+ return instance;
33
+ })();
34
+ }
35
+ return await LabDbClass._instance;
36
+ }
37
+ /**
38
+ * Returns the ClickHouse client.
39
+ * @returns The ClickHouse client.
40
+ * @deprecated Avoid using this method directly. Find alternative ways
41
+ * to query the database using the database-specific methods instead.
42
+ */
43
+ async getClient() {
44
+ const instance = await LabDbClass.getInstance();
45
+ return instance.clickhouseClient;
46
+ }
47
+ async init() {
48
+ await Promise.all([
49
+ this.operation.init(),
50
+ this.performance.init(),
51
+ this.simplifiedApex.init(),
52
+ ]);
53
+ }
54
+ /**
55
+ * Executes a query from a .sql file with optional parameter substitutions.
56
+ * @param filePath Absolute or relative path to the .sql file.
57
+ * @param params Optional key-value substitutions applied to the query (replaces {key} placeholders).
58
+ * @returns Query result rows typed as `T`.
59
+ * @example
60
+ * // Given a SQL file "get_users.sql" with the content:
61
+ * // SELECT * FROM users WHERE created_at >= {start_date} AND created_at <= {end_date}
62
+ * const users = await clickhouseService.queryFromFile<User>('get_users.sql', {
63
+ * start_date: '2024-01-01',
64
+ * end_date: '2024-12-31',
65
+ * });
66
+ */
67
+ async queryFromFile(filePath, params) {
68
+ return await queryFromFile(this.clickhouseClient, filePath, params);
69
+ }
70
+ /**
71
+ * Executes a query from a string.
72
+ * @param client The ClickHouse client to use for executing the query.
73
+ * @param query The SQL query to execute, with optional {key} placeholders for parameters.
74
+ * @param params Optional key-value substitutions applied to the query (replaces {key} placeholders).
75
+ * @returns Query result rows typed as `T`.
76
+ * @example
77
+ * const users = await queryFromString<User>(clickhouseClient,
78
+ * 'SELECT * FROM users WHERE created_at >= {start_date} AND created_at <= {end_date}',
79
+ * { start_date: '2024-01-01', end_date: '2024-12-31' }
80
+ * );
81
+ */
82
+ async queryFromString(query, params) {
83
+ return await queryFromString(this.clickhouseClient, query, params);
84
+ }
85
+ }
86
+ /* * */
87
+ export const labDb = asyncSingletonProxy(LabDbClass);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmlmobilidade/go-interfaces-labdb",
3
- "version": "20260726.1208.42",
3
+ "version": "20260726.1412.44",
4
4
  "author": {
5
5
  "email": "iso@tmlmobilidade.pt",
6
6
  "name": "TML-ISO"