GenerateUniqueInterval Class — drizzle-orm Architecture
Architecture documentation for the GenerateUniqueInterval class in Generators.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 141ee0d6_adc4_0b1e_03c3_6b833b27c8ea["GenerateUniqueInterval"] e5cee001_0354_7e76_ef0a_06dca71dc8ce["Generators.ts"] 141ee0d6_adc4_0b1e_03c3_6b833b27c8ea -->|defined in| e5cee001_0354_7e76_ef0a_06dca71dc8ce edb960eb_5f23_9fea_056f_ebda33033699["init()"] 141ee0d6_adc4_0b1e_03c3_6b833b27c8ea -->|method| edb960eb_5f23_9fea_056f_ebda33033699 db3c296b_8d94_8ab0_14d0_e0fd564dd748["generate()"] 141ee0d6_adc4_0b1e_03c3_6b833b27c8ea -->|method| db3c296b_8d94_8ab0_14d0_e0fd564dd748
Relationship Graph
Source Code
drizzle-seed/src/services/Generators.ts lines 1316–1420
export class GenerateUniqueInterval extends AbstractGenerator<{
fields?:
| 'year'
| 'month'
| 'day'
| 'hour'
| 'minute'
| 'second'
| 'year to month'
| 'day to hour'
| 'day to minute'
| 'day to second'
| 'hour to minute'
| 'hour to second'
| 'minute to second';
isUnique?: boolean;
}> {
static override readonly 'entityKind': string = 'GenerateUniqueInterval';
private state: {
rng: prand.RandomGenerator;
fieldsToGenerate: string[];
intervalSet: Set<string>;
} | undefined;
public override isUnique = true;
private config: { [key: string]: { from: number; to: number } } = {
year: {
from: 0,
to: 5,
},
month: {
from: 0,
to: 12,
},
day: {
from: 1,
to: 29,
},
hour: {
from: 0,
to: 24,
},
minute: {
from: 0,
to: 60,
},
second: {
from: 0,
to: 60,
},
};
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 };
}
generate() {
Domain
Defined In
Source
Frequently Asked Questions
What is the GenerateUniqueInterval class?
GenerateUniqueInterval is a class in the drizzle-orm codebase, defined in drizzle-seed/src/services/Generators.ts.
Where is GenerateUniqueInterval defined?
GenerateUniqueInterval is defined in drizzle-seed/src/services/Generators.ts at line 1316.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free