Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
PostgresSQL client to Nodejs servers
Did you like the project? Please, considerate a donation to help improve!
PostgresSQL client to Nodejs servers✨
Connect your database easily using the pgnode package
To install the module in your project just run the command below:
npm i pgnode
or
yarn add pgnode
Now in your project just import the module like this:
const pg = require("pgnode");
Or you can use import:
import pg from "pgnode";
This is the simplest possible way to connect, query, and disconnect with async/await:
import pg, { Client, Pool } from "pgnode";
const config = {
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DATABASE,
password: process.env.POSTGRES_PASSWORD,
port: Number(process.env.POSTGRES_PORT),
};
const client = new pg.Client({ ...config });
function query(sql, params) {
return client
.connect()
.then(() => client.query(sql, params))
.then((res) => {
client.end();
return res;
});
}
import {tx, Client, Pool} from 'pgnode';
const client = new Client({
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DATABASE,
password: process.env.POSTGRES_PASSWORD,
port: Number(process.env.POSTGRES_PORT)
});
const pool = new Pool({...client});
export async function createTable(){
return await tx(pool, async (db) => {
await db.query(`
CREATE TABLE IF NOT EXISTS test
(
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);`);
});
}
// or use a generator function to create the transactions
export function* createTableGenerator(){
yield tx(pool, async (db) => {
await db.query(`
CREATE TABLE IF NOT EXISTS test
(
id SERIAL PRIMARY KEY,
name TEXT NOT NULL
);`);
});
// create another transaction
yield tx(pool, async (db) => {
await db.query(`
INSERT INTO test (name) VALUES ('test');`);
});
}
tls.connect
options being passed to the client/pool constructor under the ssl
option.LISTEN/NOTIFY
COPY TO/COPY FROM
pg.Client
and pg.Pool
are ES6 classespg.Client.prototype.query
and pg.Pool.prototype.query
^v16x
FAQs
PostgresSQL client to Nodejs servers
The npm package pgnode receives a total of 12 weekly downloads. As such, pgnode popularity was classified as not popular.
We found that pgnode demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.