-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.mjs
More file actions
36 lines (30 loc) · 1.11 KB
/
utils.mjs
File metadata and controls
36 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { mixin } from 'mixin-prototypes' ;
import { AsyncContext } from 'asynchronous-context' ;
import { DatabaseContext } from 'database-postgresql-context' ;
import { dotenvFromSettings } from "asynchronous-context/env" ;
dotenvFromSettings();
class Hello {
ctor(...args) {
this.contextInitializers.push( async function databaseContextInitializer() {
await this.register_pg_eventhandler( 'notice', async (msg)=>{
const __msg = { ...msg };
for ( const i in __msg ) {
if ( typeof __msg[i] === 'undefined' ) {
delete __msg[i];
}
}
this.logger.output( {
type : 'postgresql-notice',
contents:__msg,
});
});
});
this.contextFinalizers.push(async function databaseContextFinalizer(is_successful) {
});
}
}
export const execute = async (fn)=>{
const THello = mixin( 'THello', AsyncContext, DatabaseContext , Hello );
const context = THello.create({ autoConnect: false, autoCommit:false, coloredReport:true, reportMethod:'stderr' });
await context.executeTransaction( fn );
};