Module

x/kysely_postgrs_js_dialect/deps.ts>kysely.AggregateFunctionBuilder#as

Kysely dialect for PostgreSQL using the Postgres.js client.
method kysely.AggregateFunctionBuilder.prototype.as
import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.3/deps.ts";
const { AggregateFunctionBuilder } = kysely;

Returns an aliased version of the function.

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.fn.count<number>('id').as('person_count')
  )
  .executeTakeFirstOrThrow()

// `person_count: number` field exists in the result type.
console.log(result.person_count)

The generated SQL (PostgreSQL):

select count("id") as "person_count"
from "person"

Type Parameters

A extends string