Home / Function/ init() — drizzle-orm Function Reference

init() — drizzle-orm Function Reference

Architecture documentation for the init() function in Generators.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  edb960eb_5f23_9fea_056f_ebda33033699["init()"]
  141ee0d6_adc4_0b1e_03c3_6b833b27c8ea["GenerateUniqueInterval"]
  edb960eb_5f23_9fea_056f_ebda33033699 -->|defined in| 141ee0d6_adc4_0b1e_03c3_6b833b27c8ea
  style edb960eb_5f23_9fea_056f_ebda33033699 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-seed/src/services/Generators.ts lines 1368–1394

	override init({ count, seed }: { count: number; seed: number }) {
		const allFields = ['year', 'month', 'day', 'hour', 'minute', 'second'];
		let fieldsToGenerate: string[] = allFields;

		if (this.params.fields !== undefined && this.params.fields?.includes(' to ')) {
			const tokens = this.params.fields.split(' to ');
			const endIdx = allFields.indexOf(tokens[1]!);
			fieldsToGenerate = allFields.slice(0, endIdx + 1);
		} else if (this.params.fields !== undefined) {
			const endIdx = allFields.indexOf(this.params.fields);
			fieldsToGenerate = allFields.slice(0, endIdx + 1);
		}

		let maxUniqueIntervalsNumber = 1;
		for (const field of fieldsToGenerate) {
			const from = this.config[field]!.from, to = this.config[field]!.to;
			maxUniqueIntervalsNumber *= from - to + 1;
		}

		if (count > maxUniqueIntervalsNumber) {
			throw new RangeError(`count exceeds max number of unique intervals(${maxUniqueIntervalsNumber})`);
		}

		const rng = prand.xoroshiro128plus(seed);
		const intervalSet = new Set<string>();
		this.state = { rng, fieldsToGenerate, intervalSet };
	}

Domain

Subdomains

Frequently Asked Questions

What does init() do?
init() is a function in the drizzle-orm codebase, defined in drizzle-seed/src/services/Generators.ts.
Where is init() defined?
init() is defined in drizzle-seed/src/services/Generators.ts at line 1368.

Analyze Your Own Codebase

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

Try Supermodel Free