Machinepack PostgreSQL

raw JSON →
4.0.2 verified Sat Apr 25 auth: no javascript maintenance

Structured Node.js bindings for connecting to and running queries against a PostgreSQL database. Version 4.0.2 is the latest stable release. It is part of the Sails.js ecosystem and implements the Waterline Driver Interface. Release cadence is irregular; primarily maintained for legacy Sails applications. Key differentiators: uses machine definitions for structured operations, integrates with Sails' Waterline ORM, wraps the `pg` driver. Unmaintained since 2017; prefer `pg` directly or newer Waterline adapters.

error Error: connect ECONNREFUSED 127.0.0.1:5432
cause PostgreSQL server is not running or not accessible at the specified host/port.
fix
Ensure PostgreSQL is running: sudo service postgresql start (Linux) or brew services start postgresql (macOS).
error error: password authentication failed for user "postgres"
cause Incorrect password or missing pg_hba.conf configuration.
fix
Set correct password in connection or configure pg_hba.conf to allow trust for local connections.
error TypeError: MPPostgresql.getConnection is not a function
cause Importing the module incorrectly, e.g., using named import or destructuring.
fix
Use const MPPostgresql = require('machinepack-postgresql'); then call MPPostgresql.getConnection(...).
deprecated This package is no longer actively maintained. Use the 'pg' package directly or a modern Waterline adapter like 'sails-postgresql'.
fix Migrate to 'pg' (npm install pg) or 'sails-postgresql' for Sails apps.
gotcha The connection object must be released manually. Forgetting to release can exhaust connection pool.
fix Always call MPPostgresql.releaseConnection() after queries, or use a connection pool wrapper.
gotcha All method calls use the machinepack pattern with .exec(), not Promises. This is unlike many modern Node.js libraries.
fix Call .exec() with callback or error/success exits. Alternatively, promisify with util.promisify.
gotcha The package wraps 'pg' but exposes a different API. Direct 'pg' configuration options may not be passed through.
fix Check the Waterline Driver Interface for supported options; use 'pg' directly for advanced features.
npm install machinepack-postgresql
yarn add machinepack-postgresql
pnpm add machinepack-postgresql

Connects to a PostgreSQL database, runs a SELECT query, and releases the connection using machinepack-postgresql's structured bindings.

var MPPostgresql = require('machinepack-postgresql');

// Get a connection
MPPostgresql.getConnection({
  host: 'localhost',
  port: 5432,
  user: 'postgres',
  password: process.env.PGPASSWORD || '',
  database: 'mydb'
}).exec({
  error: function(err) { console.log('Error:', err); },
  success: function(connection) {
    // Send a query
    MPPostgresql.sendQuery({
      connection: connection,
      query: 'SELECT * FROM users LIMIT 1'
    }).exec({
      error: function(err) { console.log('Query error:', err); },
      success: function(result) {
        console.log('Result:', result);
        MPPostgresql.releaseConnection({ connection: connection }).exec();
      }
    });
  }
});