npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

postgres-adapter

v0.0.2

Published

postgres

Readme

postgres-adapter

A high-performance PostgreSQL toolkit for Node.js built on top of the official pg driver.

postgres-adapter is the PostgreSQL adapter for the sql-core ecosystem. It provides execution utilities, repositories, batch processing, stream processing, health checks, and PostgreSQL-specific implementations while reusing the database-independent abstractions from sql-core.

Example

Features

  • Built on the official pg driver
  • Reuses Repository and CRUDRepository from sql-core
  • Works seamlessly with query-mappers
  • Metadata-driven CRUD operations
  • Batch insert and update
  • Stream processing for large datasets
  • Optimistic locking
  • Transaction support
  • PostgreSQL health check for Kubernetes
  • TypeScript first
  • Lightweight with no ORM

Installation

npm install postgres-adapter

or together with the ecosystem:

npm install sql-core query-mappers postgres-adapter

Why postgres-adapter?

Most SQL libraries are either:

  • Low-level drivers (pg)
  • Full-featured ORMs (TypeORM, Prisma, Sequelize)

This library focuses on infrastructure.

It provides:

  • Connection management
  • Transactions
  • Repository integration
  • Batch execution
  • Streaming

without hiding SQL from developers.

Moreover, postgres-adapter can work with sql-core and query-mappers. They separate responsibilities into independent layers.

This architecture keeps applications lightweight, modular, and easy to maintain.

Ecosystem

                    Application
                          │
            ┌─────────────┴─────────────┐
            │                           │
            ▼                           ▼
       Repository                 CRUDRepository
       (sql-core)
            │
            ▼
      query-mappers
            │
            ▼
      postgres-adapter
            │
            ▼
       PostgreSQL

Responsibilities

| Package | Responsibility | | ------------- | --------------------------------------------------------------------- | | sql-core | Database-independent repositories, CRUD, SQL builders, transactions | | query-mappers | Maps database rows to TypeScript models | | postgres-adapter | PostgreSQL execution, repositories, writers, streaming, health checks |


Core Components

PostgreSQL Execution

Execute SQL statements using PostgreSQL.

  • Transaction support
  • Query execution
  • Command execution
  • Prepared statements

Transactions

const tx = await db.beginTransaction()

try {
    await tx.execute(
        `INSERT INTO users(name) VALUES($1)`,
        ["John"]
    )
    await tx.commit()
}
catch (err) {
    await tx.rollback()
}

Query

Rows are automatically mapped into TypeScript objects.

interface User {

    id: number

    name: string

    active: boolean

}
const users = await db.query<User>(sql)

Automatically converts database values.

0  -> false

1  -> true

NULL -> null

Execute

await db.execute(
    `UPDATE users SET active = $1 WHERE id = $2`
    [true, 10]
)

Batch Execution

await db.executeBatch([
    {
        query: "INSERT INTO users(name) VALUES($1)",
        params: ["John"]
    },
    {
        query: "INSERT INTO users(name) VALUES($1)",
        params: ["Jane"]
    }
])

Repository

postgres-adapter provides PostgreSQL implementations that reuse the generic repositories fromsql-core.

Features include:

  • Create
  • Update
  • Delete
  • Find by id
  • Search
  • Paging
  • Sorting
  • Optimistic locking

Batch Processing

Efficiently execute multiple operations.

Suitable for:

  • Data migration
  • Import jobs
  • Synchronization
  • ETL

Writer

Insert data efficiently.

const writer = new PostgreSQLWriter(pool)

await writer.write(users)

Batch Writer

const writer = new PostgreSQLBatchWriter(pool)

await writer.write(users)

Stream Processing

Designed for processing very large datasets without loading everything into memory.

Typical use cases:

  • CSV import
  • Excel import
  • Background jobs
  • Large database synchronization

Stream Writer

const writer = new PostgreSQLStreamWriter(pool)

await writer.write(user)

Health Check

Built-in PostgreSQL health checker.

Designed for cloud-native deployments.

Features:

  • Connection validation
  • Query validation
  • Response time measurement
  • Configurable timeout
  • Kubernetes readiness and liveness probes

Example:

const checker = new PostgreSQLChecker(pool);

const result = await checker.check();

Metadata-driven Persistence

CRUD operations are generated from metadata instead of handwritten SQL.

Supports:

  • Primary keys
  • Version fields
  • Read-only fields
  • Insert-only fields
  • Update-only fields
  • Automatic SQL generation

Optimistic Locking

Version columns are automatically detected from metadata.

No additional repository code is required.

Transactions

Supports PostgreSQL transactions using the abstractions defined in sql-core.

Begin Transaction

       ↓

Execute Commands

       ↓

Commit / Rollback

Integration with query-mappers

query-mappers converts PostgreSQL rows into strongly typed TypeScript models.

PostgreSQL Row

       ↓

 query-mappers

       ↓

TypeScript Object

Designed for Enterprise Applications

postgres-adapter is suitable for:

  • REST APIs
  • Microservices
  • Batch processing
  • ETL pipelines
  • Event-driven systems
  • Cloud-native applications

Advantages

  • No ORM overhead
  • Reusable repositories
  • Modular architecture
  • High performance
  • Strong TypeScript support
  • Easy to test
  • Clean separation of responsibilities

Related Packages

  • sql-core — Common SQL abstractions, repositories, CRUD, and SQL builders.
  • query-mappers — Object mapping between SQL rows and TypeScript models.
  • mysql2-core — MySQL adapter built on top of mysql2.

License

MIT