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

    Function insert

    • Executes an insert on an automatically selected shard and returns the generated primary key.

      This is the default helper for generated-key tables. CollegeDB picks a shard using the configured allocation strategy, then stores the generated primary key -> shard mapping so routed reads can find the row later.

      Type Parameters

      • T = Record<string, unknown>

        Type of returned rows when the insert uses RETURNING

      Parameters

      • sql: string

        The INSERT statement to execute

      • bindings: any[] = []

        Parameter values to bind to the statement

      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

      1.1.4

      const created = await insert(
      'INSERT INTO auto_users (name, email) VALUES (?, ?)',
      ['Ada', 'ada@example.com']
      );

      const row = await first(String(created.generatedId), 'SELECT * FROM auto_users WHERE id = ?', [created.generatedId]);