@stackql/pgwire-lite
v1.0.1
Published
A lightweight PostgreSQL wire protocol client built with Node.js
Downloads
23
Readme
pgwire-lite
pgwire-lite
is a minimalistic PostgreSQL wire protocol library for Node.js. It is designed to be a lightweight alternative to other PostgreSQL wire protocol libraries, providing a simple and efficient way to connect to and interact with PostgreSQL wire protocol-compatible servers, such as stackql
.
Features
- Lightweight and minimal PostgreSQL wire protocol client
- Supports both secure (TLS) and non-secure connections
- Easily customizable and extendable
- Designed to interact with PostgreSQL wire protocol-compatible services like
stackql
Installation
To install pgwire-lite
, run the following command:
npm i @stackql/pgwire-lite
Quickstart
Below is an example of how to use pgwire-lite
to connect to a PostgreSQL-compatible server with both TLS and non-TLS options.
Example: run queries against a server without TLS
import { runQuery } from '@stackql/pgwire-lite';
const connectionOptions = {
user: 'stackql',
database: 'stackql',
host: 'localhost',
port: 5444,
debug: false,
};
(async () => {
try {
const result = await runQuery(connectionOptions, "REGISTRY LIST");
console.info(result.data);
} catch (error) {
console.error('Error executing queries:', error.message);
}
})();
Example: run queries against a server with TLS
import fs from 'fs';
import { runQuery } from '@stackql/pgwire-lite';
const connectionOptions = {
user: 'stackql',
database: 'stackql',
host: 'localhost',
port: 5444,
debug: true,
cert: fs.readFileSync('/path/to/client_cert.pem'),
key: fs.readFileSync('/path/to/client_key.pem'),
ca: fs.readFileSync('/path/to/server_cert.pem'),
};
(async () => {
try {
const result = await runQuery(connectionOptions, "REGISTRY LIST");
console.info(result.data);
} catch (error) {
console.error('Error executing queries:', error.message);
}
})();
Testing
You can test pgwire-lite
using stackql by following these steps.
Step 1: Download stackql
curl -L https://bit.ly/stackql-zip -O && unzip stackql-zip
Step 2: Running Tests
Test without TLS:
npm test
Test with TLS:
npm run secure-test # or NODE_DEBUG=tls,node::http npm run secure-test
Step 3: Running the Example App (optional)
Test without TLS:
sh start-server.sh node example/app.js sh stop-server.sh
Test with TLS:
sh start-secure-server.sh node example/app.js true sh stop-server.sh
Publishing
to publish or update on npmjs:
npm login
npm publish --access public