Home / Class/ GenerateStreetAddress Class — drizzle-orm Architecture

GenerateStreetAddress Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  91af7e58_7645_9a50_e553_0b1bb5526ad0["GenerateStreetAddress"]
  e5cee001_0354_7e76_ef0a_06dca71dc8ce["Generators.ts"]
  91af7e58_7645_9a50_e553_0b1bb5526ad0 -->|defined in| e5cee001_0354_7e76_ef0a_06dca71dc8ce
  9cbed0f6_8893_bc4e_258b_191c2580ec48["init()"]
  91af7e58_7645_9a50_e553_0b1bb5526ad0 -->|method| 9cbed0f6_8893_bc4e_258b_191c2580ec48
  96e7c9f7_6cec_ab45_57a2_641ce488460e["generate()"]
  91af7e58_7645_9a50_e553_0b1bb5526ad0 -->|method| 96e7c9f7_6cec_ab45_57a2_641ce488460e

Relationship Graph

Source Code

drizzle-seed/src/services/Generators.ts lines 2194–2242

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

	private state: {
		rng: prand.RandomGenerator;
		possStreetNames: string[][];
	} | undefined;
	override uniqueVersionOfGen = GenerateUniqueStreetAddress;

	override init({ count, seed }: { count: number; seed: number }) {
		super.init({ count, seed });

		const rng = prand.xoroshiro128plus(seed);
		const possStreetNames = [firstNames, lastNames];

		const maxStreetAddressLength = 4 + Math.max(maxFirstNameLength, maxLastNameLength) + 1 + maxStreetSuffixLength;
		if (this.stringLength !== undefined && this.stringLength < maxStreetAddressLength) {
			throw new Error(
				`You can't use street address generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxStreetAddressLength}.`,
			);
		}

		this.state = { rng, possStreetNames };
	}

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

		let idx, streetBaseNameIdx, streetSuffixIdx, streetNumber;
		[idx, this.state.rng] = prand.uniformIntDistribution(0, this.state.possStreetNames.length - 1, this.state.rng);

		[streetBaseNameIdx, this.state.rng] = prand.uniformIntDistribution(
			0,
			this.state.possStreetNames[idx]!.length - 1,
			this.state.rng,
		);
		[streetSuffixIdx, this.state.rng] = prand.uniformIntDistribution(0, streetSuffix.length - 1, this.state.rng);
		const streetName = `${this.state.possStreetNames[idx]![streetBaseNameIdx]} ${streetSuffix[streetSuffixIdx]}`;

		[streetNumber, this.state.rng] = prand.uniformIntDistribution(1, 999, this.state.rng);

		return `${streetNumber} ${streetName}`;
	}
}

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free