feat(M01-B): 建立核心迁移与MySQL连接池
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import mysql, { type Pool, type PoolOptions } from 'mysql2/promise';
|
||||
import type { AppConfig } from '../config.js';
|
||||
|
||||
export type MySqlPool = Pool;
|
||||
|
||||
export function createMySqlPool(config: AppConfig): MySqlPool {
|
||||
return mysql.createPool(toPoolOptions(config));
|
||||
}
|
||||
|
||||
export function toPoolOptions(config: AppConfig): PoolOptions {
|
||||
return {
|
||||
host: config.mysql.host,
|
||||
port: config.mysql.port,
|
||||
database: config.mysql.database,
|
||||
user: config.mysql.user,
|
||||
password: config.mysql.password,
|
||||
waitForConnections: true,
|
||||
connectionLimit: config.mysql.connectionLimit,
|
||||
namedPlaceholders: true,
|
||||
timezone: 'Z',
|
||||
dateStrings: false
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user