sql-switch - v1.0.1
    Preparing search index...

    Class TableProxy

    Table-level node of the fluent chain. Returned by SchemaProxy.table.

    Index
    • Select a key within this table.

      Parameters

      • id: string

        The lookup key (e.g. guild_123).

      Returns KeyProxy

    • Stream every key in this table, in ascending id order.

      Parameters

      Returns AsyncIterableIterator<string>

      An async iterator of ids => for await (const id of table.keys()).

      Streaming on purpose (SC2): rows arrive one at a time (a cursor on SQLite, keyset-paged on Postgres), so a scan of a 100k-row table never lands the whole thing in RAM. break out of the loop early & the underlying cursor is released.

      Reads committed rows straight from the engine => a write still sitting in the collector buffer is not visible here yet (unlike KeyProxy.get, which peeks the buffer). Enumerate from a quiesced state, or await/.force() the writes you care about first, for an exact view.

      for await (const id of db.schema('antinuke').table('settings').keys({ prefix: 'guild-' })) {
      console.log(id);
      }
    • Stream every value in this table, in ascending id order.

      Type Parameters

      • T = unknown

        Expected shape of the stored values.

      Parameters

      Returns AsyncIterableIterator<T>

      An async iterator of values.

      Same streaming & buffer-visibility contract as TableProxy.keys.

    • Stream every [id, value] pair in this table, in ascending id order.

      Type Parameters

      • T = unknown

        Expected shape of the stored values.

      Parameters

      Returns AsyncIterableIterator<[string, T]>

      An async iterator of [id, value] tuples (destructure like Map entries).

      Same streaming & buffer-visibility contract as TableProxy.keys.

      for await (const [id, value] of db.schema('economy').table('balances').entries()) {
      console.log(id, value);
      }
    • Stream [id, value] pairs for every key whose id starts with prefix.

      Sugar for TableProxy.entries with { prefix }. The prefix is matched exactly & case sensitively, bound as a parameter, never as a pattern => %/_/* in it match themselves.

      Type Parameters

      • T = unknown

        Expected shape of the stored values.

      Parameters

      • prefix: string

        Exact id prefix to match.

      Returns AsyncIterableIterator<[string, T]>

      // every guild under the "guild-" namespace
      for await (const [id, settings] of table.startsWith('guild-')) { ... }
    • Count the rows in this table.

      Parameters

      Returns Promise<number>

      The row total as a plain number (counted in the database, rows are never materialized).

      Counts committed rows => same buffer-visibility caveat as TableProxy.keys.

      const guilds = await db.schema('antinuke').table('settings').count({ prefix: 'guild-' });
      
    • Delete every key in this table (or just those under a prefix).

      Parameters

      Returns Promise<void>

      Scales linearly => it lists the matching ids (streamed, so the id list is the only thing held, never the values) then deletes them one at a time through the same path as KeyProxy.delete, so a queued set() on a deleted key can't resurrect it. On a huge table that's a delete per row; it's a maintenance/reset operation, not a hot path.

      Only clears rows already committed to the engine plus their buffered copies => a brand new key still sitting unflushed in the collector (never written to disk) isn't seen by the scan. Flush first (await/.force() or close()) if you need it gone too.