kysely
    Preparing search index...

    Interface ReturningInterface<DB, TB, O>

    interface ReturningInterface<DB, TB extends keyof DB, O> {
        returning<
            SE extends
                | string
                | AliasedExpression<any, any>
                | DynamicReferenceBuilder<any>
                | AliasedExpressionFactory<DB, TB>,
        >(
            selections: readonly SE[],
        ): ReturningInterface<DB, TB, ReturningRow<DB, TB, O, SE>>;
        returning<CB extends SelectCallback<DB, TB>>(
            callback: CB,
        ): ReturningInterface<DB, TB, ReturningCallbackRow<DB, TB, O, CB>>;
        returning<
            SE extends
                | string
                | AliasedExpression<any, any>
                | DynamicReferenceBuilder<any>
                | AliasedExpressionFactory<DB, TB>,
        >(
            selection: SE,
        ): ReturningInterface<DB, TB, ReturningRow<DB, TB, O, SE>>;
        returningAll(): ReturningInterface<DB, TB, Selectable<DB[TB]>>;
    }

    Type Parameters

    • DB
    • TB extends keyof DB
    • O

    Hierarchy (View Summary)

    Implemented by

    Index

    Methods

    • Allows you to return data from modified rows.

      On supported databases like PostgreSQL, this method can be chained to insert, update, delete and merge queries to return data.

      Note that on SQLite you need to give aliases for the expressions to avoid this bug in SQLite. For example .returning('id as id').

      Also see the returningAll method.

      Return one column:

      const { id } = await db
      .insertInto('person')
      .values({
      first_name: 'Jennifer',
      last_name: 'Aniston'
      })
      .returning('id')
      .executeTakeFirstOrThrow()

      Return multiple columns:

      const { id, last_name } = await db
      .insertInto('person')
      .values({
      first_name: 'Jennifer',
      last_name: 'Aniston'
      })
      .returning(['id', 'last_name'])
      .executeTakeFirstOrThrow()

      Return arbitrary expressions:

      importsql } from 'kysely'

      const { id, full_name, first_pet_id } = await db
      .insertInto('person')
      .values({
      first_name: 'Jennifer',
      last_name: 'Aniston'
      })
      .returning((eb) => [
      'id as id',
      sql<string>`concat(first_name, ' ', last_name)`.as('full_name'),
      eb.selectFrom('pet').select('pet.id').limit(1).as('first_pet_id')
      ])
      .executeTakeFirstOrThrow()

      Type Parameters

      • SE extends
            | string
            | AliasedExpression<any, any>
            | DynamicReferenceBuilder<any>
            | AliasedExpressionFactory<DB, TB>

      Parameters

      • selections: readonly SE[]

      Returns ReturningInterface<DB, TB, ReturningRow<DB, TB, O, SE>>

    • Type Parameters

      Parameters

      • callback: CB

      Returns ReturningInterface<DB, TB, ReturningCallbackRow<DB, TB, O, CB>>

    • Type Parameters

      • SE extends
            | string
            | AliasedExpression<any, any>
            | DynamicReferenceBuilder<any>
            | AliasedExpressionFactory<DB, TB>

      Parameters

      • selection: SE

      Returns ReturningInterface<DB, TB, ReturningRow<DB, TB, O, SE>>