Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
connect
✓ const connect = require('postgres-fp/connect')
const connection = await connect({ hostname: 'localhost', port: 5432 })
✗ import { connect } from 'postgres-fp'
This package does not export a single module; functions are imported from individual files. Each function file exports the function directly.
execute
✓ const execute = require('postgres-fp/execute')
const result = await execute(connection, 'CREATE TABLE test (id SERIAL PRIMARY KEY)')
✗ const { execute } = require('postgres-fp')
execute is not exported from the index; import from postgres-fp/execute.
getAll
✓ const getAll = require('postgres-fp/getAll')
const rows = await getAll(connection, 'SELECT * FROM test')
✗ import getAll from 'postgres-fp/getAll'; getAll(connection, 'SELECT') // missing await
getAll returns a promise when using the promise API (postgres-fp/promises) or expects a callback via righto. Ensure you await or use .then.
Connects to PostgreSQL, creates a table, inserts a row, retrieves all rows, and closes the connection using the promise-based API.
const postgres = require('postgres-fp/promises');
async function main() {
const connection = await postgres.connect({
hostname: process.env.PGHOST ?? 'localhost',
port: process.env.PGPORT ?? 5432,
user: process.env.PGUSER ?? 'postgres',
password: process.env.PGPASSWORD ?? '',
database: process.env.PGDATABASE ?? 'test'
});
await postgres.execute(connection, 'DROP TABLE IF EXISTS lorem');
await postgres.execute(connection, 'CREATE TABLE lorem (info TEXT)');
await postgres.execute(connection, 'INSERT INTO lorem (info) VALUES ($1)', ['hello']);
const rows = await postgres.getAll(connection, 'SELECT * FROM lorem');
console.log(rows);
await postgres.close(connection);
}
main().catch(console.error);
Errors
Common errors & fixes
TypeError: connect is not a function
Importing from 'postgres-fp' instead of 'postgres-fp/connect'.
fixUse const connect = require('postgres-fp/connect'); Error: connect ECONNREFUSED 127.0.0.1:5432
PostgreSQL server is not running or connection parameters are wrong.
fixStart PostgreSQL service or correct host/port in connect options.
TypeError: Cannot read property 'then' of undefined
Using the promise API but not importing from 'postgres-fp/promises' (imported from 'postgres-fp/execute' which returns undefined when used without callback).
fixUse const postgres = require('postgres-fp/promises'); and call postgres.execute() etc. Audit
Dependencies
pgrequiredFoundation library for PostgreSQL connectivity
rightooptionalOptional runtime dependency for callback-based examples (not required for promises)