Setu-TS
    Preparing search index...

    Interface IDatabaseAdapter

    The full database backend port: lifecycle plus data access.

    This is the seam an application implements to plug a database the framework does not ship an adapter for, and hand it to DatabasePlugin({ type: 'custom', adapter }). It lives in common rather than inside the database plugin precisely so a backend can be written in another package — cloudflare-plugin's D1Adapter is the first.

    migrate() is deliberately absent: programmatic migration is not honestly implementable across the supported backends, and every one of them owns migrations through its own CLI.

    class MyAdapter implements IDatabaseAdapter {
    connect(): Promise<void> { return Promise.resolve(); }
    disconnect(): Promise<void> { return Promise.resolve(); }
    isReady(): boolean { return true; }
    createDataSource(entity: string): IDataSource { return makeSource(entity); }
    transactionIsolationLevels = ['serializable'] as const;
    beginTransaction(options?: TransactionOptions): Promise<IAdapterTransaction> {
    return openTx(options);
    }
    rawQuery<T>(sql: string, params?: unknown[]): Promise<T[]> { return run(sql, params); }
    }

    0.2.0

    interface IDatabaseAdapter {
        transactionIsolationLevels?: readonly TransactionIsolationLevel[];
        beginTransaction(
            options?: TransactionOptions,
        ): Promise<IAdapterTransaction>;
        connect(): Promise<void>;
        createDataSource(entity: string): IDataSource;
        disconnect(): Promise<void>;
        isHealthy?(): Promise<boolean>;
        isReady(): boolean;
        rawQuery<T>(sql: string, params?: unknown[]): Promise<T[]>;
    }

    Hierarchy (View Summary)

    Implemented by

    Index
    transactionIsolationLevels?: readonly TransactionIsolationLevel[]

    The portable isolation levels this adapter honours.

    • Reports whether the backend answers right now (optional, M95b).

      isReady() — the lifecycle member this interface inherits — reports that connect() once succeeded; it says nothing about the backend now, and a probe built on it reports up for a database that has been dead for minutes (X51-1). This member is the liveness read the lifecycle read was mistaken for. true — the backend answered; false — it was contacted and refused or failed; a rejection reports as "could not determine". An adapter that cannot probe honestly OMITS the member: a probe that was never written is evidence of nothing, and the DatabaseService reports its absence rather than inventing an answer. Optional on the fs?/workers?/dns? precedent, so an out-of-repo adapter without it is unaffected.

      An implementation SHOULD answer false once it has been disconnected, rather than reporting on a connection it no longer holds. The health indicator gates this probe behind the lifecycle read as well, so a probe that forgets to is not a readiness defect — but this member is also read directly through DatabaseService.reachability(), where nothing else is watching.

      Returns Promise<boolean>

      true when the backend answered, false when it did not

    • Execute a raw query in the backend's own dialect.

      Type Parameters

      • T

        Expected row shape

      Parameters

      • sql: string

        The query text

      • Optionalparams: unknown[]

        Positional parameters

      Returns Promise<T[]>

      The result rows