[feat] switched from mysql to postgresql
This commit is contained in:
@@ -1,11 +1,23 @@
|
||||
// src/db/index.ts
|
||||
import 'dotenv/config';
|
||||
import { relations } from './relations.ts';
|
||||
import { drizzle } from 'drizzle-orm/mysql2';
|
||||
import mysql from 'mysql2/promise';
|
||||
import { drizzle } from "drizzle-orm/node-postgres";
|
||||
import { Pool } from "pg";
|
||||
|
||||
//export const poolConnection = mysql.createPool({ uri: process.env.DATABASE_URL, client_found_rows: false });
|
||||
export const poolConnection = mysql.createPool({ uri: process.env.DATABASE_URL, flags: ["-FOUND_ROWS"] });
|
||||
const pool = new Pool({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
max: 10,
|
||||
idleTimeoutMillis: 30000,
|
||||
connectionTimeoutMillis: 2000,
|
||||
});
|
||||
|
||||
export const db = drizzle({ client: poolConnection, relations: relations});
|
||||
// Handle pool errors to prevent connection corruption
|
||||
pool.on('error', (err) => {
|
||||
console.error('Unexpected error on idle client', err);
|
||||
});
|
||||
|
||||
export const db = drizzle({ client: pool, relations: relations, casing: 'snake_case' });
|
||||
|
||||
export const ClosePool = () => {
|
||||
pool.end();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user