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

    Function firstShard

    • Bypasses the normal routing logic to execute a query directly on a specified shard. This is useful for administrative operations, cross-shard queries, or when you need to query data that doesn't follow the primary key routing pattern.

      Use with caution: This function bypasses routing safeguards and should be used only when you specifically need to target a particular shard.

      Type Parameters

      • T = Record<string, unknown>

      Parameters

      • shardBinding: string

        The shard binding name to execute the query on

      • sql: string

        SQL statement to execute

      • bindings: any[] = []

        Parameter values to bind to the SQL statement

      Returns Promise<null | T>

      Promise resolving to the first matching record, or null if not found

      If shard not found or query fails

      // Administrative query: get a specific user from a shard
      const user = await firstShard('db-east',
      'SELECT * FROM users WHERE id = ?',
      ['user-123']);
      if (user) {
      console.log(`Found user: ${user.name}`);
      } else {
      console.log('User not found in east shard');
      }