MCPcopy
hub / github.com/entropic-dev/entropic / providePostgres

Function providePostgres

services/storage/test/utils/postgres.js:8–45  ·  view source on GitHub ↗
(to)

Source from the content-addressed store, hash-verified

6const { Client } = require('pg');
7
8function providePostgres(to) {
9 return async function(...args) {
10 const client = new Client();
11
12 await client.connect();
13 await client.query('begin');
14 if (typeof to.middleware === 'function') {
15 to.middleware([
16 ...to.middleware(),
17 function addpg() {
18 return next => {
19 return req => {
20 req.getPostgresClient = async () => client;
21 return next(req);
22 };
23 };
24 }
25 ]);
26 }
27
28 orm.setConnection(async () => {
29 return {
30 connection: client,
31 release() {}
32 };
33 });
34
35 try {
36 await to(...args);
37 } finally {
38 await client.query('rollback');
39 await client.end();
40 orm.setConnection(() => {
41 throw new Error('no connection available');
42 });
43 }
44 };
45}

Callers 5

00-basics.spec.jsFile · 0.85
user.spec.jsFile · 0.85
package.spec.jsFile · 0.85
token.spec.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected