()
| 30 | |
| 31 | let pool, databaseMonitor; |
| 32 | async function loadPool(): Promise<Pool> { |
| 33 | if (pool) { |
| 34 | return pool; |
| 35 | } |
| 36 | const scriptContext = getScriptContext(); |
| 37 | const dbConfig = await getDBConfig(); |
| 38 | const options: PoolOptions = { |
| 39 | ...dbConfig, |
| 40 | connectionLimit, |
| 41 | multipleStatements: !!( |
| 42 | scriptContext && scriptContext.allowMultiStatementSQLQueries |
| 43 | ), |
| 44 | }; |
| 45 | |
| 46 | // This function can be run asynchronously multiple times, |
| 47 | // the previous check is not enough because the function will await |
| 48 | // on `getDBConfig()` and as result we might get there |
| 49 | // while the pool is already defined, which will result with |
| 50 | // creating a new pool and losing the previous one which will stay open |
| 51 | if (pool) { |
| 52 | return pool; |
| 53 | } |
| 54 | pool = mysqlPromise.createPool(options); |
| 55 | databaseMonitor = new DatabaseMonitor(pool); |
| 56 | return pool; |
| 57 | } |
| 58 | |
| 59 | function endPool() { |
| 60 | pool?.end(); |
no test coverage detected