@earth-app/collegedb
    Preparing search index...

    Function firstByLookupKey

    • Retrieves the first record using a secondary lookup key when available.

      This helper avoids creating new primary-key mappings for secondary identifiers. It first checks KV for a lookup-key mapping and queries that shard directly. If no mapping exists (or the mapping is stale), it falls back to fanout (firstAllShards) and returns the first non-null result.

      Type Parameters

      • T = Record<string, unknown>

        Type of the result record

      Parameters

      • lookupKey: string

        Secondary key such as email:user@example.com or username:alice

      • sql: string

        SQL statement to execute

      • bindings: any[] = []

        Parameter values to bind to the SQL statement

      • batchSize: number = 50

        Number of concurrent shard queries during fanout (default: 50)

      Returns Promise<T | null>

      Promise resolving to the first matching record, or null

      1.1.4