Module

x/kysely_postgrs_js_dialect/mod.ts>kysely.QueryCreator#insertInto

Kysely dialect for PostgreSQL using the Postgres.js client.
Latest
method kysely.QueryCreator.prototype.insertInto
import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.4/mod.ts";
const { QueryCreator } = kysely;

Creates an insert query.

The return value of this query is an instance of InsertResult. InsertResult has the {@link InsertResult.insertId | insertId} field that holds the auto incremented id of the inserted row if the db returned one.

See the {@link InsertQueryBuilder.values | values} method for more info and examples. Also see the {@link ReturningInterface.returning | returning} method for a way to return columns on supported databases like PostgreSQL.

Examples

const result = await db
  .insertInto('person')
  .values({
    first_name: 'Jennifer',
    last_name: 'Aniston'
  })
  .executeTakeFirst()

console.log(result.insertId)

Some databases like PostgreSQL support the returning method:

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

Type Parameters

T extends keyof DB & string