how to properly close mysql pool connection?

Just wanted to add a migrate.ts file, and got this out a example:
import "dotenv/config"
import { migrate } from "drizzle-orm/mysql2/migrator"
import db from "@/app/db/drizzle"

// This will run migrations on the database, skipping the ones already applied
migrate(db, { migrationsFolder: "./drizzle" }).catch(() => {});

// Don't forget to close the connection, otherwise the script will hang
import "dotenv/config"
import { migrate } from "drizzle-orm/mysql2/migrator"
import db from "@/app/db/drizzle"

// This will run migrations on the database, skipping the ones already applied
migrate(db, { migrationsFolder: "./drizzle" }).catch(() => {});

// Don't forget to close the connection, otherwise the script will hang
but how would I close the connection there? thats my drizzle.ts file:
import "dotenv/config";
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2";

// we are using createPool instead of createConnection as createConnection won't work over long run time.
export const sql = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
})

const db = drizzle(sql);

export default db;
import "dotenv/config";
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2";

// we are using createPool instead of createConnection as createConnection won't work over long run time.
export const sql = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
})

const db = drizzle(sql);

export default db;
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server