import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.4/deps.ts";
const { QueryCreator } = kysely;
Sets the schema to be used for all table references that don't explicitly specify a schema.
This only affects the query created through the builder returned from
this method and doesn't modify the db
instance.
See this recipe for a more detailed explanation.
Examples
await db
.withSchema('mammals')
.selectFrom('pet')
.selectAll()
.innerJoin('public.person', 'public.person.id', 'pet.owner_id')
.execute()
The generated SQL (PostgreSQL):
select * from "mammals"."pet"
inner join "public"."person"
on "public"."person"."id" = "mammals"."pet"."owner_id"
withSchema
is smart enough to not add schema for aliases,
common table expressions or other places where the schema
doesn't belong to:
await db
.withSchema('mammals')
.selectFrom('pet as p')
.select('p.name')
.execute()
The generated SQL (PostgreSQL):
select "p"."name" from "mammals"."pet" as "p"