Use createPostgresAdapter from @framers/sql-storage-adapter/postgres with the Supabase connection string.

Implements

Constructors

Properties

kind: "supabase-postgres" = 'supabase-postgres'

Identifier for logging/diagnostics (e.g., 'better-sqlite3', 'postgres').

capabilities: ReadonlySet<StorageCapability> = ...

Capability flags indicating supported features.

Methods

  • Opens the underlying connection or initializes the backing store.

    Parameters

    Returns Promise<void>

    If connection cannot be established

    await adapter.open({ filePath: '/path/to/db.sqlite3' });
    
  • Closes the underlying connection and releases resources.

    After calling close(), the adapter should not be used again. Always close adapters when done to prevent resource leaks.

    Returns Promise<void>

    try {
    await adapter.open();
    // ... use adapter ...
    } finally {
    await adapter.close();
    }
  • Executes a mutation statement (INSERT, UPDATE, DELETE).

    Parameters

    • statement: string

      SQL statement to execute

    • Optionalparameters: StorageParameters

      Optional parameters for the statement

    Returns Promise<StorageRunResult>

    Metadata about affected rows

    If statement execution fails

    const result = await adapter.run('INSERT INTO users (name) VALUES (?)', ['John']);
    console.log(`Inserted with ID: ${result.lastInsertRowid}`);
  • Retrieves a single row (or null if none found).

    Type Parameters

    • T = unknown

    Parameters

    • statement: string

      SQL SELECT statement

    • Optionalparameters: StorageParameters

      Optional parameters for the statement

    Returns Promise<null | T>

    First row or null if no results

    If query execution fails

    const user = await adapter.get<User>('SELECT * FROM users WHERE id = ?', [123]);
    
  • Retrieves all rows returned by the statement.

    WARNING: For large result sets, this loads everything into memory. Consider using streaming (if supported) for large queries.

    Type Parameters

    • T = unknown

    Parameters

    • statement: string

      SQL SELECT statement

    • Optionalparameters: StorageParameters

      Optional parameters for the statement

    Returns Promise<T[]>

    Array of all matching rows (empty array if none)

    If query execution fails

    const users = await adapter.all<User>('SELECT * FROM users WHERE age > ?', [18]);
    
  • Executes a script containing multiple SQL statements.

    Statements are typically delimited by semicolons. This is useful for running migrations or initialization scripts. No results are returned.

    Parameters

    • script: string

      SQL script with multiple statements

    Returns Promise<void>

    If any statement in the script fails

    await adapter.exec(`
    CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);
    CREATE INDEX idx_users_name ON users(name);
    `);
  • Runs fn in a transaction on one pooled client: COMMIT when it resolves, ROLLBACK when it or COMMIT throws, and that error is thrown. A COMMIT that PostgreSQL answers with ROLLBACK, as it answers one when a statement in the transaction failed and fn went on, throws too, as nothing was written. When the ROLLBACK cannot run either, the error thrown is still the transaction's own, with the ROLLBACK's on it as rollbackError, and the client goes back to the pool closed, as it does when its connection failed, since it could still be inside the transaction.

    Type Parameters

    • T

    Parameters

    Returns Promise<T>

  • Writes the operations in one transaction, each under a savepoint: a failed statement aborts a PostgreSQL transaction, so a failed operation rolls back to its savepoint and the batch goes on, as the PostgreSQL adapter's batch does. The operations that succeeded commit, and the result names each one that failed by its index, one whose values could not be read (a getter or a proxy that throws) among them. An operation of a type the batch does not know writes nothing and is not counted.

    Parameters

    Returns Promise<BatchResult>

  • Keeps the answers of SELECTs through get and all, at most maxSize of them, and answers the same statement with the same parameters from them, each time with a copy, so a caller that changes the row or list it was given changes nothing the cache answers next. An answer holding a value with no faithful copy, such as an interval, which pg parses to an object of its own, is not kept. A SELECT is a statement whose first word, past white space and comments (a -- comment ends at a line feed or a carriage return), is SELECT; a string of several statements counts as a write. One the cache does not hold runs once, in a transaction of its own, and its answer is kept only when PostgreSQL gave that transaction no ID, which it gives a transaction when it first writes to the database: a SELECT that calls a function that writes, or makes a table with INTO, runs each time it is asked. That check reads pg_current_xact_id_if_assigned(), so the cache needs PostgreSQL 13 or later. A SELECT the cache may keep is sent its values as pg's own prepareValue writes them when the call is made, so its answer is the answer to those values whatever the caller changes afterwards, and two calls share an answer only when they send the same statement and the same values; with pg before 8.15.0, which does not export prepareValue, a SELECT with parameters runs each time it is asked. Every statement that writes, through run, exec, get or all, and every transaction, batchWrite and migrate, clears the cache when it ends, and a read that was in flight across one keeps nothing, so the cache never answers a row as it stood before this adapter's own write. It cannot see a write through another adapter, pool or process, an effect that writes no row, such as pg_notify() or an advisory lock, nor a SELECT whose answer changes from one call to the next by itself, such as one that calls random(), now() or nextval(): a kept answer is given again without running the statement, until clearCache(). Run a statement wanted for its effect through run, or begin it with a word other than SELECT, such as VALUES (nextval('ids')), which runs each time.

    Parameters

    • maxSize: number = 100

    Returns void

  • Returns {
        active: number;
        idle: number;
        waiting: number;
        max: number;
    }

    • active: number
    • idle: number
    • waiting: number
    • max: number