Registry / database / postgres-fp

postgres-fp

JSON →
library1.4.1jsnpmunverified

A functional programming wrapper around the postgres npm module, providing curried functions for connecting, executing queries, and retrieving results. Current stable version 1.4.1 (last updated in 2021) with a low release cadence. Supports both callback-based (compatible with righto) and promise-based APIs. Key differentiator: offers a purely functional interface over pg, unlike traditional object-oriented drivers. Includes functions like connect, execute, getAll, getOne, insert, and close. Note: not actively maintained; consider using pg directly with a functional helper library.

npm install postgres-fp
INSTALL
IMPORT
SIG · POSTGRES-FP
P
postgres-fp
databasejavascriptv1.4.1
harness data pending
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);
Debug
Known issues
deprecatedThe package has not been updated since 2021. It may not work with newer versions of pg or Node.js.
fix
Consider migrating to pg directly or using a modern functional wrapper like slonik or postgres.js.
affects: >=1.4.1
gotchaMissing error handling: functions do not throw by default; they return null or undefined on failure if not using promises correctly.
fix
Always use try/catch with the promise API or handle error in callbacks.
affects: >=1.0.0
gotchaThe promise API (postgres-fp/promises) is undocumented and may have different signatures than the callback API.
fix
Check the source code for exact promise signatures; use the callback API for stability.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: connect is not a function
Importing from 'postgres-fp' instead of 'postgres-fp/connect'.
fix
Use const connect = require('postgres-fp/connect');
Error: connect ECONNREFUSED 127.0.0.1:5432
PostgreSQL server is not running or connection parameters are wrong.
fix
Start 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).
fix
Use const postgres = require('postgres-fp/promises'); and call postgres.execute() etc.
Upgrade
Version history
1.4.1latest on npm
Audit
Dependencies
pgrequiredFoundation library for PostgreSQL connectivity
rightooptionalOptional runtime dependency for callback-based examples (not required for promises)
Agent activity
6 hits · last 30 days
node
6
Resources
postgres-fp — npm install postgres-fp · libregistry