import type { ReturningAllRow, ReturningCallbackRow, ReturningRow } from '../parser/returning-parser.js'; import type { SelectCallback, SelectExpression } from '../parser/select-parser.js'; import type { Selectable } from '../util/column-type.js'; export interface ReturningInterface { /** * 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. * * Also see the {@link returningAll} method. * * ### Examples * * Return one column: * * ```ts * const { id } = await db * .insertInto('person') * .values({ * first_name: 'Jennifer', * last_name: 'Aniston' * }) * .returning('id') * .executeTakeFirstOrThrow() * ``` * * Return multiple columns: * * ```ts * const { id, last_name } = await db * .insertInto('person') * .values({ * first_name: 'Jennifer', * last_name: 'Aniston' * }) * .returning(['id', 'last_name']) * .executeTakeFirstOrThrow() * ``` * * Return arbitrary expressions: * * ```ts * import { sql } 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`concat(first_name, ' ', last_name)`.as('full_name'), * eb.selectFrom('pet').select('pet.id').limit(1).as('first_pet_id') * ]) * .executeTakeFirstOrThrow() * ``` */ returning>(selections: ReadonlyArray): ReturningInterface>; returning>(callback: CB): ReturningInterface>; returning>(selection: SE): ReturningInterface>; /** * Adds a `returning *` to an insert/update/delete/merge query on databases * that support `returning` such as PostgreSQL. * * Also see the {@link returning} method. */ returningAll(): ReturningInterface>; } export interface MultiTableReturningInterface extends ReturningInterface { /** * Adds a `returning *` or `returning table.*` to an insert/update/delete/merge * query on databases that support `returning` such as PostgreSQL. * * Also see the {@link returning} method. */ returningAll(tables: ReadonlyArray): MultiTableReturningInterface>; /** * Adds a `returning *` to an insert/update/delete/merge query on databases * that support `returning` such as PostgreSQL. * * Also see the {@link returning} method. */ returningAll(table: T): MultiTableReturningInterface>; returningAll(): ReturningInterface>; }