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 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:
class SomeExpression<T> implements Expression<T> {
toOperationNode(): OperationNode {
return sql`some sql here`.toOperationNode()
}
}
Generated using TypeDoc
An expression with an
as
method.