// import "dotenv/config";
// import { drizzle } from "drizzle-orm/node-postgres";
// import { Client } from "pg";
// import * as schema from "./schema";
// import { env } from "process";

// console.log({ Client });

// const connection = new Client({
//   host: env.DB_SERVER,
//   user: env.DB_USERNAME,
//   port: Number(env.DB_PORT),
//   password: env.DB_PASSWORD,
//   database: env.DB_NAME,
// });
// await connection.connect();
// const database = drizzle(connection, { schema });

// export { connection, database };

import "dotenv/config";
import { drizzle } from "drizzle-orm/mysql2";
import { createConnection } from "mysql2/promise";
import * as schema from "@db/schema";

const options = {
  host: process.env.DB_SERVER,
  user: process.env.DB_USERNAME,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
};

export const connection = await createConnection(options);

export const database = drizzle(connection, {
  schema,
  mode: "default",
});
