Skip to content

Commit

Permalink
refactor: simplify database connection setup and remove global variab…
Browse files Browse the repository at this point in the history
…le usage
  • Loading branch information
robertotcestari committed Sep 16, 2024
1 parent d3bcfe8 commit ca9da55
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/features/codante-apis/senator-expenses/db/db.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
import { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';

declare global {
var _db: ReturnType<typeof drizzle> | undefined;
}
import * as schema from './schema';

const poolConnection = mysql.createPool({
user: process.env.DATABASE_USER_SENATOR_EXPENSES,
password: process.env.DATABASE_PASSWORD_SENATOR_EXPENSES,
database: process.env.DATABASE_SENATOR_EXPENSES,
});

const db = globalThis._db || drizzle(poolConnection);

if (process.env.NODE_ENV !== 'production') {
globalThis._db = db;
}
const db = drizzle(poolConnection, { schema, mode: 'default' });

export { db, poolConnection };

0 comments on commit ca9da55

Please sign in to comment.