Class ExpressionWrapper<DB, TB, T>

An expression with an as method.

Type Parameters

  • DB

  • TB extends keyof DB

  • T

Hierarchy

  • ExpressionWrapper

Implements

Constructors

Methods

  • Omit null from the expression's type.

    This function can be useful in cases where you know an expression can't be null, but Kysely is unable to infer it.

    This method call doesn't change the SQL in any way. This methods simply returns a copy of this with a new output type.

    Returns ExpressionWrapper<DB, TB, Exclude<T, null>>

  • Combines this and another expression using AND.

    Also see and

    Examples

    db.selectFrom('person')
    .selectAll()
    .where(eb => eb('first_name', '=', 'Jennifer')
    .and('last_name', '=', 'Aniston')
    .and('age', '>', 40)
    )

    The generated SQL (PostgreSQL):

    select *
    from "person"
    where (
    "first_name" = $1
    and "last_name" = $2
    and "age" > $3
    )

    You can also pass any expression as the only argument to this method:

    db.selectFrom('person')
    .selectAll()
    .where(eb => eb('first_name', '=', 'Jennifer')
    .and(eb('first_name', '=', 'Sylvester').or('last_name', '=', 'Stallone'))
    .and(eb.exists(
    eb.selectFrom('pet')
    .select('id')
    .whereRef('pet.owner_id', '=', 'person.id')
    )
    )

    The generated SQL (PostgreSQL):

    select *
    from "person"
    where (
    "first_name" = $1
    and ("first_name" = $2 or "last_name" = $3)
    and exists (
    select "id"
    from "pet"
    where "pet"."owner_id" = "person"."id"
    )
    )

    Type Parameters

    • RE extends string | Expression<any> | DynamicReferenceBuilder<any> | SelectQueryBuilderExpression<Record<string, any>> | OperandExpressionFactory<DB, TB, any>

    • VE extends any

    Parameters

    Returns T extends SqlBool
        ? AndWrapper<DB, TB, SqlBool>
        : KyselyTypeError<"and() method can only be called on boolean expressions">

  • Type Parameters

    Parameters

    • expression: E

    Returns T extends SqlBool
        ? AndWrapper<DB, TB, SqlBool>
        : KyselyTypeError<"and() method can only be called on boolean expressions">

  • Combines this and another expression using OR.

    Also see or

    Examples

    db.selectFrom('person')
    .selectAll()
    .where(eb => eb('first_name', '=', 'Jennifer')
    .or('first_name', '=', 'Arnold')
    .or('first_name', '=', 'Sylvester')
    )

    The generated SQL (PostgreSQL):

    select *
    from "person"
    where (
    "first_name" = $1
    or "first_name" = $2
    or "first_name" = $3
    )

    You can also pass any expression as the only argument to this method:

    db.selectFrom('person')
    .selectAll()
    .where(eb => eb('first_name', '=', 'Jennifer')
    .or(eb('first_name', '=', 'Sylvester').and('last_name', '=', 'Stallone'))
    .or(eb.exists(
    eb.selectFrom('pet')
    .select('id')
    .whereRef('pet.owner_id', '=', 'person.id')
    )
    )

    The generated SQL (PostgreSQL):

    select *
    from "person"
    where (
    "first_name" = $1
    or ("first_name" = $2 and "last_name" = $3)
    or exists (
    select "id"
    from "pet"
    where "pet"."owner_id" = "person"."id"
    )
    )

    Type Parameters

    • RE extends string | Expression<any> | DynamicReferenceBuilder<any> | SelectQueryBuilderExpression<Record<string, any>> | OperandExpressionFactory<DB, TB, any>

    • VE extends any

    Parameters

    Returns T extends SqlBool
        ? OrWrapper<DB, TB, SqlBool>
        : KyselyTypeError<"or() method can only be called on boolean expressions">

  • Type Parameters

    Parameters

    • expression: E

    Returns T extends SqlBool
        ? OrWrapper<DB, TB, SqlBool>
        : KyselyTypeError<"or() method can only be called on boolean expressions">

Generated using TypeDoc