refactor(connection): corrected the connection to the old system
This commit is contained in:
@@ -1,46 +1,41 @@
|
|||||||
import pkg from "pg";
|
import pkg from "pg";
|
||||||
const { Client } = pkg;
|
const { Pool } = pkg;
|
||||||
|
|
||||||
const v1client = new Client({
|
const baseConfig = {
|
||||||
host: "localhost",
|
host: process.env.DATABASE_HOST ?? "localhost",
|
||||||
port: 5432,
|
port: parseInt(process.env.DATABASE_PORT ?? "5433", 10),
|
||||||
user: "postgres",
|
user: process.env.DATABASE_USER,
|
||||||
password: "obelix",
|
password: process.env.DATABASE_PASSWORD,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Pools (one per DB)
|
||||||
|
const v1Pool = new Pool({
|
||||||
|
...baseConfig,
|
||||||
database: "lst",
|
database: "lst",
|
||||||
});
|
});
|
||||||
|
|
||||||
const v2client = new Client({
|
const v2Pool = new Pool({
|
||||||
host: "localhost",
|
...baseConfig,
|
||||||
port: 5432,
|
|
||||||
user: "postgres",
|
|
||||||
password: "obelix",
|
|
||||||
database: "lst_db",
|
database: "lst_db",
|
||||||
});
|
});
|
||||||
|
|
||||||
export const v1QueryRun= async (query:string)=> {
|
// Query helpers
|
||||||
|
export const v1QueryRun = async (query: string, params?: any[]) => {
|
||||||
try {
|
try {
|
||||||
await v1client.connect();
|
const res = await v1Pool.query(query, params);
|
||||||
|
return res;
|
||||||
const res = await v1client.query(query);
|
|
||||||
|
|
||||||
console.log("Rows affected:", res.rowCount);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error running query:", err);
|
console.error("V1 query error:", err);
|
||||||
} finally {
|
throw err;
|
||||||
await v1client.end();
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
export const v2QueryRun = async (query:string)=> {
|
export const v2QueryRun = async (query: string, params?: any[]) => {
|
||||||
try {
|
try {
|
||||||
await v2client.connect();
|
const res = await v2Pool.query(query, params);
|
||||||
|
return res;
|
||||||
const res = await v2client.query(query);
|
|
||||||
|
|
||||||
console.log("Rows affected:", res.rowCount);
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error running query:", err);
|
console.error("V2 query error:", err);
|
||||||
} finally {
|
throw err;
|
||||||
await v2client.end();
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
Reference in New Issue
Block a user