A simple DAO library for PostgreSQL built on postgres-gen and pg, providing basic CRUD operations with automatic marshalling between objects and tables. Current stable version is 0.18.2 (mature, infrequent releases). Key differentiators: uses promise-based query methods compatible with generators, supports object-relation mapping with automatic ID and timestamp handling, offers a ql query language for referencing multiple DAO tables in SQL, and includes upsert functionality that determines insert vs update based on record state. Minimal dependencies and simple API focused on reducing boilerplate for common patterns.
npm install postgres-gen-daoNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initialize postgres-gen-dao with a postgres-gen database connection, perform upsert, find, findOne, and delete operations.
Await the DAO promise before executing dependent queries: const books = await dao({ db, table: 'books' });Use object config: dao({ db, table: 'books' }) instead of dao('books', db).Avoid keyless tables or ensure records are unique and re-fetch before update/delete.
Explicitly use insert() or update() when the operation is known, or ensure objects have required fields (e.g., id).
Always wrap delete by query in a transaction db.transaction(...) if you need rollback capability.
Use const dao = require('postgres-gen-dao');Run npm install postgres-gen
Create the table or correct the table name in the DAO config.