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

    Function insertShard

    • Executes an insert directly on a named shard and returns the generated primary key.

      Use this helper when you already know the shard you want to target. The helper still captures the generated id and stores the mapping so routed reads can find the new row later.

      Throws GENERATED_KEY_COLLISION when another shard already owns the generated id. Cleanup of the row the refused INSERT wrote works as in insert: pass options.table to have it deleted, otherwise it is the caller's to remove.

      Type Parameters

      • T = Record<string, unknown>

        Type of returned rows when the insert uses RETURNING

      Parameters

      • shardBinding: string

        The shard binding to execute the insert on

      • sql: string

        The INSERT statement to execute

      • bindings: any[] = []

        Parameter values to bind to the statement

      • options: InsertOptions = {}

        idColumn names the generated key column, table enables cleanup of a refused row

      Returns Promise<InsertResult<T>>

      Promise resolving to the write result plus the generated id

      If the insert succeeds but no generated id can be determined

      GENERATED_KEY_COLLISION when another shard already owns the generated id

      1.1.4

      const created = await insertShard('db-east',
      'INSERT INTO auto_users (name, email, created_at) VALUES (?, ?, ?)',
      ['Ada', 'ada@example.com', Date.now()]
      );

      console.log(created.generatedId);
      const created = await insertShard('db-east',
      'INSERT INTO auto_users (name, email) VALUES (?, ?) RETURNING id',
      ['Ada', 'ada@example.com']
      );