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')
.or('first_name', '=', 'Sylvester')
.as('is_jennifer_or_sylvester')
)
.executeTakeFirstOrThrow()
// `is_jennifer_or_sylvester: SqlBool` field exists in the result type.
console.log(result.is_jennifer_or_sylvester)
The generated SQL (PostgreSQL):
select "first_name" = $1 or "first_name" = $2 as "is_jennifer_or_sylvester"
from "person"
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')
.or('first_name', '=', 'Sylvester')
.as('is_jennifer_or_sylvester')
)
.executeTakeFirstOrThrow()
// `is_jennifer_or_sylvester: SqlBool` field exists in the result type.
console.log(result.is_jennifer_or_sylvester)
The generated SQL (PostgreSQL):
select "first_name" = $1 or "first_name" = $2 as "is_jennifer_or_sylvester"
from "person"
Combines this and another expression using OR.
See ExpressionWrapper.or for examples.
Combines this and another expression using OR.
See ExpressionWrapper.or for examples.
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()
}
}
An expression with an
asmethod.