0.2.0 • Published 5 years ago

@communitylife/cl-postgresql v0.2.0

Weekly downloads
-
License
UNLICENSED
Repository
gitlab
Last release
5 years ago

cl-postgresql

This module provides helper functions to query the specified database.

Prerequisites

Since this package provides only the functions to query the database, a standalone database to connect to is required.

  • NodeJS (>=8.15.0)
  • PostgreSQL Database

These needs to be fulfilled, before proceeding with installation.

Installation

  • npm install @communitylife/cl-postgresql

Environment variables

Please refer to the official ones.

Usage

This module will be used inside your application as a wrapper for database operations.

It contains custom functions for basic CRUD operations (select, insert, update, delete).

Import the module

const db = require('@communitylife/cl-postgresql');

It will automatically connect to specified database based on declared environment variables.

Query the database

db.query('SELECT id FROM demo').then((result) => {
    console.log(result);
}).catch((err) => {
    console.error(err);
});

This function also provides escaping functionality for parameters to prevent SQL injection. Always ensure to use this syntax when applying dynamic data. Always use ? placeholders among params.

db.query('SELECT test FROM demo WHERE id=?', [42]).then((result) => {
    //..
}).catch((err) => {
    // ..
});
0.2.0

5 years ago

0.1.0

5 years ago