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

    Function first

    • Retrieves the first record matching the query for a given primary key.

      This function is useful for fetching a single record based on a primary key. It automatically routes the query to the correct shard based on the provided primary key, ensuring consistent data access.

      Type Parameters

      • T = Record<string, unknown>

        Type of the result record

      Parameters

      • key: string

        Primary key to route the query

      • sql: string

        SQL statement with parameter placeholders

      • bindings: any[] = []

        Parameter values to bind to the SQL statement

      Returns Promise<null | T>

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

      If query fails or routing fails

      type User = {
      id: string;
      name: string;
      email: string;
      };
      // Get a specific user
      const userResult = await first<User>('user-123',
      'SELECT * FROM users WHERE id = ?',
      ['user-123']
      );

      if (userResult) {
      console.log(`Found user: ${userResult.name}`);