Observer embryo, Maestro done
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import mysql from 'mysql2/promise'
|
||||
|
||||
export function resolveMysqlCredentials(config = {}) {
|
||||
const user = process.env.user
|
||||
const password = process.env.mysql_pass
|
||||
if(!user || !password) {
|
||||
throw new Error('Missing MySQL credentials: set user and mysql_pass in environment')
|
||||
}
|
||||
return({
|
||||
socketPath: config.socketPath,
|
||||
host: config.host,
|
||||
port: config.port,
|
||||
user,
|
||||
password,
|
||||
database: config.database ?? 'p42GUI',
|
||||
waitForConnections: true,
|
||||
connectionLimit: config.connectionLimit ?? 5,
|
||||
queueLimit: 0,
|
||||
})
|
||||
}
|
||||
|
||||
export async function createMysqlPool(config) {
|
||||
return(await mysql.createPool(resolveMysqlCredentials(config)))
|
||||
}
|
||||
|
||||
export async function mysqlExecute(pool, query, values = []) {
|
||||
const [rows] = await pool.execute(query, values)
|
||||
return(rows)
|
||||
}
|
||||
Reference in New Issue
Block a user