Module

x/kysely_postgrs_js_dialect/mod.ts>kysely.CreateIndexBuilder

Kysely dialect for PostgreSQL using the Postgres.js client.
class kysely.CreateIndexBuilder
import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.3/mod.ts";
const { CreateIndexBuilder } = kysely;

Constructors

new
CreateIndexBuilder(props: CreateIndexBuilderProps)

Type Parameters

optional
C = never

Methods

$call<T>(func: (qb: this) => T): T

Simply calls the provided function passing this as the only argument. $call returns what the provided function returns.

column<CL extends string>(column: OrderedColumnName<CL>): CreateIndexBuilder<C | ExtractColumnNameFromOrderedColumnName<CL>>

Adds a column to the index.

Also see {@link columns} for adding multiple columns at once or {@link expression} for specifying an arbitrary expression.

Examples

await db.schema
        .createIndex('person_first_name_and_age_index')
        .on('person')
        .column('first_name')
        .column('age desc')
        .execute()

The generated SQL (PostgreSQL):

create index "person_first_name_and_age_index" on "person" ("first_name", "age" desc)
columns<CL extends string>(columns: OrderedColumnName<CL>[]): CreateIndexBuilder<C | ExtractColumnNameFromOrderedColumnName<CL>>

Specifies a list of columns for the index.

Also see {@link column} for adding a single column or {@link expression} for specifying an arbitrary expression.

Examples

await db.schema
        .createIndex('person_first_name_and_age_index')
        .on('person')
        .columns(['first_name', 'age desc'])
        .execute()

The generated SQL (PostgreSQL):

create index "person_first_name_and_age_index" on "person" ("first_name", "age" desc)
execute(): Promise<void>

Specifies an arbitrary expression for the index.

Examples

import { sql } from 'kysely'

await db.schema
  .createIndex('person_first_name_index')
  .on('person')
  .expression(sql`first_name COLLATE "fi_FI"`)
  .execute()

The generated SQL (PostgreSQL):

create index "person_first_name_index" on "person" (first_name COLLATE "fi_FI")

Adds the "if not exists" modifier.

If the index already exists, no error is thrown if this method has been called.

Adds nulls not distinct specifier to index. This only works on some dialects like PostgreSQL.

Examples

db.schema.createIndex('person_first_name_index')
 .on('person')
 .column('first_name')
 .nullsNotDistinct()
 .execute()

The generated SQL (PostgreSQL):

create index "person_first_name_index"
on "test" ("first_name")
nulls not distinct;
on(table: string): CreateIndexBuilder<C>

Specifies the table for the index.

Makes the index unique.

Specifies the index type.

using(indexType: string): CreateIndexBuilder<C>

Adds a where clause to the query. This Effectively turns the index partial.

Examples

import { sql } from 'kysely'

await db.schema
   .createIndex('orders_unbilled_index')
   .on('orders')
   .column('order_nr')
   .where(sql.ref('billed'), 'is not', true)
   .where('order_nr', 'like', '123%')

The generated SQL (PostgreSQL):

create index "orders_unbilled_index" on "orders" ("order_nr") where "billed" is not true and "order_nr" like '123%'

Column names specified in {@link column} or {@link columns} are known at compile-time and can be referred to in the current query and context.

Sometimes you may want to refer to columns that exist in the table but are not part of the current index. In that case you can refer to them using sql expressions.

Parameters are always sent as literals due to database restrictions.

where(factory: (qb: ExpressionBuilder<ShallowRecord<string, ShallowRecord<C & string, any>>, string>) => Expression<SqlBool>): CreateIndexBuilder<C>
import kysely.CreateIndexBuilder
import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.3/mod.ts";
const { CreateIndexBuilder } = kysely;