Skip to content

Repository files navigation

serverless-pg

A PostgreSQL client for Node.js serverless applications.

Note: This library is currently alpha and subject to breaking changes. Please install this dependency using an exact version.

About

This module is intended for use in node.js serverless applications. It supports node v8 and above. It is simply some boilerplate around the fantastic pg library for serverless apps.

Installation

npm install serverless-pg --save-exact

How to use

First, setup your client in a dedicated module:

// client.jsimportcreateClientfrom'serverless-pg';constdbClient=createClient({config: {host: process.env.HOST,port: process.env.PORT,user: process.env.USERNAME,password: process.env.PASSWORD,database: process.env.NAME,},onConnect: ()=>{},onClose: ()=>{},beforeQuery: ()=>{},afterQuery: ()=>{},});exportdefaultdbClient;

Then, import anywhere in your application and use.

// handler.jsimportdbClientfrom'./client';consthandler=async()=>{// calling query automagically connects to the databaseawaitdbClient.query('SELECT * FROM users');awaitdbClient.transaction([()=>dbClient.query(''),()=>dbClient.query('')]);awaitdbClient.end();};

About

A PostgreSQL client for Node.js serverless applications.

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages