Home / Class/ GenerateUniqueFirstName Class — drizzle-orm Architecture

GenerateUniqueFirstName Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  fb817b73_2ef2_452e_5f84_8bd519902eef["GenerateUniqueFirstName"]
  e5cee001_0354_7e76_ef0a_06dca71dc8ce["Generators.ts"]
  fb817b73_2ef2_452e_5f84_8bd519902eef -->|defined in| e5cee001_0354_7e76_ef0a_06dca71dc8ce
  27bc7623_8c08_e5be_d4ed_26dc9d09158f["init()"]
  fb817b73_2ef2_452e_5f84_8bd519902eef -->|method| 27bc7623_8c08_e5be_d4ed_26dc9d09158f
  3503f8d1_c017_d1eb_7c1c_ff77acd30fec["generate()"]
  fb817b73_2ef2_452e_5f84_8bd519902eef -->|method| 3503f8d1_c017_d1eb_7c1c_ff77acd30fec

Relationship Graph

Source Code

drizzle-seed/src/services/Generators.ts lines 1599–1637

export class GenerateUniqueFirstName extends AbstractGenerator<{
	isUnique?: boolean;
}> {
	static override readonly entityKind: string = 'GenerateUniqueFirstName';

	private state: {
		genIndicesObj: GenerateUniqueInt;
	} | undefined;
	public override isUnique = true;

	override init({ count, seed }: { count: number; seed: number }) {
		if (count > firstNames.length) {
			throw new Error('count exceeds max number of unique first names.');
		}

		if (this.stringLength !== undefined && this.stringLength < maxFirstNameLength) {
			throw new Error(
				`You can't use first name generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxFirstNameLength}.`,
			);
		}

		const genIndicesObj = new GenerateUniqueInt({ minValue: 0, maxValue: firstNames.length - 1 });
		genIndicesObj.init({ count, seed });

		this.state = { genIndicesObj };
	}

	generate() {
		// names dataset contains about 30000 unique names.
		if (this.state === undefined) {
			throw new Error('state is not defined.');
		}

		const nameIdx = this.state.genIndicesObj.generate() as number;
		const name = firstNames[nameIdx] as string;

		return name;
	}
}

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free