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

time.ts — drizzle-orm Source File

Architecture documentation for time.ts, a typescript file in the drizzle-orm codebase. 9 imports, 1 dependents.

File typescript DrizzleORM DatabaseDrivers 9 imports 1 dependents 1 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  7102357c_0ef2_b03e_a1a8_871e6fea8eac["time.ts"]
  f4f42b4c_8610_03dd_fe01_232098668127["common.ts"]
  7102357c_0ef2_b03e_a1a8_871e6fea8eac --> f4f42b4c_8610_03dd_fe01_232098668127
  099d7c6d_2fc4_7b20_40e3_1b8af4138fe6["PgColumn"]
  7102357c_0ef2_b03e_a1a8_871e6fea8eac --> 099d7c6d_2fc4_7b20_40e3_1b8af4138fe6
  40f2fd93_0821_09d6_99ff_d1f9b2b69641["date.common.ts"]
  7102357c_0ef2_b03e_a1a8_871e6fea8eac --> 40f2fd93_0821_09d6_99ff_d1f9b2b69641
  a7bcec86_fec9_446d_0dc2_721126dd50c7["timestamp.ts"]
  7102357c_0ef2_b03e_a1a8_871e6fea8eac --> a7bcec86_fec9_446d_0dc2_721126dd50c7
  2dc784c6_95e9_4e28_ec81_7caf4acbd426["column-builder.ts"]
  7102357c_0ef2_b03e_a1a8_871e6fea8eac --> 2dc784c6_95e9_4e28_ec81_7caf4acbd426
  05f0a280_d0c9_693a_a4bf_83cc671012d2["column.ts"]
  7102357c_0ef2_b03e_a1a8_871e6fea8eac --> 05f0a280_d0c9_693a_a4bf_83cc671012d2
  27705a9d_afe9_57dd_8c97_e52d8a67d426["entity.ts"]
  7102357c_0ef2_b03e_a1a8_871e6fea8eac --> 27705a9d_afe9_57dd_8c97_e52d8a67d426
  17418917_ff81_c4e5_90f4_f37d557e5d51["table.ts"]
  7102357c_0ef2_b03e_a1a8_871e6fea8eac --> 17418917_ff81_c4e5_90f4_f37d557e5d51
  ecce3253_1e75_a87f_27b3_ca87e81a3024["utils.ts"]
  7102357c_0ef2_b03e_a1a8_871e6fea8eac --> ecce3253_1e75_a87f_27b3_ca87e81a3024
  b38cf654_48d6_41dc_6c0f_203697984d98["all.ts"]
  b38cf654_48d6_41dc_6c0f_203697984d98 --> 7102357c_0ef2_b03e_a1a8_871e6fea8eac
  style 7102357c_0ef2_b03e_a1a8_871e6fea8eac fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { ColumnBuilderBaseConfig, ColumnBuilderRuntimeConfig, MakeColumnConfig } from '~/column-builder.ts';
import type { ColumnBaseConfig } from '~/column.ts';
import { entityKind } from '~/entity.ts';
import type { AnyPgTable } from '~/pg-core/table.ts';
import { getColumnNameAndConfig } from '~/utils.ts';
import { PgColumn } from './common.ts';
import { PgDateColumnBaseBuilder } from './date.common.ts';
import type { Precision } from './timestamp.ts';

export type PgTimeBuilderInitial<TName extends string> = PgTimeBuilder<{
	name: TName;
	dataType: 'string';
	columnType: 'PgTime';
	data: string;
	driverParam: string;
	enumValues: undefined;
}>;

export class PgTimeBuilder<T extends ColumnBuilderBaseConfig<'string', 'PgTime'>> extends PgDateColumnBaseBuilder<
	T,
	{ withTimezone: boolean; precision: number | undefined }
> {
	static override readonly [entityKind]: string = 'PgTimeBuilder';

	constructor(
		name: T['name'],
		readonly withTimezone: boolean,
		readonly precision: number | undefined,
	) {
		super(name, 'string', 'PgTime');
		this.config.withTimezone = withTimezone;
		this.config.precision = precision;
	}

	/** @internal */
	override build<TTableName extends string>(
		table: AnyPgTable<{ name: TTableName }>,
	): PgTime<MakeColumnConfig<T, TTableName>> {
		return new PgTime<MakeColumnConfig<T, TTableName>>(table, this.config as ColumnBuilderRuntimeConfig<any, any>);
	}
}

export class PgTime<T extends ColumnBaseConfig<'string', 'PgTime'>> extends PgColumn<T> {
	static override readonly [entityKind]: string = 'PgTime';

	readonly withTimezone: boolean;
	readonly precision: number | undefined;

	constructor(table: AnyPgTable<{ name: T['tableName'] }>, config: PgTimeBuilder<T>['config']) {
		super(table, config);
		this.withTimezone = config.withTimezone;
		this.precision = config.precision;
	}

	getSQLType(): string {
		const precision = this.precision === undefined ? '' : `(${this.precision})`;
		return `time${precision}${this.withTimezone ? ' with time zone' : ''}`;
	}
}

export interface TimeConfig {
	precision?: Precision;
	withTimezone?: boolean;
}

export function time(): PgTimeBuilderInitial<''>;
export function time(config?: TimeConfig): PgTimeBuilderInitial<''>;
export function time<TName extends string>(name: TName, config?: TimeConfig): PgTimeBuilderInitial<TName>;
export function time(a?: string | TimeConfig, b: TimeConfig = {}) {
	const { name, config } = getColumnNameAndConfig<TimeConfig>(a, b);
	return new PgTimeBuilder(name, config.withTimezone ?? false, config.precision);
}

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

What does time.ts do?
time.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 time.ts?
time.ts defines 1 function(s): time.
What does time.ts depend on?
time.ts imports 9 module(s): PgColumn, column-builder.ts, column.ts, common.ts, date.common.ts, entity.ts, table.ts, timestamp.ts, and 1 more.
What files import time.ts?
time.ts is imported by 1 file(s): all.ts.
Where is time.ts in the architecture?
time.ts is located at drizzle-orm/src/pg-core/columns/time.ts (domain: DrizzleORM, subdomain: DatabaseDrivers, directory: drizzle-orm/src/pg-core/columns).

Analyze Your Own Codebase

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

Try Supermodel Free