@uandev/pg-functions
TypeScript icon, indicating that this package has built-in type declarations

3.0.5 • Public • Published

UANDEV - Postgres Functions

I prefer to only call functions from my node applications with PostgreSQL back end. This module is for that. Also, those functions always return data in JSON format ready to be consumed by my JavaScript.

Usage

This module works best with TypeScript. It provides the following:

Interface: PGConfig

The configuration defintion for opening Postgres clients. It contains the following fields:

host

The hostname of the server

port

The port the Postgres service is listening to. Default: 5432

database

The database that should be connected to by the service

ssl

Should you use SSL to communicate with the server true/false.

user

The user account to connect to the server with

password

The password for the user account

Function: Start

Two parameters of the following types: PGConfig and LogWriter (see module @uandev/log). The second parameter is optional in case you are not using @uandev/log. This generates a new connection pool that will be used to generate clients for database function calls.

Function: Stop

Close the connection pool.

Function Execute

Returns a new promise that will resolve to the provided type T if using Typescript. The required parameter is the name of the function which should include the schema name. Parameters are optional and can be of any type. They will be resolved to proper postgres inputs.

Example

import { PGFunctions } from '@uandev/pg-functions'
import { Log } from '@uandev/log'

let config: PGFunctions.PGConfig = {
  host: 'my.pg.host',
  port: 5432,
  user: 'sericeAccount',
  password: 'pleasedontputpasswordsinsourcecode',
  ssl: true,
  database: 'mydatabase'
}

let log: Log.LogWriter = Log.GetWriter('postgres')

PGFunctions.Start(config, log)

PGFunctions.Execute<boolean>('myschema.myfunction', 'abc', 123)
  .then((result) => {
    console.log(result)
  })
  .catch((error) => {
    console.log(error.message)
  })

Readme

Keywords

none

Package Sidebar

Install

npm i @uandev/pg-functions

Weekly Downloads

1

Version

3.0.5

License

MIT

Unpacked Size

23.4 kB

Total Files

12

Last publish

Collaborators

  • driverjb