Home / Class/ GenerateUniqueCompanyName Class — drizzle-orm Architecture

GenerateUniqueCompanyName Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  d099dc27_7cb1_ca3a_a106_42456c7d079a["GenerateUniqueCompanyName"]
  e5cee001_0354_7e76_ef0a_06dca71dc8ce["Generators.ts"]
  d099dc27_7cb1_ca3a_a106_42456c7d079a -->|defined in| e5cee001_0354_7e76_ef0a_06dca71dc8ce
  edb57f9c_b176_e9e2_07e4_4350a972cb3d["init()"]
  d099dc27_7cb1_ca3a_a106_42456c7d079a -->|method| edb57f9c_b176_e9e2_07e4_4350a972cb3d
  4cad4f03_d6fa_5c40_fb6a_ce3cb188d9d7["generate()"]
  d099dc27_7cb1_ca3a_a106_42456c7d079a -->|method| 4cad4f03_d6fa_5c40_fb6a_ce3cb188d9d7

Relationship Graph

Source Code

drizzle-seed/src/services/Generators.ts lines 2660–2766

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

	private state: {
		rng: prand.RandomGenerator;
		templates: {
			template: string;
			placeholdersCount: number;
			indicesGen: GenerateUniqueInt;
			maxUniqueCompanyNameNumber: number;
			count: number;
			arraysToChooseFrom: string[][];
		}[];
	} | undefined;
	public override isUnique = true;

	override init({ count, seed }: { count: number; seed: number }) {
		const maxUniqueCompanyNameNumber = lastNames.length * companyNameSuffixes.length + Math.pow(lastNames.length, 2)
			+ Math.pow(lastNames.length, 2) + Math.pow(lastNames.length, 3);
		if (count > maxUniqueCompanyNameNumber) {
			throw new RangeError(
				`count exceeds max number of unique company names(${maxUniqueCompanyNameNumber}).`,
			);
		}

		// max( { template: '#', placeholdersCount: 1 }, { template: '#, # and #', placeholdersCount: 3 } )
		const maxCompanyNameLength = Math.max(
			maxLastNameLength + maxCompanyNameSuffixLength + 1,
			3 * maxLastNameLength + 7,
		);
		if (this.stringLength !== undefined && this.stringLength < maxCompanyNameLength) {
			throw new Error(
				`You can't use company name generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxCompanyNameLength}.`,
			);
		}

		const rng = prand.xoroshiro128plus(seed);
		// when count reach maxUniqueCompanyNameNumber template will be deleted from array
		const templates = [
			{
				template: '# - #',
				placeholdersCount: 1,
				indicesGen: new GenerateUniqueInt({ minValue: 0, maxValue: lastNames.length * companyNameSuffixes.length - 1 }),
				maxUniqueCompanyNameNumber: lastNames.length * companyNameSuffixes.length,
				count: 0,
				arraysToChooseFrom: [lastNames, companyNameSuffixes],
			},
			{
				template: '# - #',
				placeholdersCount: 2,
				indicesGen: new GenerateUniqueInt({ minValue: 0, maxValue: Math.pow(lastNames.length, 2) - 1 }),
				maxUniqueCompanyNameNumber: Math.pow(lastNames.length, 2),
				count: 0,
				arraysToChooseFrom: [lastNames, lastNames],
			},
			{
				template: '# and #',
				placeholdersCount: 2,
				indicesGen: new GenerateUniqueInt({ minValue: 0, maxValue: Math.pow(lastNames.length, 2) - 1 }),
				maxUniqueCompanyNameNumber: Math.pow(lastNames.length, 2),
				count: 0,
				arraysToChooseFrom: [lastNames, lastNames],
			},
			{
				template: '#, # and #',
				placeholdersCount: 3,
				indicesGen: new GenerateUniqueInt({ minValue: 0, maxValue: Math.pow(lastNames.length, 3) - 1 }),
				maxUniqueCompanyNameNumber: Math.pow(lastNames.length, 3),
				count: 0,
				arraysToChooseFrom: [lastNames, lastNames, lastNames],
			},
		];

		for (const templateObj of templates) {
			templateObj.indicesGen.skipCheck = true;
			templateObj.indicesGen.init({ count, seed });
		}

		this.state = { rng, templates };
	}

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free