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

# Postgres

<a name="module_postgres" />

## postgres

* [postgres](#module_postgres)
  * [`PGClient`](#module_postgres..PGClient)
    * [`.Connect(host, port, username, password)`](#module_postgres..PGClient+Connect) ⇒ <code>bool</code>
    * [`.ConnectWithDB(host, port, username, password, dbName)`](#module_postgres..PGClient+ConnectWithDB) ⇒ <code>bool</code>
    * [`.ExecuteQuery(host, port, username, password, dbName, query)`](#module_postgres..PGClient+ExecuteQuery) ⇒ <code>string</code>
    * [`.IsPostgres(host, port)`](#module_postgres..PGClient+IsPostgres) ⇒ <code>bool</code>

<a name="module_postgres..PGClient" />

### (postgres).PGClient

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

**Kind**: inner class of [<code>postgres</code>](#module_postgres)

* [`PGClient`](#module_postgres..PGClient)
  * [`.Connect(host, port, username, password)`](#module_postgres..PGClient+Connect) ⇒ <code>bool</code>
  * [`.ConnectWithDB(host, port, username, password, dbName)`](#module_postgres..PGClient+ConnectWithDB) ⇒ <code>bool</code>
  * [`.ExecuteQuery(host, port, username, password, dbName, query)`](#module_postgres..PGClient+ExecuteQuery) ⇒ <code>string</code>
  * [`.IsPostgres(host, port)`](#module_postgres..PGClient+IsPostgres) ⇒ <code>bool</code>

<a name="module_postgres..PGClient+Connect" />

#### pgClient.Connect(host, port, username, password) ⇒ <code>bool</code>

Connect connects to Postgres database using given credentials. The connection is closed after the function returns.

**Kind**: instance method of [<code>PGClient</code>](#module_postgres..PGClient)\
**Returns**: <code>bool</code> - - If connection is successful, it returns true.\
**Throws**:

* <code>error</code> - If connection is unsuccessful, it returns the error.

| Param    | Type                | Description                                       |
| -------- | ------------------- | ------------------------------------------------- |
| host     | <code>string</code> | The host of the Postgres database.                |
| port     | <code>int</code>    | The port of the Postgres database.                |
| username | <code>string</code> | The username to connect to the Postgres database. |
| password | <code>string</code> | The password to connect to the Postgres database. |

**Example**

```js
let m = require('nuclei/postgres');
let c = m.PGClient();
let isConnected = c.Connect('localhost', 5432, 'username', 'password');
```

<a name="module_postgres..PGClient+ConnectWithDB" />

#### pgClient.ConnectWithDB(host, port, username, password, dbName) ⇒ <code>bool</code>

ConnectWithDB connects to Postgres database using given credentials and database name. The connection is closed after the function returns.

**Kind**: instance method of [<code>PGClient</code>](#module_postgres..PGClient)\
**Returns**: <code>bool</code> - - If connection is successful, it returns true.\
**Throws**:

* <code>error</code> - If connection is unsuccessful, it returns the error.

| Param    | Type                | Description                                       |
| -------- | ------------------- | ------------------------------------------------- |
| host     | <code>string</code> | The host of the Postgres database.                |
| port     | <code>int</code>    | The port of the Postgres database.                |
| username | <code>string</code> | The username to connect to the Postgres database. |
| password | <code>string</code> | The password to connect to the Postgres database. |
| dbName   | <code>string</code> | The name of the database to connect to.           |

**Example**

```js
let m = require('nuclei/postgres');
let c = m.PGClient();
let isConnected = c.ConnectWithDB('localhost', 5432, 'username', 'password', 'mydb');
```

<a name="module_postgres..PGClient+ExecuteQuery" />

#### pgClient.ExecuteQuery(host, port, username, password, dbName, query) ⇒ <code>string</code>

ExecuteQuery connects to Postgres database using given credentials and database name and executes a query on the db.

**Kind**: instance method of [<code>PGClient</code>](#module_postgres..PGClient)\
**Returns**: <code>string</code> - - The result of the query execution.\
**Throws**:

* <code>error</code> - If query execution is unsuccessful, it returns the error.

| Param    | Type                | Description                                       |
| -------- | ------------------- | ------------------------------------------------- |
| host     | <code>string</code> | The host of the Postgres database.                |
| port     | <code>int</code>    | The port of the Postgres database.                |
| username | <code>string</code> | The username to connect to the Postgres database. |
| password | <code>string</code> | The password to connect to the Postgres database. |
| dbName   | <code>string</code> | The name of the database to connect to.           |
| query    | <code>string</code> | The query to execute on the database.             |

**Example**

```js
let m = require('nuclei/postgres');
let c = m.PGClient();
let result = c.ExecuteQuery('localhost', 5432, 'username', 'password', 'mydb', 'SELECT * FROM users');
```

<a name="module_postgres..PGClient+IsPostgres" />

#### pgClient.IsPostgres(host, port) ⇒ <code>bool</code>

IsPostgres checks if the given host and port are running Postgres database.

**Kind**: instance method of [<code>PGClient</code>](#module_postgres..PGClient)\
**Returns**: <code>bool</code> - - If the host and port are running Postgres database, it returns true.\
**Throws**:

* <code>error</code> - If the check is unsuccessful, it returns the error.

| Param | Type                | Description        |
| ----- | ------------------- | ------------------ |
| host  | <code>string</code> | The host to check. |
| port  | <code>int</code>    | The port to check. |

**Example**

```js
let m = require('nuclei/postgres');
let c = m.PGClient();
let isPostgres = c.IsPostgres('localhost', 5432);
```
