Home / File/ primary-keys.ts — drizzle-orm Source File

primary-keys.ts — drizzle-orm Source File

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

File typescript DrizzleORM SQLDialects 4 imports 2 dependents 1 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  a7ff59de_fcfb_68fe_6665_16d01fc2937f["primary-keys.ts"]
  17004f28_e6fd_9cb9_4060_89241969160e["index.ts"]
  a7ff59de_fcfb_68fe_6665_16d01fc2937f --> 17004f28_e6fd_9cb9_4060_89241969160e
  64ae061d_ed9a_c5f9_235a_3f31995a8d54["table.ts"]
  a7ff59de_fcfb_68fe_6665_16d01fc2937f --> 64ae061d_ed9a_c5f9_235a_3f31995a8d54
  173bb8b4_9ed6_8c4b_ec84_da0f0e14ceb2["SQLiteTable"]
  a7ff59de_fcfb_68fe_6665_16d01fc2937f --> 173bb8b4_9ed6_8c4b_ec84_da0f0e14ceb2
  27705a9d_afe9_57dd_8c97_e52d8a67d426["entity.ts"]
  a7ff59de_fcfb_68fe_6665_16d01fc2937f --> 27705a9d_afe9_57dd_8c97_e52d8a67d426
  64ae061d_ed9a_c5f9_235a_3f31995a8d54["table.ts"]
  64ae061d_ed9a_c5f9_235a_3f31995a8d54 --> a7ff59de_fcfb_68fe_6665_16d01fc2937f
  5eb95521_a13c_5ed6_36c8_8869eb8138fc["utils.ts"]
  5eb95521_a13c_5ed6_36c8_8869eb8138fc --> a7ff59de_fcfb_68fe_6665_16d01fc2937f
  style a7ff59de_fcfb_68fe_6665_16d01fc2937f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

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

export function primaryKey<
	TTableName extends string,
	TColumn extends AnySQLiteColumn<{ tableName: TTableName }>,
	TColumns extends AnySQLiteColumn<{ tableName: TTableName }>[],
>(config: { name?: string; columns: [TColumn, ...TColumns] }): PrimaryKeyBuilder;
/**
 * @deprecated: Please use primaryKey({ columns: [] }) instead of this function
 * @param columns
 */
export function primaryKey<
	TTableName extends string,
	TColumns extends AnySQLiteColumn<{ tableName: TTableName }>[],
>(...columns: TColumns): PrimaryKeyBuilder;
export function primaryKey(...config: any) {
	if (config[0].columns) {
		return new PrimaryKeyBuilder(config[0].columns, config[0].name);
	}
	return new PrimaryKeyBuilder(config);
}
export class PrimaryKeyBuilder {
	static readonly [entityKind]: string = 'SQLitePrimaryKeyBuilder';

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

	/** @internal */
	columns: SQLiteColumn[];

	/** @internal */
	name?: string;

	constructor(
		columns: SQLiteColumn[],
		name?: string,
	) {
		this.columns = columns;
		this.name = name;
	}

	/** @internal */
	build(table: SQLiteTable): PrimaryKey {
		return new PrimaryKey(table, this.columns, this.name);
	}
}

export class PrimaryKey {
	static readonly [entityKind]: string = 'SQLitePrimaryKey';

	readonly columns: SQLiteColumn[];
	readonly name?: string;

	constructor(readonly table: SQLiteTable, columns: SQLiteColumn[], name?: string) {
		this.columns = columns;
		this.name = name;
	}

	getName(): string {
		return this.name
			?? `${this.table[SQLiteTable.Symbol.Name]}_${this.columns.map((column) => column.name).join('_')}_pk`;
	}
}

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does primary-keys.ts do?
primary-keys.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, SQLDialects subdomain.
What functions are defined in primary-keys.ts?
primary-keys.ts defines 1 function(s): primaryKey.
What does primary-keys.ts depend on?
primary-keys.ts imports 4 module(s): SQLiteTable, entity.ts, index.ts, table.ts.
What files import primary-keys.ts?
primary-keys.ts is imported by 2 file(s): table.ts, utils.ts.
Where is primary-keys.ts in the architecture?
primary-keys.ts is located at drizzle-orm/src/sqlite-core/primary-keys.ts (domain: DrizzleORM, subdomain: SQLDialects, 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