parent
ecd9d2b8f4
commit
c406590923
@ -0,0 +1,8 @@ |
|||||||
|
import { Global, Module } from '@nestjs/common'; |
||||||
|
import { GdatabaseService } from './gdatabase.service'; |
||||||
|
@Global() |
||||||
|
@Module({ |
||||||
|
providers: [GdatabaseService], |
||||||
|
exports: [GdatabaseService], |
||||||
|
}) |
||||||
|
export class GdatabaseModule {} |
@ -0,0 +1,29 @@ |
|||||||
|
import { Injectable } from '@nestjs/common'; |
||||||
|
import * as mysql from 'mysql2/promise'; |
||||||
|
import config from '../../config'; |
||||||
|
|
||||||
|
@Injectable() |
||||||
|
export class GdatabaseService { |
||||||
|
public DB; |
||||||
|
constructor() { |
||||||
|
this.start(); |
||||||
|
} |
||||||
|
private async start() { |
||||||
|
const DBConfig = config().databases.starLight; |
||||||
|
const DB = mysql.createPool({ |
||||||
|
host: DBConfig.host, |
||||||
|
port: DBConfig.port, |
||||||
|
user: DBConfig.username, |
||||||
|
password: DBConfig.password, |
||||||
|
database: DBConfig.database, |
||||||
|
connectionLimit: 20, // 用于指定连接池中最大的链接数,默认属性值为10.
|
||||||
|
multipleStatements: true, //是否允许执行多条sql语句,默认值为false
|
||||||
|
waitForConnections: true, // 超过最大连接时排队
|
||||||
|
queueLimit: 0, // 排队最大数量(0 代表不做限制)
|
||||||
|
maxIdle: 20, // 最大空闲连接数
|
||||||
|
idleTimeout: 60000, // 空闲连接超时,以毫秒为单位,默认值60000
|
||||||
|
}); |
||||||
|
this.DB = DB; |
||||||
|
return DB; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue