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
  b3d8df90_567b_aad8_8bde_70a8cb190d3a["init()"]
  e2c413a5_f1cc_23b4_acd7_ab626330b0d7["GenerateUniqueInt"]
  b3d8df90_567b_aad8_8bde_70a8cb190d3a -->|defined in| e2c413a5_f1cc_23b4_acd7_ab626330b0d7
  style b3d8df90_567b_aad8_8bde_70a8cb190d3a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-seed/src/services/Generators.ts lines 662–698

	override init({ count, seed }: { count: number; seed: number }) {
		const rng = prand.xoroshiro128plus(seed);
		let { minValue, maxValue } = this.params;

		if (maxValue === undefined) {
			maxValue = count * 10;
		}
		if (minValue === undefined) {
			minValue = -maxValue;
		}

		const intervals = [[minValue, maxValue]];

		const integersCount = new Map();

		if (typeof minValue === 'bigint' && typeof maxValue === 'bigint') {
			if (this.skipCheck === false && maxValue - minValue + BigInt(1) < count) {
				throw new Error(
					'count exceeds max number of unique integers in given range(min, max), try to make range wider.',
				);
			}
		} else 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);
			if (this.skipCheck === false && maxValue - minValue + 1 < count) {
				throw new Error(
					'count exceeds max number of unique integers in given range(min, max), try to make range wider.',
				);
			}
		} else {
			throw new Error(
				'minValue and maxValue should be the same type.',
			);
		}

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

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 662.

Analyze Your Own Codebase

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

Try Supermodel Free