Skip to content

Commit ae4ae90

Browse files
committed
fix: update connection issue for new connection logic which will parse driver
1 parent 0af1ad8 commit ae4ae90

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

src/client/routes/insights/warehouse/connections/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ type ConnectionItem = {
3232
id: string;
3333
name: string;
3434
description: string;
35-
dbDriver: string;
35+
dbDriver: 'mysql' | 'postgresql';
3636
createdAt: string;
3737
updatedAt: string;
3838
};
@@ -41,7 +41,7 @@ interface ConnectionFormValues {
4141
id?: string;
4242
name: string;
4343
description: string;
44-
dbDriver: string;
44+
dbDriver: 'mysql' | 'postgresql';
4545
}
4646

4747
function PageComponent() {

src/server/model/insights/warehouse/ai.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ export const createWarehouseAITools = (
139139

140140
const connection = getWarehouseConnection(connectionUrl);
141141

142+
if (connection.driver === 'postgresql') {
143+
throw new Error('PostgreSQL connection is not supported yet');
144+
}
145+
142146
// Auto-add LIMIT if not present
143147
let finalSql = sql.trim();
144148
const trimmedSqlLower = finalSql.toLowerCase();
@@ -155,7 +159,8 @@ export const createWarehouseAITools = (
155159
// const [res] = env.isDev
156160
// ? [chatByCountryDemo] // TODO: remove this after testing
157161
// : await connection.query(finalSql);
158-
const [res] = await connection.query(finalSql);
162+
163+
const [res] = await connection.pool.query(finalSql);
159164

160165
logger.info('[queryWarehouse] result:' + JSON.stringify(res));
161166

src/server/model/insights/warehouse/longTable.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,17 @@ export class WarehouseLongTableInsightsSqlBuilder extends InsightsSqlBuilder {
397397

398398
async executeQuery(sql: Prisma.Sql): Promise<any[]> {
399399
const application = this.getApplication();
400+
if (!application.databaseUrl) {
401+
throw new Error('Database url is not set');
402+
}
403+
400404
const connection = getWarehouseConnection(application.databaseUrl);
401405

402-
const [rows] = await connection.query(
406+
if (connection.driver === 'postgresql') {
407+
throw new Error('PostgreSQL connection is not supported yet');
408+
}
409+
410+
const [rows] = await connection.pool.query(
403411
sql.sql.replaceAll('"', '`'), // avoid mysql and pg sql syntax error about double quote
404412
sql.values
405413
);
@@ -483,10 +491,18 @@ export async function insightsLongTableWarehouseEvents(
483491
throw new Error(`Event table not found for application ${applicationId}`);
484492
}
485493

494+
if (!application.databaseUrl) {
495+
throw new Error('Database url is not set');
496+
}
497+
486498
const connection = getWarehouseConnection(application.databaseUrl);
487499
const eventTable = application.eventTable;
488500

489-
const [rows] = await connection.query(`
501+
if (connection.driver === 'postgresql') {
502+
throw new Error('PostgreSQL connection is not supported yet');
503+
}
504+
505+
const [rows] = await connection.pool.query(`
490506
SELECT DISTINCT event_name
491507
FROM (
492508
SELECT \`${eventTable.eventNameField}\` as event_name, \`${eventTable.dateBasedCreatedAtField ?? eventTable.createdAtField}\` as date
@@ -515,10 +531,18 @@ export async function insightsLongTableWarehouseFilterParams(
515531
throw new Error(`Event table not found for application ${applicationId}`);
516532
}
517533

534+
if (!application.databaseUrl) {
535+
throw new Error('Database url is not set');
536+
}
537+
518538
const connection = getWarehouseConnection(application.databaseUrl);
519539
const eventParametersTable = application.eventParametersTable;
520540

521-
const [rows] = await connection.query(`
541+
if (connection.driver === 'postgresql') {
542+
throw new Error('PostgreSQL connection is not supported yet');
543+
}
544+
545+
const [rows] = await connection.pool.query(`
522546
SELECT DISTINCT param_value
523547
FROM (
524548
SELECT \`${eventParametersTable.paramsNameField}\` as param_value, \`${eventParametersTable.dateBasedCreatedAtField ?? eventParametersTable.createdAtField}\` as date

src/server/model/insights/warehouse/wideTable.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,16 @@ export class WarehouseWideTableInsightsSqlBuilder extends InsightsSqlBuilder {
273273

274274
async executeQuery(sql: Prisma.Sql): Promise<any[]> {
275275
const application = this.getApplication();
276+
if (!application.databaseUrl) {
277+
throw new Error('Database url is not set');
278+
}
276279
const connection = getWarehouseConnection(application.databaseUrl);
277280

278-
const [rows] = await connection.query(
281+
if (connection.driver === 'postgresql') {
282+
throw new Error('PostgreSQL connection is not supported yet');
283+
}
284+
285+
const [rows] = await connection.pool.query(
279286
sql.sql.replaceAll('"', '`'), // avoid mysql and pg sql syntax error about double quote
280287
sql.values
281288
);

0 commit comments

Comments
 (0)