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

binary.ts — drizzle-orm Source File

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

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

Entity Profile

Dependency Diagram

graph LR
  ae99d625_4bae_76fd_4d10_fa20ca723d3b["binary.ts"]
  83c65ad5_22a0_d33f_47b8_c2ed1c8d8bbb["common.ts"]
  ae99d625_4bae_76fd_4d10_fa20ca723d3b --> 83c65ad5_22a0_d33f_47b8_c2ed1c8d8bbb
  8da43de9_1be1_48fb_1db1_a6bc59f5b306["MySqlColumn"]
  ae99d625_4bae_76fd_4d10_fa20ca723d3b --> 8da43de9_1be1_48fb_1db1_a6bc59f5b306
  2dc784c6_95e9_4e28_ec81_7caf4acbd426["column-builder.ts"]
  ae99d625_4bae_76fd_4d10_fa20ca723d3b --> 2dc784c6_95e9_4e28_ec81_7caf4acbd426
  05f0a280_d0c9_693a_a4bf_83cc671012d2["column.ts"]
  ae99d625_4bae_76fd_4d10_fa20ca723d3b --> 05f0a280_d0c9_693a_a4bf_83cc671012d2
  27705a9d_afe9_57dd_8c97_e52d8a67d426["entity.ts"]
  ae99d625_4bae_76fd_4d10_fa20ca723d3b --> 27705a9d_afe9_57dd_8c97_e52d8a67d426
  70e1783e_f575_ccd4_36bd_5f0978c2172c["table.ts"]
  ae99d625_4bae_76fd_4d10_fa20ca723d3b --> 70e1783e_f575_ccd4_36bd_5f0978c2172c
  ecce3253_1e75_a87f_27b3_ca87e81a3024["utils.ts"]
  ae99d625_4bae_76fd_4d10_fa20ca723d3b --> ecce3253_1e75_a87f_27b3_ca87e81a3024
  6dd15b44_b15c_62ef_81b2_e72b28299be9["all.ts"]
  6dd15b44_b15c_62ef_81b2_e72b28299be9 --> ae99d625_4bae_76fd_4d10_fa20ca723d3b
  style ae99d625_4bae_76fd_4d10_fa20ca723d3b 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 { AnyMySqlTable } from '~/mysql-core/table.ts';
import { getColumnNameAndConfig } from '~/utils.ts';
import { MySqlColumn, MySqlColumnBuilder } from './common.ts';

export type MySqlBinaryBuilderInitial<TName extends string> = MySqlBinaryBuilder<{
	name: TName;
	dataType: 'string';
	columnType: 'MySqlBinary';
	data: string;
	driverParam: string;
	enumValues: undefined;
}>;

export class MySqlBinaryBuilder<T extends ColumnBuilderBaseConfig<'string', 'MySqlBinary'>> extends MySqlColumnBuilder<
	T,
	MySqlBinaryConfig
> {
	static override readonly [entityKind]: string = 'MySqlBinaryBuilder';

	constructor(name: T['name'], length: number | undefined) {
		super(name, 'string', 'MySqlBinary');
		this.config.length = length;
	}

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

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

	length: number | undefined = this.config.length;

	override mapFromDriverValue(value: string | Buffer | Uint8Array): string {
		if (typeof value === 'string') return value;
		if (Buffer.isBuffer(value)) return value.toString();

		const str: string[] = [];
		for (const v of value) {
			str.push(v === 49 ? '1' : '0');
		}

		return str.join('');
	}

	getSQLType(): string {
		return this.length === undefined ? `binary` : `binary(${this.length})`;
	}
}

export interface MySqlBinaryConfig {
	length?: number;
}

export function binary(): MySqlBinaryBuilderInitial<''>;
export function binary(
	config?: MySqlBinaryConfig,
): MySqlBinaryBuilderInitial<''>;
export function binary<TName extends string>(
	name: TName,
	config?: MySqlBinaryConfig,
): MySqlBinaryBuilderInitial<TName>;
export function binary(a?: string | MySqlBinaryConfig, b: MySqlBinaryConfig = {}) {
	const { name, config } = getColumnNameAndConfig<MySqlBinaryConfig>(a, b);
	return new MySqlBinaryBuilder(name, config.length);
}

Domain

Subdomains

Functions

Dependencies

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free