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

checks() — drizzle-orm Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  b3c3a50c_06a8_f41b_767f_088142c03301["checks()"]
  ebde298b_d6a3_4062_c1b1_f4cfa069de7b["GenerateValuesFromArray"]
  b3c3a50c_06a8_f41b_767f_088142c03301 -->|defined in| ebde298b_d6a3_4062_c1b1_f4cfa069de7b
  81c8cbf9_2fb1_f2b8_0172_4f36943e36bf["init()"]
  81c8cbf9_2fb1_f2b8_0172_4f36943e36bf -->|calls| b3c3a50c_06a8_f41b_767f_088142c03301
  1bc6ff75_57cd_61d0_a164_cb68e7e797c4["isObject()"]
  b3c3a50c_06a8_f41b_767f_088142c03301 -->|calls| 1bc6ff75_57cd_61d0_a164_cb68e7e797c4
  style b3c3a50c_06a8_f41b_767f_088142c03301 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-seed/src/services/Generators.ts lines 212–281

	checks({ count }: { count: number }) {
		const { values } = this.params;
		const { maxRepeatedValuesCount, notNull, isUnique } = this;
		if (values.length === 0) {
			throw new Error('Values length equals zero.');
		}

		if (
			isObject(values[0])
			&& !(values as { weight: number; values: any[] }[]).every((val) => val.values.length !== 0)
		) {
			throw new Error('One of weighted values length equals zero.');
		}

		if (
			maxRepeatedValuesCount !== undefined && (
				(typeof maxRepeatedValuesCount === 'number' && maxRepeatedValuesCount <= 0)
				|| (typeof maxRepeatedValuesCount === 'object' && !maxRepeatedValuesCount
					.every((obj) =>
						(typeof obj.count) === 'number'
							? (obj.count as number) > 0
							: (obj.count as number[]).every((count) => count > 0)
					))
			)
		) {
			throw new Error('maxRepeatedValuesCount should be greater than zero.');
		}

		let allValuesCount = values.length;
		if (isObject(values[0])) {
			allValuesCount = (values as { values: any[] }[]).reduce((acc, currVal) => acc + currVal.values.length, 0);
		}

		if (
			notNull === true
			&& maxRepeatedValuesCount !== undefined
			&& (
				(!isObject(values[0]) && typeof maxRepeatedValuesCount === 'number'
					&& maxRepeatedValuesCount * values.length < count)
				|| (isObject(values[0]) && typeof maxRepeatedValuesCount === 'number'
					&& maxRepeatedValuesCount * allValuesCount < count)
			)
		) {
			throw new Error("Can't fill notNull column with null values.");
		}

		if (
			isUnique === true && maxRepeatedValuesCount !== undefined && (
				(typeof maxRepeatedValuesCount === 'number' && maxRepeatedValuesCount > 1)
				|| (typeof maxRepeatedValuesCount === 'object' && !maxRepeatedValuesCount
					.every((obj) =>
						(typeof obj.count) === 'number'
							? obj.count === 1
							: (obj.count as number[]).every((count) => count === 1)
					))
			)
		) {
			throw new Error("Can't be greater than 1 if column is unique.");
		}

		if (
			isUnique === true && notNull === true && (
				(!isObject(values[0]) && values.length < count)
				|| (isObject(values[0]) && allValuesCount < count)
			)
		) {
			// console.log(maxRepeatedValuesCount, values.length, allValuesCount, count)
			throw new Error('There are no enough values to fill unique column.');
		}
	}

Domain

Subdomains

Calls

Called By

Frequently Asked Questions

What does checks() do?
checks() is a function in the drizzle-orm codebase, defined in drizzle-seed/src/services/Generators.ts.
Where is checks() defined?
checks() is defined in drizzle-seed/src/services/Generators.ts at line 212.
What does checks() call?
checks() calls 1 function(s): isObject.
What calls checks()?
checks() is called by 1 function(s): init.

Analyze Your Own Codebase

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

Try Supermodel Free