{"id":16333,"library":"database-js-postgres","title":"PostgreSQL Wrapper for database-js","description":"database-js-postgres is a wrapper library designed to integrate PostgreSQL databases with the database-js framework. It utilizes the widely adopted node-postgres package under the hood to handle core database interactions, exposing its functionality through a consistent promise-based API, even when used independently of database-js. The library reached its latest stable version, 1.1.3, in late 2017. Given the lack of updates or commits since then, its release cadence is effectively ceased, and the project is considered unmaintained. Its primary differentiation was to provide a standardized interface within the database-js ecosystem, enabling a uniform approach to various SQL databases. However, its dependency on outdated Node.js versions and its CommonJS-only structure limit its applicability in modern JavaScript environments.","status":"abandoned","version":"1.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/mlaanderson/database-js-postgres","tags":["javascript","database-js","postgresql"],"install":[{"cmd":"npm install database-js-postgres","lang":"bash","label":"npm"},{"cmd":"yarn add database-js-postgres","lang":"bash","label":"yarn"},{"cmd":"pnpm add database-js-postgres","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core underlying PostgreSQL driver","package":"node-postgres","optional":false},{"reason":"Parent framework it's designed to integrate with (often imported as 'database-js2' in examples, likely referring to a specific version or alias)","package":"database-js","optional":false}],"imports":[{"note":"Package is CommonJS-only; direct ESM import is not supported.","wrong":"import postgres from 'database-js-postgres';","symbol":"postgres","correct":"const postgres = require('database-js-postgres');"},{"note":"When using with database-js, the Connection class is imported from 'database-js2' as shown in the original documentation. This is a CommonJS require.","wrong":"import { Connection } from 'database-js2';","symbol":"Connection","correct":"const Database = require('database-js2').Connection;"},{"note":"The `open` method for standalone usage is accessed via the default export of the package, not a named export. Requires CommonJS.","wrong":"import { open } from 'database-js-postgres';\nconst connection = open({ ... });","symbol":"Connection (standalone)","correct":"const postgres = require('database-js-postgres');\nconst connection = postgres.open({ ... });"}],"quickstart":{"code":"const postgres = require('database-js-postgres');\n\n(async () => {\n    let connection, rows;\n\n    // Establish a connection to the PostgreSQL database\n    connection = postgres.open({\n        Hostname: 'localhost',\n        Port: 5432,\n        Username: 'my_secret_username',\n        Password: 'my_secret_password',\n        Database: 'my_top_secret_database'\n    });\n    \n    try {\n        // Execute a query and fetch results\n        rows = await connection.query(\"SELECT id, name FROM users WHERE email = ?\", ['example@email.com']);\n        console.log('Query Results:', rows);\n\n        // Example of an insert statement\n        const insertResult = await connection.query(\"INSERT INTO logs (message) VALUES (?) RETURNING id\", ['User logged in successfully']);\n        console.log('Insert Result:', insertResult);\n\n    } catch (error) {\n        console.error('Database Operation Error:', error);\n    } finally {\n        // Always ensure the connection is closed\n        await connection.close();\n        console.log('Connection closed.');\n    }\n})();","lang":"javascript","description":"Demonstrates connecting to a PostgreSQL database, executing a SELECT query with parameters, performing an INSERT operation, and properly closing the connection using the standalone promise-based API."},"warnings":[{"fix":"Migrate to a currently maintained PostgreSQL driver like `node-postgres` directly or a well-supported ORM/query builder.","message":"The package `database-js-postgres` has been abandoned since late 2017. It no longer receives updates, bug fixes, or security patches. Using it in production is highly discouraged.","severity":"breaking","affected_versions":">=1.1.3"},{"fix":"Avoid using this package with modern Node.js versions. If forced to use, thorough testing is required, but migration is the recommended path.","message":"The documentation specifies a prerequisite of 'NodeJS >= 6.0'. Modern Node.js versions are not guaranteed to be compatible, and using such an old Node.js version is a significant security risk.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use CommonJS `require()` syntax for all imports. For projects requiring ESM, consider alternative, actively maintained libraries.","message":"This package is CommonJS-only and does not support ES Modules (ESM) syntax (`import/export`). Attempting to use ESM will result in errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Verify your `package.json` dependencies and import paths to match the documented `require('database-js2').Connection;` if integrating with the parent framework.","message":"When used with `database-js`, the README explicitly imports from `database-js2`. Ensure the correct package (`database-js` or `database-js2`) is installed and matched to the example's usage, as this can be a source of confusion.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Verify that your PostgreSQL server is running, listening on the specified host and port (default 5432), and that no firewall is blocking the connection.","cause":"The PostgreSQL server is not running, is not accessible from the application's host, or the specified port is incorrect.","error":"Error: connect ECONNREFUSED"},{"fix":"Double-check the username and password in your connection string. Consult your PostgreSQL server's `pg_hba.conf` file to ensure the client IP address and user are permitted to connect with password authentication (e.g., `md5`, `scram-sha-256`).","cause":"Incorrect username or password, or the PostgreSQL server's `pg_hba.conf` configuration does not allow the specified authentication method for the user/database.","error":"Error: password authentication failed for user \"my_secret_username\""},{"fix":"Run `npm install database-js-postgres` in your project directory to install the package.","cause":"The package is not installed or `npm install` was not run.","error":"Cannot find module 'database-js-postgres'"}],"ecosystem":"npm"}