kysely
    Preparing search index...

    Class AndWrapper<DB, TB, T>

    An expression with an as method.

    Type Parameters

    Implements

    Index

    Constructors

    Methods

    • Returns an aliased version of the expression.

      In addition to slapping as "the_alias" to the end of the SQL, this method also provides strict typing:

      const result = await db
      .selectFrom('person')
      .select(eb =>
      eb('first_name', '=', 'Jennifer')
      .and('last_name', '=', 'Aniston')
      .as('is_jennifer_aniston')
      )
      .executeTakeFirstOrThrow()

      // `is_jennifer_aniston: SqlBool` field exists in the result type.
      console.log(result.is_jennifer_aniston)

      The generated SQL (PostgreSQL):

      select "first_name" = $1 and "first_name" = $2 as "is_jennifer_aniston"
      from "person"

      Type Parameters

      • A extends string

      Parameters

      • alias: A

      Returns AliasedExpression<T, A>

    • Returns an aliased version of the expression.

      In addition to slapping as "the_alias" to the end of the SQL, this method also provides strict typing:

      const result = await db
      .selectFrom('person')
      .select(eb =>
      eb('first_name', '=', 'Jennifer')
      .and('last_name', '=', 'Aniston')
      .as('is_jennifer_aniston')
      )
      .executeTakeFirstOrThrow()

      // `is_jennifer_aniston: SqlBool` field exists in the result type.
      console.log(result.is_jennifer_aniston)

      The generated SQL (PostgreSQL):

      select "first_name" = $1 and "first_name" = $2 as "is_jennifer_aniston"
      from "person"

      Type Parameters

      • A extends string

      Parameters

      Returns AliasedExpression<T, A>

    • Creates the OperationNode that describes how to compile this expression into SQL.

      If you are creating a custom expression, it's often easiest to use the sql template tag to build the node:

      import { type Expression, type OperationNode, sql } from 'kysely'

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

      toOperationNode(): OperationNode {
      return sql`some sql here`.toOperationNode()
      }
      }

      Returns ParensNode