EMS: move DB connection to env

This commit is contained in:
cracklesparkle
2024-12-18 11:28:38 +09:00
parent 87866e4e51
commit dec796b75e
5 changed files with 21 additions and 15 deletions

View File

@ -1,25 +1,30 @@
import { Connection, ConnectionConfiguration, Request } from "tedious";
import 'dotenv/config'
const MSSQL_HOST = process.env.MSSQL_HOST || 'localhost'
const MSSQL_LOGIN = process.env.MSSQL_LOGIN || 'sa'
const MSSQL_PASSWORD = process.env.MSSQL_PASSWORD || ''
const MSSQL_DB = process.env.MSSQL_DB || 'nGeneral'
const MSSQL_PORT = Number(process.env.MSSQL_PORT) || 1433
const tediousConfig: ConnectionConfiguration = {
server: 'localhost',
server: MSSQL_HOST,
options: {
trustServerCertificate: true,
port: 1433,
database: 'nGeneral'
port: MSSQL_PORT,
database: MSSQL_DB
},
authentication: {
type: 'default',
options: {
userName: 'SA',
password: 'oMhthmsvbYHc'
userName: MSSQL_LOGIN,
password: MSSQL_PASSWORD
}
}
}
export function tediousQuery(query: string) {
// Read all rows from table
return new Promise((resolve, reject) => {
const connection = new Connection(tediousConfig)