Home / Class/ GenerateUniqueLine Class — drizzle-orm Architecture

GenerateUniqueLine Class — drizzle-orm Architecture

Architecture documentation for the GenerateUniqueLine class in Generators.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  c6bae486_ac57_8569_8412_6d2932eaefe2["GenerateUniqueLine"]
  e5cee001_0354_7e76_ef0a_06dca71dc8ce["Generators.ts"]
  c6bae486_ac57_8569_8412_6d2932eaefe2 -->|defined in| e5cee001_0354_7e76_ef0a_06dca71dc8ce
  c82375d7_9d94_c385_0ab3_2d34aaf01c46["init()"]
  c6bae486_ac57_8569_8412_6d2932eaefe2 -->|method| c82375d7_9d94_c385_0ab3_2d34aaf01c46
  e949cbe6_ad2e_b07a_44a9_090e06b2f64a["generate()"]
  c6bae486_ac57_8569_8412_6d2932eaefe2 -->|method| e949cbe6_ad2e_b07a_44a9_090e06b2f64a

Relationship Graph

Source Code

drizzle-seed/src/services/Generators.ts lines 3052–3119

export class GenerateUniqueLine extends AbstractGenerator<{
	minAValue?: number;
	maxAValue?: number;
	minBValue?: number;
	maxBValue?: number;
	minCValue?: number;
	maxCValue?: number;
	isUnique?: boolean;
}> {
	static override readonly entityKind: string = 'GenerateUniqueLine';

	private state: {
		aCoefficientGen: GenerateUniqueNumber;
		bCoefficientGen: GenerateUniqueNumber;
		cCoefficientGen: GenerateUniqueNumber;
	} | undefined;
	public override isUnique = true;

	override init({ count, seed }: { count: number; seed: number }) {
		const aCoefficientGen = new GenerateUniqueNumber({
			minValue: this.params.minAValue,
			maxValue: this.params.maxAValue,
			precision: 10,
		});
		aCoefficientGen.init({ count, seed });

		const bCoefficientGen = new GenerateUniqueNumber({
			minValue: this.params.minBValue,
			maxValue: this.params.maxBValue,
			precision: 10,
		});
		bCoefficientGen.init({ count, seed });

		const cCoefficientGen = new GenerateUniqueNumber({
			minValue: this.params.minCValue,
			maxValue: this.params.maxCValue,
			precision: 10,
		});
		cCoefficientGen.init({ count, seed });

		this.state = { aCoefficientGen, bCoefficientGen, cCoefficientGen };
	}

	generate() {
		if (this.state === undefined) {
			throw new Error('state is not defined.');
		}

		let b: number;
		const a = this.state.aCoefficientGen.generate();

		b = this.state.bCoefficientGen.generate();
		while (a === 0 && b === 0) {
			b = this.state.bCoefficientGen.generate();
		}

		const c = this.state.cCoefficientGen.generate();

		if (this.dataType === 'json') {
			return { a, b, c };
		} else if (this.dataType === 'string') {
			return `[${a}, ${b}, ${c}]`;
		} else {
			// if (this.dataType === "array")
			return [a, b, c];
		}
	}
}

Domain

Frequently Asked Questions

What is the GenerateUniqueLine class?
GenerateUniqueLine is a class in the drizzle-orm codebase, defined in drizzle-seed/src/services/Generators.ts.
Where is GenerateUniqueLine defined?
GenerateUniqueLine is defined in drizzle-seed/src/services/Generators.ts at line 3052.

Analyze Your Own Codebase

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

Try Supermodel Free