Skip to main content

类: PGClient

postgres.PGClient PGClient 是一个用于 Postgres 数据库的客户端。 内部客户端使用 go-pg/pg 驱动程序。 示例
const postgres = require('nuclei/postgres');
const client = new postgres.PGClient;

目录

构造函数

方法

构造函数

constructor

new PGClient(): PGClient

返回

PGClient

定义于

postgres.ts:16

方法

Connect

Connect(host, port, username): boolean Connect 使用给定的凭据连接到 Postgres 数据库。 如果连接成功,它返回 true。 如果连接不成功,它返回 false 和错误。 函数返回后连接关闭。

参数

名称类型
hoststring
portnumber
usernamestring

返回

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

定义于

postgres.ts:44

ConnectWithDB

ConnectWithDB(host, port, username): boolean ConnectWithDB 使用给定的凭据和数据库名称连接到 Postgres 数据库。 如果连接成功,它返回 true。 如果连接不成功,它返回 false 和错误。 函数返回后连接关闭。

参数

名称类型
hoststring
portnumber
usernamestring

返回

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

定义于

postgres.ts:78

ExecuteQuery

ExecuteQuery(host, port, username): SQLResult ExecuteQuery 使用给定的凭据和数据库名称连接到 Postgres 数据库, 并在数据库上执行查询。 如果连接成功,它返回查询的结果。

参数

名称类型
hoststring
portnumber
usernamestring

返回

SQLResult 示例
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));

定义于

postgres.ts:61

IsPostgres

IsPostgres(host, port): boolean IsPostgres 检查给定的主机和端口是否运行 Postgres 数据库。 如果连接成功,它返回 true。 如果连接不成功,它返回 false 和错误。

参数

名称类型
hoststring
portnumber

返回

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

定义于

postgres.ts:27