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

@morphdb/adapter-postgres

v1.1.0

Published

Official PostgreSQL Adapter for MorphDB

Readme

@morphdb/adapter-postgres

Official PostgreSQL Database Adapter for MorphDB.


1. Responsibility

The @morphdb/adapter-postgres package provides the PostgreSQL storage engine adapter for MorphDB. It is responsible for:

  • Compiling abstract query AST instances into parameterized PostgreSQL SQL statements via PostgresCompiler.
  • Managing PostgreSQL connection pools using pg.Pool.
  • Handling transactional sessions with native SQL isolation levels (BEGIN, COMMIT, ROLLBACK, SAVEPOINT).
  • Exposing a driver-native escape hatch for raw SQL queries (adapter.native()).

2. Public API

export class PostgresAdapter implements DatabaseAdapter {
  readonly name: string;
  readonly capabilities: CapabilitiesSet;
  constructor(config: PoolConfig);
  connect(): Promise<void>;
  disconnect(): Promise<void>;
  execute<T>(ast: SelectQueryNode, session?: TransactionSession): Promise<QueryResult<T>>;
  beginTransaction(options?: TransactionOptions): Promise<TransactionSession>;
  native<T>(rawQuery: unknown): Promise<T>;
}

export class PostgresCompiler implements ASTVisitor<string> {
  static compile(node: SelectQueryNode): CompiledSQLStatement;
}

3. Folder Structure

adapters/postgres/
├── package.json
├── tsconfig.json
├── README.md
├── src/
│   ├── index.ts               # Barrel exports
│   ├── postgres-adapter.ts    # PostgresAdapter class
│   └── postgres-compiler.ts   # PostgresCompiler AST visitor
├── tests/
│   └── postgres.test.ts       # Vitest unit & compiler tests
├── benchmarks/
│   └── query.bench.ts         # Query AST compilation benchmarks
└── examples/
    └── index.ts              # Runnable usage example

4. Internal Components

  • PostgresCompiler: Implements ASTVisitor<string> to generate parameterized SQL strings (SELECT ... FROM ... WHERE ... = $1) with extracted parameter arrays.
  • PostgresAdapter: Manages pg.Pool connection lifecycle and transaction execution handles.

5. Interfaces

export interface CompiledSQLStatement {
  readonly sql: string;
  readonly params: ReadonlyArray<unknown>;
}

6. Dependency Graph

graph TD
    AdapterPG["@morphdb/adapter-postgres"] --> AST["@morphdb/ast"]
    AdapterPG --> SDK["@morphdb/adapter-sdk"]
    AdapterPG --> Driver["pg (node-postgres)"]

7. Extension Points

  • Postgres Custom Dialects: Extend PostgresCompiler to support PostgreSQL-specific functions (JSONB operators ->>, full-text search tsvector).

8. Design Patterns Used

  • Visitor Pattern: Implements ASTVisitor<string> for SQL statement lowering.
  • Adapter Pattern: Wraps pg.Pool to satisfy the universal DatabaseAdapter port interface.