Home / Class/ PgSchema Class — drizzle-orm Architecture

PgSchema Class — drizzle-orm Architecture

Architecture documentation for the PgSchema class in schema.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  f09872e6_67fb_3eea_d2d9_8ed355276639["PgSchema"]
  06e0abfd_8dae_0f31_4535_349e0a684907["schema.ts"]
  f09872e6_67fb_3eea_d2d9_8ed355276639 -->|defined in| 06e0abfd_8dae_0f31_4535_349e0a684907
  1abbc7e7_10f0_abc3_5c2f_a24504092c13["constructor()"]
  f09872e6_67fb_3eea_d2d9_8ed355276639 -->|method| 1abbc7e7_10f0_abc3_5c2f_a24504092c13
  a5932bed_e5de_b594_d849_c3984cefac59["enum()"]
  f09872e6_67fb_3eea_d2d9_8ed355276639 -->|method| a5932bed_e5de_b594_d849_c3984cefac59
  55a8fdfb_5344_cb22_cc04_23c797f83850["getSQL()"]
  f09872e6_67fb_3eea_d2d9_8ed355276639 -->|method| 55a8fdfb_5344_cb22_cc04_23c797f83850
  1dfa914c_f52f_e89f_ae39_a4d1dd872166["shouldOmitSQLParens()"]
  f09872e6_67fb_3eea_d2d9_8ed355276639 -->|method| 1dfa914c_f52f_e89f_ae39_a4d1dd872166

Relationship Graph

Source Code

drizzle-orm/src/pg-core/schema.ts lines 9–58

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

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

	view = ((name, columns) => {
		return pgViewWithSchema(name, columns, this.schemaName);
	}) as typeof pgView;

	materializedView = ((name, columns) => {
		return pgMaterializedViewWithSchema(name, columns, this.schemaName);
	}) as typeof pgMaterializedView;

	public enum<U extends string, T extends Readonly<[U, ...U[]]>>(
		enumName: string,
		values: T | Writable<T>,
	): PgEnum<Writable<T>>;

	public enum<E extends Record<string, string>>(
		enumName: string,
		enumObj: NonArray<E>,
	): PgEnumObject<E>;

	public enum(enumName: any, input: any): any {
		return Array.isArray(input)
			? pgEnumWithSchema(
				enumName,
				[...input] as [string, ...string[]],
				this.schemaName,
			)
			: pgEnumObjectWithSchema(enumName, input, this.schemaName);
	}

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

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

	shouldOmitSQLParens(): boolean {
		return true;
	}
}

Domain

Frequently Asked Questions

What is the PgSchema class?
PgSchema is a class in the drizzle-orm codebase, defined in drizzle-orm/src/pg-core/schema.ts.
Where is PgSchema defined?
PgSchema is defined in drizzle-orm/src/pg-core/schema.ts at line 9.

Analyze Your Own Codebase

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

Try Supermodel Free