Home / File/ indexes.ts — drizzle-orm Source File

indexes.ts — drizzle-orm Source File

Architecture documentation for indexes.ts, a typescript file in the drizzle-orm codebase. 4 imports, 2 dependents.

File typescript DrizzleORM DatabaseDrivers 4 imports 2 dependents 2 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  cb5b7b23_e36f_992f_699f_d048e0e8a1b1["indexes.ts"]
  44282906_e8a5_11fb_ce14_bb101c95fc0a["index.ts"]
  cb5b7b23_e36f_992f_699f_d048e0e8a1b1 --> 44282906_e8a5_11fb_ce14_bb101c95fc0a
  8a18d7fd_0345_b81c_63b2_ba1765d2fbf3["table.ts"]
  cb5b7b23_e36f_992f_699f_d048e0e8a1b1 --> 8a18d7fd_0345_b81c_63b2_ba1765d2fbf3
  9347c3af_060d_bd99_cd17_d7f17fadf7cb["entity.ts"]
  cb5b7b23_e36f_992f_699f_d048e0e8a1b1 --> 9347c3af_060d_bd99_cd17_d7f17fadf7cb
  163f3669_76fd_05ca_2197_16086705de4a["sql.ts"]
  cb5b7b23_e36f_992f_699f_d048e0e8a1b1 --> 163f3669_76fd_05ca_2197_16086705de4a
  8a18d7fd_0345_b81c_63b2_ba1765d2fbf3["table.ts"]
  8a18d7fd_0345_b81c_63b2_ba1765d2fbf3 --> cb5b7b23_e36f_992f_699f_d048e0e8a1b1
  0f5db9ee_3497_170d_35c2_f74855a5ab79["utils.ts"]
  0f5db9ee_3497_170d_35c2_f74855a5ab79 --> cb5b7b23_e36f_992f_699f_d048e0e8a1b1
  style cb5b7b23_e36f_992f_699f_d048e0e8a1b1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { entityKind } from '~/entity.ts';
import type { SQL } from '~/sql/sql.ts';
import type { SQLiteColumn } from './columns/index.ts';
import type { SQLiteTable } from './table.ts';

export interface IndexConfig {
	name: string;
	columns: IndexColumn[];
	unique: boolean;
	where: SQL | undefined;
}

export type IndexColumn = SQLiteColumn | SQL;

export class IndexBuilderOn {
	static readonly [entityKind]: string = 'SQLiteIndexBuilderOn';

	constructor(private name: string, private unique: boolean) {}

	on(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder {
		return new IndexBuilder(this.name, columns, this.unique);
	}
}

export class IndexBuilder {
	static readonly [entityKind]: string = 'SQLiteIndexBuilder';

	declare _: {
		brand: 'SQLiteIndexBuilder';
	};

	/** @internal */
	config: IndexConfig;

	constructor(name: string, columns: IndexColumn[], unique: boolean) {
		this.config = {
			name,
			columns,
			unique,
			where: undefined,
		};
	}

	/**
	 * Condition for partial index.
	 */
	where(condition: SQL): this {
		this.config.where = condition;
		return this;
	}

	/** @internal */
	build(table: SQLiteTable): Index {
		return new Index(this.config, table);
	}
}

export class Index {
	static readonly [entityKind]: string = 'SQLiteIndex';

	declare _: {
		brand: 'SQLiteIndex';
	};

	readonly config: IndexConfig & { table: SQLiteTable };

	constructor(config: IndexConfig, table: SQLiteTable) {
		this.config = { ...config, table };
	}
}

export function index(name: string): IndexBuilderOn {
	return new IndexBuilderOn(name, false);
}

export function uniqueIndex(name: string): IndexBuilderOn {
	return new IndexBuilderOn(name, true);
}

Domain

Subdomains

Dependencies

Frequently Asked Questions

What does indexes.ts do?
indexes.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, DatabaseDrivers subdomain.
What functions are defined in indexes.ts?
indexes.ts defines 2 function(s): index, uniqueIndex.
What does indexes.ts depend on?
indexes.ts imports 4 module(s): entity.ts, index.ts, sql.ts, table.ts.
What files import indexes.ts?
indexes.ts is imported by 2 file(s): table.ts, utils.ts.
Where is indexes.ts in the architecture?
indexes.ts is located at drizzle-orm/src/sqlite-core/indexes.ts (domain: DrizzleORM, subdomain: DatabaseDrivers, directory: drizzle-orm/src/sqlite-core).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free