Skip to main content

Kysely

The main Kysely class for interacting with your database. You should create one instance of Kysely per database using the constructor. Each Kysely instance maintains its own connection pool.

Constructor

config
KyselyConfig
required
Configuration object for Kysely instance

Example

Properties

schema

Returns the SchemaModule for building database schema. Example:

dynamic

Returns the DynamicModule for bypassing strict typing and passing dynamic values. Example:

introspection

Returns a database introspector for examining database structure.

fn

Returns a FunctionModule for building SQL function calls. Example:

isTransaction

Returns true if this Kysely instance is a transaction. You can also use db instanceof Transaction.

Methods

selectFrom

Creates a select query builder for the given table(s). Inherited from QueryCreator. See SelectQueryBuilder for available methods.

insertInto

Creates an insert query builder for the given table. See InsertQueryBuilder for available methods.

updateTable

Creates an update query builder for the given table(s). See UpdateQueryBuilder for available methods.

deleteFrom

Creates a delete query builder for the given table(s). See DeleteQueryBuilder for available methods.

transaction

Creates a TransactionBuilder for running queries inside a transaction. The callback function passed to execute() gets the transaction object as its only argument. If the function throws, the transaction is rolled back. Otherwise it’s committed. Example:
Setting isolation level:

startTransaction

Creates a ControlledTransactionBuilder for manually controlled transactions. Returns a ControlledTransaction that allows manual commit/rollback and savepoint operations. Example:

connection

Provides a kysely instance bound to a single database connection. Example:

case

Creates a case statement/operator. See ExpressionBuilder.case for more information.

withPlugin

Returns a copy of this Kysely instance with the given plugin installed.

withoutPlugins

Returns a copy of this Kysely instance without any plugins.

withSchema

Returns a copy of this Kysely instance with a schema prefix for all queries.

withTables

Returns a copy of this Kysely instance with tables added to its database type. This method only modifies the types and doesn’t affect executed queries. Example:

executeQuery

Executes a given compiled query or query builder. See the splitting build, compile and execute recipe for more information.

destroy

Releases all resources and disconnects from the database. You need to call this when you are done using the Kysely instance. Example: