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

line.ts — drizzle-orm Source File

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

File typescript DrizzleORM DatabaseDrivers 7 imports 1 dependents 1 functions 4 classes

Entity Profile

Dependency Diagram

graph LR
  a7331579_1f99_939d_d745_dbe535402f7e["line.ts"]
  f4f42b4c_8610_03dd_fe01_232098668127["common.ts"]
  a7331579_1f99_939d_d745_dbe535402f7e --> f4f42b4c_8610_03dd_fe01_232098668127
  099d7c6d_2fc4_7b20_40e3_1b8af4138fe6["PgColumn"]
  a7331579_1f99_939d_d745_dbe535402f7e --> 099d7c6d_2fc4_7b20_40e3_1b8af4138fe6
  2dc784c6_95e9_4e28_ec81_7caf4acbd426["column-builder.ts"]
  a7331579_1f99_939d_d745_dbe535402f7e --> 2dc784c6_95e9_4e28_ec81_7caf4acbd426
  05f0a280_d0c9_693a_a4bf_83cc671012d2["column.ts"]
  a7331579_1f99_939d_d745_dbe535402f7e --> 05f0a280_d0c9_693a_a4bf_83cc671012d2
  27705a9d_afe9_57dd_8c97_e52d8a67d426["entity.ts"]
  a7331579_1f99_939d_d745_dbe535402f7e --> 27705a9d_afe9_57dd_8c97_e52d8a67d426
  17418917_ff81_c4e5_90f4_f37d557e5d51["table.ts"]
  a7331579_1f99_939d_d745_dbe535402f7e --> 17418917_ff81_c4e5_90f4_f37d557e5d51
  ecce3253_1e75_a87f_27b3_ca87e81a3024["utils.ts"]
  a7331579_1f99_939d_d745_dbe535402f7e --> ecce3253_1e75_a87f_27b3_ca87e81a3024
  b38cf654_48d6_41dc_6c0f_203697984d98["all.ts"]
  b38cf654_48d6_41dc_6c0f_203697984d98 --> a7331579_1f99_939d_d745_dbe535402f7e
  style a7331579_1f99_939d_d745_dbe535402f7e 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 { type Equal, getColumnNameAndConfig } from '~/utils.ts';
import { PgColumn, PgColumnBuilder } from './common.ts';

export type PgLineBuilderInitial<TName extends string> = PgLineBuilder<{
	name: TName;
	dataType: 'array';
	columnType: 'PgLine';
	data: [number, number, number];
	driverParam: number | string;
	enumValues: undefined;
}>;

export class PgLineBuilder<T extends ColumnBuilderBaseConfig<'array', 'PgLine'>> extends PgColumnBuilder<T> {
	static override readonly [entityKind]: string = 'PgLineBuilder';

	constructor(name: T['name']) {
		super(name, 'array', 'PgLine');
	}

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

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

	getSQLType(): string {
		return 'line';
	}

	override mapFromDriverValue(value: string): [number, number, number] {
		const [a, b, c] = value.slice(1, -1).split(',');
		return [Number.parseFloat(a!), Number.parseFloat(b!), Number.parseFloat(c!)];
	}

	override mapToDriverValue(value: [number, number, number]): string {
		return `{${value[0]},${value[1]},${value[2]}}`;
	}
}

export type PgLineABCBuilderInitial<TName extends string> = PgLineABCBuilder<{
	name: TName;
	dataType: 'json';
	columnType: 'PgLineABC';
	data: { a: number; b: number; c: number };
	driverParam: string;
	enumValues: undefined;
}>;

export class PgLineABCBuilder<T extends ColumnBuilderBaseConfig<'json', 'PgLineABC'>> extends PgColumnBuilder<T> {
	static override readonly [entityKind]: string = 'PgLineABCBuilder';

	constructor(name: T['name']) {
		super(name, 'json', 'PgLineABC');
	}

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

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

	getSQLType(): string {
		return 'line';
	}

	override mapFromDriverValue(value: string): { a: number; b: number; c: number } {
		const [a, b, c] = value.slice(1, -1).split(',');
		return { a: Number.parseFloat(a!), b: Number.parseFloat(b!), c: Number.parseFloat(c!) };
	}

	override mapToDriverValue(value: { a: number; b: number; c: number }): string {
		return `{${value.a},${value.b},${value.c}}`;
	}
}

export interface PgLineTypeConfig<T extends 'tuple' | 'abc' = 'tuple' | 'abc'> {
	mode?: T;
}

export function line(): PgLineBuilderInitial<''>;
export function line<TMode extends PgLineTypeConfig['mode'] & {}>(
	config?: PgLineTypeConfig<TMode>,
): Equal<TMode, 'abc'> extends true ? PgLineABCBuilderInitial<''>
	: PgLineBuilderInitial<''>;
export function line<TName extends string, TMode extends PgLineTypeConfig['mode'] & {}>(
	name: TName,
	config?: PgLineTypeConfig<TMode>,
): Equal<TMode, 'abc'> extends true ? PgLineABCBuilderInitial<TName>
	: PgLineBuilderInitial<TName>;
export function line(a?: string | PgLineTypeConfig, b?: PgLineTypeConfig) {
	const { name, config } = getColumnNameAndConfig<PgLineTypeConfig>(a, b);
	if (!config?.mode || config.mode === 'tuple') {
		return new PgLineBuilder(name);
	}
	return new PgLineABCBuilder(name);
}

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

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