MCPcopy
hub / github.com/sequelize/sequelize / connect

Method connect

lib/dialects/postgres/connection-manager.js:86–251  ·  view source on GitHub ↗
(config)

Source from the content-addressed store, hash-verified

84 }
85
86 async connect(config) {
87 config.user = config.username;
88 const connectionConfig = _.pick(config, [
89 'user', 'password', 'host', 'database', 'port'
90 ]);
91
92 connectionConfig.types = {
93 getTypeParser: ConnectionManager.prototype.getTypeParser.bind(this)
94 };
95
96 if (config.dialectOptions) {
97 _.merge(connectionConfig,
98 _.pick(config.dialectOptions, [
99 // see [http://www.postgresql.org/docs/9.3/static/runtime-config-logging.html#GUC-APPLICATION-NAME]
100 'application_name',
101 // choose the SSL mode with the PGSSLMODE environment variable
102 // object format: [https://github.com/brianc/node-postgres/blob/ee19e74ffa6309c9c5e8e01746261a8f651661f8/lib/connection.js#L79]
103 // see also [http://www.postgresql.org/docs/9.3/static/libpq-ssl.html]
104 'ssl',
105 // In addition to the values accepted by the corresponding server,
106 // you can use "auto" to determine the right encoding from the
107 // current locale in the client (LC_CTYPE environment variable on Unix systems)
108 'client_encoding',
109 // !! DO NOT SET THIS TO TRUE !!
110 // (unless you know what you're doing)
111 // see [http://www.postgresql.org/message-id/flat/bc9549a50706040852u27633f41ib1e6b09f8339d845@mail.gmail.com#bc9549a50706040852u27633f41ib1e6b09f8339d845@mail.gmail.com]
112 'binary',
113 // This should help with backends incorrectly considering idle clients to be dead and prematurely disconnecting them.
114 // this feature has been added in pg module v6.0.0, check pg/CHANGELOG.md
115 'keepAlive',
116 // Times out queries after a set time in milliseconds in the database end. Added in pg v7.3
117 'statement_timeout',
118 // Times out queries after a set time in milliseconds in client end, query would be still running in database end.
119 'query_timeout',
120 // Terminate any session with an open transaction that has been idle for longer than the specified duration in milliseconds. Added in pg v7.17.0 only supported in postgres >= 10
121 'idle_in_transaction_session_timeout',
122 // Postgres allows additional session variables to be configured in the connection string in the `options` param.
123 // see [https://www.postgresql.org/docs/14/libpq-connect.html#LIBPQ-CONNECT-OPTIONS]
124 'options'
125 ]));
126 }
127
128 const connection = await new Promise((resolve, reject) => {
129 let responded = false;
130
131 const connection = new this.lib.Client(connectionConfig);
132
133 const parameterHandler = message => {
134 switch (message.parameterName) {
135 case 'server_version':
136 if (this.sequelize.options.databaseVersion === 0) {
137 const version = semver.coerce(message.parameterValue).version;
138 this.sequelize.options.databaseVersion = semver.valid(version)
139 ? version
140 : this.dialect.defaultVersion;
141 }
142 break;
143 case 'standard_conforming_strings':

Callers

nothing calls this directly

Calls 4

_refreshDynamicOIDsMethod · 0.95
destroyMethod · 0.80
warnMethod · 0.65
queryMethod · 0.45

Tested by

no test coverage detected