PostgresAdapter (adapters/postgresql.ts)

Memori · memori-ts/src/storage/adapters/postgresql.ts · typescript · Apache-2.0
database, tag:embed-classified

PostgresAdapter implements StorageAdapter for PostgreSQL with transaction support.

// Source: https://github.com/MemoriLabs/Memori | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import type { PoolClient, Pool } from 'pg';
import { StorageAdapter, SqlBindValue } from '../base.js';
import { Registry } from '../registry.js';

function isPostgresConnection(conn: unknown): boolean {
  return (
    conn != null &&
    typeof (conn as Pool).query === 'function' &&
    typeof (conn as Pool).connect === 'function' &&
    typeof (conn as { execute?: unknown }).execute !== 'function'
  );
}

export class PostgresAdapter implements StorageAdapter {
  private readonly pool: Pool;
  private txConn: PoolClient | null = null;

  constructor(conn: unknown) {
    this.pool = con

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key