Home / Class/ GenerateStringV2 Class — drizzle-orm Architecture

GenerateStringV2 Class — drizzle-orm Architecture

Architecture documentation for the GenerateStringV2 class in v2.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  c19990f2_d916_926e_6b46_f2be0233936b["GenerateStringV2"]
  78da996c_90cc_6154_e2a5_4b2639015e5b["v2.ts"]
  c19990f2_d916_926e_6b46_f2be0233936b -->|defined in| 78da996c_90cc_6154_e2a5_4b2639015e5b
  5cecc64c_e513_e3f2_0856_2895b372b093["init()"]
  c19990f2_d916_926e_6b46_f2be0233936b -->|method| 5cecc64c_e513_e3f2_0856_2895b372b093
  fa2bad95_1025_4449_3bb0_992ea8fb7839["generate()"]
  c19990f2_d916_926e_6b46_f2be0233936b -->|method| fa2bad95_1025_4449_3bb0_992ea8fb7839

Relationship Graph

Source Code

drizzle-seed/src/services/versioning/v2.ts lines 112–169

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

	private state: {
		rng: prand.RandomGenerator;
		minStringLength: number;
		maxStringLength: number;
	} | undefined;
	override uniqueVersionOfGen = GenerateUniqueStringV2;

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

		let minStringLength = 7;
		let maxStringLength = 20;
		if (this.stringLength !== undefined) {
			maxStringLength = this.stringLength;
			if (maxStringLength === 1) minStringLength = maxStringLength;
			if (maxStringLength < minStringLength) minStringLength = 1;
		}

		const rng = prand.xoroshiro128plus(seed);
		this.state = { rng, minStringLength, maxStringLength };
	}

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

		const minStringLength = this.state.minStringLength,
			maxStringLength = this.state.maxStringLength;
		const stringChars = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
		let idx: number,
			strLength: number,
			currStr: string;

		currStr = '';
		[strLength, this.state.rng] = prand.uniformIntDistribution(
			minStringLength,
			maxStringLength,
			this.state.rng,
		);
		for (let j = 0; j < strLength; j++) {
			[idx, this.state.rng] = prand.uniformIntDistribution(
				0,
				stringChars.length - 1,
				this.state.rng,
			);
			currStr += stringChars[idx];
		}
		return currStr;
	}
}

Domain

Frequently Asked Questions

What is the GenerateStringV2 class?
GenerateStringV2 is a class in the drizzle-orm codebase, defined in drizzle-seed/src/services/versioning/v2.ts.
Where is GenerateStringV2 defined?
GenerateStringV2 is defined in drizzle-seed/src/services/versioning/v2.ts at line 112.

Analyze Your Own Codebase

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

Try Supermodel Free