Registry / database / postgres-driver-service

postgres-driver-service

JSON →
library2.1.1jsnpmunverified

Postgres Driver Service v2.1.1 is a lightweight Node.js library that abstracts raw SQL queries into an automated service layer. It wraps the node-postgres (pg) Pool and provides methods like `find`, `insert`, `update`, and `delete` for common CRUD operations without writing SQL. Designed for fast prototyping and small-to-medium projects where full ORMs like Sequelize or TypeORM are overkill. The package ships TypeScript definitions, has a simple constructor, and follows a service-object pattern. Release cadence is irregular; last update in 2020. Key differentiator: automatic query generation from config objects, but lacks advanced features like migrations, connection pooling beyond pg, or SQL injection protections beyond parameterized queries.

npm install postgres-driver-service
INSTALL
IMPORT
SIG · POSTGRES-DRIVER-SE
P
postgres-driver-service
databasejavascriptv2.1.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.

DriverService
import { DriverService } from 'postgres-driver-service'
const DriverService = require('postgres-driver-service')
Named import, not default. Works in both CJS and ESM.
DriverService
const { DriverService } = require('postgres-driver-service')
const DriverService = require('postgres-driver-service').default
CJS destructured import is correct. Do not use .default.
type DriverService
import type { DriverService } from 'postgres-driver-service'
import { DriverServiceType } from 'postgres-driver-service'
For TypeScript type imports, use `import type` with the class name.

Initializes a pg Pool, creates a DriverService, and performs a simple insert and find operation without writing SQL.

import { Pool } from 'pg'; import { DriverService } from 'postgres-driver-service'; const pool = new Pool({ host: process.env.PGHOST ?? 'localhost', port: Number(process.env.PGPORT) || 5432, database: process.env.PGDATABASE ?? 'mydb', user: process.env.PGUSER ?? 'postgres', password: process.env.PGPASSWORD ?? '', }); const ds = new DriverService(pool); async function main() { // Insert a user const newUser = await ds.insert('users', { name: 'Alice', email: 'alice@example.com' }); console.log('Inserted:', newUser); // Find users const users = await ds.find('users', { name: 'Alice' }); console.log('Found:', users); await pool.end(); } main().catch(console.error);
Debug
Known issues
gotchaDriverService does not escape column/table names. Using user-provided strings for table names can lead to SQL injection.
fix
Always validate or whitelist table/column names before passing to DriverService methods.
affects: >=0.0.0
gotchaThe `find` method returns the entire result set as an array; there is no built-in pagination. For large tables, this can cause memory issues.
fix
Use custom SQL with LIMIT/OFFSET or query within your own pagination logic.
affects: >=0.0.0
deprecatedThe package has not been updated since 2020. It depends on older patterns and may lack support for newer pg features.
fix
Consider migrating to Knex.js or TypeORM for active maintenance.
affects: >=2.0.0
gotchaThe `insert` method requires an object with column-value pairs; if you pass an empty object, it will generate invalid SQL.
fix
Always ensure the data object has at least one key before calling insert.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: DriverService is not a constructor
Used default import instead of named import: `import DriverService from 'postgres-driver-service'`
fix
Use named import: `import { DriverService } from 'postgres-driver-service'`
Cannot find module 'pg'
Missing peer dependency 'pg'.
fix
Run `npm install pg`
TypeError: pool.query is not a function
Passed a single PoolClient instead of a Pool instance to DriverService constructor.
fix
Ensure you create a Pool using `new Pool()` and pass it to DriverService.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies
pgrequiredPeer dependency; required to create the Pool instance passed to DriverService.
Agent activity
7 hits · last 30 days
node
6
Resources
postgres-driver-service — npm install postgres-driver-service · libregistry