feat: add SQL Server connection pool utility
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
22
lib/db.ts
Normal file
22
lib/db.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import sql from "mssql";
|
||||
|
||||
const dbConfig: sql.config = {
|
||||
server: process.env.DB_SERVER!,
|
||||
port: Number(process.env.DB_PORT) || 1433,
|
||||
database: process.env.DB_DATABASE!,
|
||||
user: process.env.DB_USER!,
|
||||
password: process.env.DB_PASSWORD!,
|
||||
options: {
|
||||
encrypt: false,
|
||||
trustServerCertificate: true,
|
||||
enableArithAbort: true,
|
||||
},
|
||||
};
|
||||
|
||||
let pool: sql.ConnectionPool | null = null;
|
||||
|
||||
export async function getPool(): Promise<sql.ConnectionPool> {
|
||||
if (pool && pool.connected) return pool;
|
||||
pool = await sql.connect(dbConfig);
|
||||
return pool;
|
||||
}
|
||||
Reference in New Issue
Block a user