mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-07-26 05:23:37 +00:00
Co-authored-by: 夏姜 <wenfengjiang.jwf@digital-engine.com> Co-authored-by: yhjun1026 <460342015@qq.com> Co-authored-by: aries_ckt <916701291@qq.com> Co-authored-by: wb-lh513319 <wb-lh513319@alibaba-inc.com>
23 lines
613 B
TypeScript
23 lines
613 B
TypeScript
import { Sequelize } from 'sequelize';
|
|
|
|
export let sequelize: Sequelize;
|
|
|
|
const { MYSQL_DATABASE, MYSQL_HOST, MYSQL_PORT, MYSQL_PASSWORD, MYSQL_USERNAME } = process.env;
|
|
|
|
export async function connection() {
|
|
if (sequelize) return;
|
|
try {
|
|
sequelize = new Sequelize(MYSQL_DATABASE!, MYSQL_USERNAME!, MYSQL_PASSWORD!, {
|
|
dialect: 'mysql',
|
|
host: MYSQL_HOST!,
|
|
port: Number(MYSQL_PORT!),
|
|
});
|
|
await sequelize.authenticate();
|
|
console.log('Connection has been established successfully.');
|
|
} catch (e) {
|
|
console.error('Unable to connect to the database:', e);
|
|
}
|
|
}
|
|
|
|
connection();
|