Home / Class/ GenerateInt Class — drizzle-orm Architecture

GenerateInt Class — drizzle-orm Architecture

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

Entity Profile

Dependency Diagram

graph TD
  dc015a24_3620_97c4_4fea_d3bbba712474["GenerateInt"]
  e5cee001_0354_7e76_ef0a_06dca71dc8ce["Generators.ts"]
  dc015a24_3620_97c4_4fea_d3bbba712474 -->|defined in| e5cee001_0354_7e76_ef0a_06dca71dc8ce
  e2a4f454_fadb_af71_2195_1b77a1675473["init()"]
  dc015a24_3620_97c4_4fea_d3bbba712474 -->|method| e2a4f454_fadb_af71_2195_1b77a1675473
  b51e59e1_f7e1_e692_d984_f4e8dae2e50d["generate()"]
  dc015a24_3620_97c4_4fea_d3bbba712474 -->|method| b51e59e1_f7e1_e692_d984_f4e8dae2e50d

Relationship Graph

Source Code

drizzle-seed/src/services/Generators.ts lines 574–641

export class GenerateInt extends AbstractGenerator<{
	minValue?: number | bigint;
	maxValue?: number | bigint;
	isUnique?: boolean;
	arraySize?: number;
}> {
	static override readonly entityKind: string = 'GenerateInt';

	private state: {
		rng: prand.RandomGenerator;
		minValue: number | bigint;
		maxValue: number | bigint;
	} | undefined;
	override uniqueVersionOfGen = GenerateUniqueInt;

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

		let { minValue, maxValue } = this.params;

		if (maxValue === undefined) {
			maxValue = 1000;
		}

		if (minValue === undefined) {
			minValue = -maxValue;
		}

		if (typeof minValue === 'number' && typeof maxValue === 'number') {
			minValue = minValue >= 0 ? Math.ceil(minValue) : Math.floor(minValue);
			maxValue = maxValue >= 0 ? Math.floor(maxValue) : Math.ceil(maxValue);
		}

		const rng = prand.xoroshiro128plus(seed);

		this.state = { rng, minValue, maxValue };
	}

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

		let value: number | bigint;
		if (typeof this.state.minValue === 'bigint' && typeof this.state.maxValue === 'bigint') {
			[value, this.state.rng] = prand.uniformBigIntDistribution(
				this.state.minValue,
				this.state.maxValue,
				this.state.rng,
			);
		} else {
			[value, this.state.rng] = prand.uniformIntDistribution(
				this.state.minValue as number,
				this.state.maxValue as number,
				this.state.rng,
			);
		}

		if (this.dataType === 'string') {
			return String(value);
		}

		if (this.dataType === 'bigint') {
			value = BigInt(value);
		}
		return value;
	}
}

Domain

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free