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

    Function discoverExistingPrimaryKeys

    • Scans an existing table to find all primary keys that need to be mapped to shards. This is useful when integrating CollegeDB with an existing database that already contains data. The function assumes the table has an 'id' column as the primary key.

      Parameters

      • d1: D1Database

        The D1 database instance to scan

      • tableName: string

        Name of the table to discover primary keys from

      • primaryKeyColumn: string = 'id'

        Name of the primary key column (defaults to 'id')

      Returns Promise<string[]>

      Promise resolving to array of primary key values

      If table doesn't exist or database query fails

      // Discover all user IDs in an existing users table
      const userIds = await discoverExistingPrimaryKeys(env.DB_EXISTING, 'users');
      console.log(`Found ${userIds.length} existing users`);

      // Discover with custom primary key column
      const orderIds = await discoverExistingPrimaryKeys(env.DB_ORDERS, 'orders', 'order_id');