> ## Documentation Index
> Fetch the complete documentation index at: https://projectdiscovery-nuclei-syntax-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Postgres.PGClient

# Class: PGClient

[postgres](/templates/protocols/javascript/modules/postgres).PGClient

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

**`Example`**

```javascript
const postgres = require('nuclei/postgres');
const client = new postgres.PGClient;
```

## Table of contents

### Constructors

* [constructor](/templates/protocols/javascript/modules/postgres.PGClient#constructor)

### Methods

* [Connect](/templates/protocols/javascript/modules/postgres.PGClient#connect)
* [ConnectWithDB](/templates/protocols/javascript/modules/postgres.PGClient#connectwithdb)
* [ExecuteQuery](/templates/protocols/javascript/modules/postgres.PGClient#executequery)
* [IsPostgres](/templates/protocols/javascript/modules/postgres.PGClient#ispostgres)

## Constructors

### constructor

• **new PGClient**(): [`PGClient`](/templates/protocols/javascript/modules/postgres.PGClient)

#### Returns

[`PGClient`](/templates/protocols/javascript/modules/postgres.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

| Name       | Type     |
| :--------- | :------- |
| `host`     | `string` |
| `port`     | `number` |
| `username` | `string` |

#### Returns

`boolean`

**`Example`**

```javascript
const postgres = require('nuclei/postgres');
const client = new postgres.PGClient;
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

| Name       | Type     |
| :--------- | :------- |
| `host`     | `string` |
| `port`     | `number` |
| `username` | `string` |

#### Returns

`boolean`

**`Example`**

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

#### Defined in

postgres.ts:78

***

### ExecuteQuery

▸ **ExecuteQuery**(`host`, `port`, `username`): [`SQLResult`](/templates/protocols/javascript/modules/postgres.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

| Name       | Type     |
| :--------- | :------- |
| `host`     | `string` |
| `port`     | `number` |
| `username` | `string` |

#### Returns

[`SQLResult`](/templates/protocols/javascript/modules/postgres.SQLResult)

**`Example`**

```javascript
const postgres = require('nuclei/postgres');
const client = new postgres.PGClient;
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

| Name   | Type     |
| :----- | :------- |
| `host` | `string` |
| `port` | `number` |

#### Returns

`boolean`

**`Example`**

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

#### Defined in

postgres.ts:27
