{"id":43837,"library":"simple-postgres","title":"simple-postgres","description":"A minimal PostgreSQL interface for Node.js (v5.0.0) that eliminates boilerplate by automatically connecting via the DATABASE_URL environment variable. It provides a small set of helper functions (query, rows, row, value, column) with automatic parameterization to prevent SQL injection, and supports template string queries for readability. Simple-postgres focuses on simplicity: no ORM, no query builder, no connection pool configuration, and no initialization required. It is trusted in production and has good test coverage. Alternative to node-postgres but with a much smaller API surface.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/madd512/simple-postgres","tags":["javascript","pg","simple","postgres","postgresql","database"],"install":[{"cmd":"npm install simple-postgres","lang":"bash","label":"npm"},{"cmd":"yarn add simple-postgres","lang":"bash","label":"yarn"},{"cmd":"pnpm add simple-postgres","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"simple-postgres uses the `pg` module under the hood for all PostgreSQL connectivity.","package":"pg","optional":false}],"imports":[{"note":"simple-postgres is ESM-only since v5.0.0. CommonJS require() will error.","wrong":"const db = require('simple-postgres');","symbol":"default","correct":"import db from 'simple-postgres'"},{"note":"The default export is an object with all methods. Named imports are not available.","wrong":"import { query } from 'simple-postgres';","symbol":"query","correct":"import db from 'simple-postgres';\ndb.query(...)"},{"note":"db.identifier is a method on the default export, not a standalone named export.","wrong":"import { identifier } from 'simple-postgres';","symbol":"identifier","correct":"import db from 'simple-postgres';\ndb.identifier('table_name')"}],"quickstart":{"code":"import db from 'simple-postgres'\n\n// Ensure DATABASE_URL is set, e.g., postgres://user:pass@localhost/mydb\n// Insert a row safely\nawait db.query('INSERT INTO accounts (name) VALUES ($1)', ['ACME'])\n\n// Query rows\nlet accounts = await db.rows('SELECT * FROM accounts')\nconsole.log(accounts)\n\n// Query single row\nlet account = await db.row('SELECT * FROM accounts WHERE id = $1', [1])\nconsole.log(account.name)\n\n// Query single value\nlet count = await db.value('SELECT COUNT(*) FROM accounts')\nconsole.log(count)\n\n// Template string mode (no parentheses around backticks)\nlet type = 'pancake'\nlet result = await db.value`\n  SELECT COUNT(*)\n  FROM breakfast\n  WHERE type = ${type}\n`\nconsole.log(result)","lang":"javascript","description":"Shows basic usage: setting up, inserting, querying rows/values, and template string mode."},"warnings":[{"fix":"Use import syntax (import db from 'simple-postgres') or switch to dynamic import().","message":"simple-postgres v5.0.0 is ESM-only. CommonJS require() will throw an error.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use template literals without parentheses: db.value`SELECT ... ${var}`","message":"Do NOT use parentheses around template string literals. db.value(`SELECT ... ${var}`) treats the template as a regular string and will not properly parameterize the query, leading to SQL injection.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Explicitly add LIMIT 1 to your SQL query if you expect only one row.","message":"db.row() does not automatically add LIMIT 1. If the query returns multiple rows, only the first is returned, but no error is thrown.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set DATABASE_URL before running your application. For advanced config, consider using node-postgres directly.","message":"The DATABASE_URL environment variable is the only supported configuration. There is no support for connection pooling, custom credentials, or multiple databases.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'altern':79 'api':89 'automat':15,37 'boilerpl':13 'builder':60 'column':35 'configur':64 'connect':16,62 'coverag':78 'databas':19,96 'elimin':12 'environ':21 'focus':53 'function':30 'good':76 'helper':29 'initi':67 'inject':42 'interfac':7 'javascript':91 'minim':5 'much':87 'node':82 'node-postgr':81 'node.js':9 'orm':57 'parameter':38 'pg':92 'pool':63 'postgr':3,52,83,94 'postgresql':6,95 'prevent':40 'product':73 'provid':24 'queri':31,47,59 'readabl':49 'requir':68 'row':32,33 'set':27 'simpl':2,51,93 'simple-postgr':1,50 'simplic':55 'small':26 'smaller':88 'sql':41 'string':46 'support':44 'surfac':90 'templat':45 'test':77 'trust':71 'url':20 'v5.0.0':10 'valu':34 'variabl':22 'via':17","created_at":"2026-06-05T17:01:42.707802+00:00","updated_at":"2026-06-05T17:01:42.707802+00:00","problems":[{"fix":"Run 'npm install simple-postgres' and ensure your project uses ES modules (type: 'module' in package.json or use .mjs extension).","cause":"Module not installed or ESM-only package used via CommonJS require().","error":"Cannot find package 'simple-postgres' imported from ..."},{"fix":"Use 'import db from 'simple-postgres'' instead of 'import { query } from 'simple-postgres''.","cause":"Using named import ({ query }) instead of default import.","error":"TypeError: db.query is not a function"},{"fix":"Set the DATABASE_URL environment variable or ensure PostgreSQL is running on localhost:5432.","cause":"DATABASE_URL not set or database not running.","error":"Error: connect ECONNREFUSED 127.0.0.1:5432"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/madd512/simple-postgres#readme","github":"https://github.com/madd512/simple-postgres","docs":null,"changelog":null,"pypi":null,"npm":"simple-postgres","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}