Function withChangeEvents

  • The adapter, reporting each write made through it: an INSERT (REPLACE and upserts included), UPDATE, DELETE or TRUNCATE, through run(), get(), all(), exec(), batch(), transaction() and, on PostgreSQL, withConnection(). A write is reported once it commits: at once outside a transaction, when transaction() commits inside one, and not at all when it rolls back.

    The changes are those made through this adapter: another adapter, another process, or a transaction begun with BEGIN through run() (reported as its statements run) is outside it. On PostgreSQL, listen() and the dialect's changeNotificationSql report writes from every session.

    A listener that throws is logged through the host logger, and the write goes on.

    Type Parameters

    Parameters

    • adapter: A

    Returns A & ChangeEvents

    const db = withChangeEvents(await createDatabase());
    const stop = db.onChange((change) => cache.invalidate(change.table), { tables: ['notes'] });