MCPcopy Create free account
hub / github.com/CommE2E/comm / loadPool

Function loadPool

keyserver/src/database/database.js:32–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30
31let pool, databaseMonitor;
32async 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
59function endPool() {
60 pool?.end();

Callers 1

dbQueryFunction · 0.85

Calls 2

getScriptContextFunction · 0.90
getDBConfigFunction · 0.90

Tested by

no test coverage detected