Class: PGClient

postgres.PGClient

PGClient is a client for Postgres database. Internally client uses go-pg/pg driver.

Example

const postgres = require('nuclei/postgres');
const client = new postgres.Client();

Table of contents

Constructors

Methods

Constructors

constructor

new PGClient(): PGClient

Returns

PGClient

Defined in

postgres.ts:16

Methods

Connect

Connect(host, port, username): boolean

Connect connects to Postgres database using given credentials. If connection is successful, it returns true. If connection is unsuccessful, it returns false and error. The connection is closed after the function returns.

Parameters

NameType
hoststring
portnumber
usernamestring

Returns

boolean

Example

const postgres = require('nuclei/postgres');
const client = new postgres.Client();
const connected = client.Connect('acme.com', 5432, 'username', 'password');

Defined in

postgres.ts:44


ConnectWithDB

ConnectWithDB(host, port, username): boolean

ConnectWithDB connects to Postgres database using given credentials and database name. If connection is successful, it returns true. If connection is unsuccessful, it returns false and error. The connection is closed after the function returns.

Parameters

NameType
hoststring
portnumber
usernamestring

Returns

boolean

Example

const postgres = require('nuclei/postgres');
const client = new postgres.Client();
const connected = client.ConnectWithDB('acme.com', 5432, 'username', 'password', 'dbname');

Defined in

postgres.ts:78


ExecuteQuery

ExecuteQuery(host, port, username): SQLResult

ExecuteQuery connects to Postgres database using given credentials and database name. and executes a query on the db. If connection is successful, it returns the result of the query.

Parameters

NameType
hoststring
portnumber
usernamestring

Returns

SQLResult

Example

const postgres = require('nuclei/postgres');
const client = new postgres.Client();
const result = client.ExecuteQuery('acme.com', 5432, 'username', 'password', 'dbname', 'select * from users');
log(to_json(result));

Defined in

postgres.ts:61


IsPostgres

IsPostgres(host, port): boolean

IsPostgres checks if the given host and port are running Postgres database. If connection is successful, it returns true. If connection is unsuccessful, it returns false and error.

Parameters

NameType
hoststring
portnumber

Returns

boolean

Example

const postgres = require('nuclei/postgres');
const isPostgres = postgres.IsPostgres('acme.com', 5432);

Defined in

postgres.ts:27