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

schema.ts — drizzle-orm Source File

Architecture documentation for schema.ts, a typescript file in the drizzle-orm codebase. 6 imports, 0 dependents.

File typescript DrizzleORM RelationalQuery 6 imports 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  a24fdf3c_9905_a1c9_be31_c88bf0a5c079["schema.ts"]
  37aabffb_158c_feb8_20e6_26334698593c["sequence.ts"]
  a24fdf3c_9905_a1c9_be31_c88bf0a5c079 --> 37aabffb_158c_feb8_20e6_26334698593c
  92764f4c_eeb1_6f82_8f16_6e0459f370be["gelSequenceWithSchema"]
  a24fdf3c_9905_a1c9_be31_c88bf0a5c079 --> 92764f4c_eeb1_6f82_8f16_6e0459f370be
  cbe7af57_41be_454d_306f_02d0e6f81949["table.ts"]
  a24fdf3c_9905_a1c9_be31_c88bf0a5c079 --> cbe7af57_41be_454d_306f_02d0e6f81949
  e52caf0d_6511_67ab_71ab_401ba052d941["gelTableWithSchema"]
  a24fdf3c_9905_a1c9_be31_c88bf0a5c079 --> e52caf0d_6511_67ab_71ab_401ba052d941
  27705a9d_afe9_57dd_8c97_e52d8a67d426["entity.ts"]
  a24fdf3c_9905_a1c9_be31_c88bf0a5c079 --> 27705a9d_afe9_57dd_8c97_e52d8a67d426
  be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd["sql.ts"]
  a24fdf3c_9905_a1c9_be31_c88bf0a5c079 --> be483a7f_d5d7_7a9b_9a13_44a4a6aafbbd
  style a24fdf3c_9905_a1c9_be31_c88bf0a5c079 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { entityKind, is } from '~/entity.ts';
import { SQL, sql, type SQLWrapper } from '~/sql/sql.ts';
import type { gelSequence } from './sequence.ts';
import { gelSequenceWithSchema } from './sequence.ts';
import { type GelTableFn, gelTableWithSchema } from './table.ts';
// import type { gelMaterializedView, gelView } from './view.ts';
// import { gelMaterializedViewWithSchema, gelViewWithSchema } from './view.ts';

export class GelSchema<TName extends string = string> implements SQLWrapper {
	static readonly [entityKind]: string = 'GelSchema';
	constructor(
		public readonly schemaName: TName,
	) {}

	table: GelTableFn<TName> = ((name, columns, extraConfig) => {
		return gelTableWithSchema(name, columns, extraConfig, this.schemaName);
	});

	// view = ((name, columns) => {
	// 	return gelViewWithSchema(name, columns, this.schemaName);
	// }) as typeof gelView;

	// materializedView = ((name, columns) => {
	// 	return gelMaterializedViewWithSchema(name, columns, this.schemaName);
	// }) as typeof gelMaterializedView;

	// enum: typeof gelEnum = ((name, values) => {
	// 	return gelEnumWithSchema(name, values, this.schemaName);
	// });

	sequence: typeof gelSequence = ((name, options) => {
		return gelSequenceWithSchema(name, options, this.schemaName);
	});

	getSQL(): SQL {
		return new SQL([sql.identifier(this.schemaName)]);
	}

	shouldOmitSQLParens(): boolean {
		return true;
	}
}

export function isGelSchema(obj: unknown): obj is GelSchema {
	return is(obj, GelSchema);
}

export function gelSchema<T extends string>(name: T) {
	if (name === 'public') {
		throw new Error(
			`You can't specify 'public' as schema name. Postgres is using public schema by default. If you want to use 'public' schema, just use GelTable() instead of creating a schema`,
		);
	}

	return new GelSchema(name);
}

Domain

Subdomains

Classes

Frequently Asked Questions

What does schema.ts do?
schema.ts is a source file in the drizzle-orm codebase, written in typescript. It belongs to the DrizzleORM domain, RelationalQuery subdomain.
What functions are defined in schema.ts?
schema.ts defines 2 function(s): gelSchema, isGelSchema.
What does schema.ts depend on?
schema.ts imports 6 module(s): entity.ts, gelSequenceWithSchema, gelTableWithSchema, sequence.ts, sql.ts, table.ts.
Where is schema.ts in the architecture?
schema.ts is located at drizzle-orm/src/gel-core/schema.ts (domain: DrizzleORM, subdomain: RelationalQuery, directory: drizzle-orm/src/gel-core).

Analyze Your Own Codebase

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

Try Supermodel Free