-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
51 lines (48 loc) · 1.68 KB
/
index.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
const { Connection } = require('./lib/core/connection')
const { DataAccess } = require('./lib/core/dataAccess')
const { ModelImpl } = require('./lib/model')
const { DataType } = require('./lib/dataType')
class PgLink {
/**
* @param {{host:string,port:number,userName:string,password:string,database:string,connectionMax:number,globalAutoSetTimeFields:Array<striing>,idleTimeoutMillis:number,connectionTimeoutMillis:number}} args
*/
constructor(args) {
const {
host,
port,
password,
userName,
database,
connectionMax,
connectionTimeoutMillis,
idleTimeoutMillis,
ssl, // v0.3.5
globalAutoSetTimeFields = [] // v0.1.8 for whole app to use
} = args
const connection = Connection({
host,
port,
password,
userName,
database,
// maximum number of clients the pool should contain
// by default this is set to 10.
connectionMax,
// number of milliseconds to wait before timing out when connecting a new client
// by default this is 0 which means no timeout
connectionTimeoutMillis,
// number of milliseconds a client must sit idle in the pool and not be checked out
// before it is disconnected from the backend and discarded
// default is 10000 (10 seconds) - set to 0 to disable auto-disconnection of idle clients
idleTimeoutMillis,
ssl
})
console.info(`Connected DB at ${host}:${port}/${database} successfully!👍`)
this.Model = ModelImpl(new DataAccess(connection), globalAutoSetTimeFields)
this.DataTypes = DataType
}
}
module.exports = { PgLink }
module.exports.PgLink = PgLink
module.exports.default = PgLink