Interface Expression<T>

Expression represents an arbitrary SQL expression with a type.

Most Kysely methods accept instances of Expression and most classes like SelectQueryBuilder and the return value of the sql template tag implement it.

const exp1: Expression<string> = sql<string>`CONCAT('hello', ' ', 'world')`
const exp2: Expression<{ first_name: string }> = db.selectFrom('person').select('first_name')

You can implement the Expression interface to create your own type-safe utilities for Kysely.

Type Parameters

  • T





  • get expressionType(): undefined | T
  • All expressions need to have this getter for complicated type-related reasons. Simply add this getter for your expression and always return undefined from it:

    class SomeExpression<T> implements Expression<T> {
    get expressionType(): Tundefined {
    return undefined

    The getter is needed to make the expression assignable to another expression only if the types T are assignable. Without this property (or some other property that references T), you could assing Expression<string> to Expression<number>.

    Returns undefined | T


Generated using TypeDoc