Connecting to the database
To connect to the database, import the default database module and provide the necessary options.
The options are as follows:
host
(string) the host of your databaseport
(number) the port to connect ondbName
(string) the name of your postgres databaseusername
(string) the user to connect aspassword
(string) the users passwordconnectionString
(string) the connection string URIssl
(object) passed directly to node.TLSSocket, supports all tls.connect optionsstatementTimeout
(number) number of milliseconds before a statement in query will time out, default is no timeoutqueryTimeout
(number) number of milliseconds before a query call will timeout, default is no timeoutidleInTransactionSessionTimeout
(number) number of milliseconds before terminating any session with an open idle transaction, default is no timeout
#
SSLThe package supports TLS/SSL connections to your PostgreSQL server as long as the server is configured to support it. When instantiating a pool or a client you can provide an ssl property on the config object and it will be passed to the constructor for the node TLSSocket. node TLSSocket.
#
Connect DatabaseAfter you create the instance, call connectDB()
to make the connection. Make sure the promise resolves before using the connection any further.