https://github.com/evbots/serverless-pg
A PostgreSQL client for Node.js serverless applications.
https://github.com/evbots/serverless-pg
postgresql serverless
Last synced: 6 months ago
JSON representation
A PostgreSQL client for Node.js serverless applications.
- Host: GitHub
- URL: https://github.com/evbots/serverless-pg
- Owner: evbots
- Created: 2019-09-14T00:07:30.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T22:00:50.000Z (about 3 years ago)
- Last Synced: 2025-08-18T13:51:22.268Z (7 months ago)
- Topics: postgresql, serverless
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/serverless-pg
- Size: 649 KB
- Stars: 9
- Watchers: 2
- Forks: 3
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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:
```javascript
// client.js
import createClient from 'serverless-pg';
const dbClient = 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: () => {},
});
export default dbClient;
```
Then, import anywhere in your application and use.
```javascript
// handler.js
import dbClient from './client';
const handler = async () => {
// calling query automagically connects to the database
await dbClient.query('SELECT * FROM users');
await dbClient.transaction([
() => dbClient.query(''),
() => dbClient.query('')
]);
await dbClient.end();
};
```