GenerateEmail Class — drizzle-orm Architecture
Architecture documentation for the GenerateEmail class in Generators.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 2d763d92_faa5_50ae_1f76_896734c85168["GenerateEmail"] e5cee001_0354_7e76_ef0a_06dca71dc8ce["Generators.ts"] 2d763d92_faa5_50ae_1f76_896734c85168 -->|defined in| e5cee001_0354_7e76_ef0a_06dca71dc8ce 07fecfcd_d3cc_41ab_9a1f_d57432f45a01["init()"] 2d763d92_faa5_50ae_1f76_896734c85168 -->|method| 07fecfcd_d3cc_41ab_9a1f_d57432f45a01 dbb1ade2_43d3_49d3_351f_cf7034140971["generate()"] 2d763d92_faa5_50ae_1f76_896734c85168 -->|method| dbb1ade2_43d3_49d3_351f_cf7034140971
Relationship Graph
Source Code
drizzle-seed/src/services/Generators.ts lines 1823–1885
export class GenerateEmail extends AbstractGenerator<{
arraySize?: number;
}> {
static override readonly entityKind: string = 'GenerateEmail';
private state: {
genIndicesObj: GenerateUniqueInt;
arraysToGenerateFrom: string[][];
} | undefined;
public override timeSpent: number = 0;
public override isUnique = true;
override init({ count, seed }: { count: number; seed: number }) {
super.init({ count, seed });
const domainsArray = emailDomains;
const adjectivesArray = adjectives;
const namesArray = firstNames;
const maxUniqueEmailsNumber = adjectivesArray.length * namesArray.length * domainsArray.length;
if (count > maxUniqueEmailsNumber) {
throw new RangeError(
`count exceeds max number of unique emails(${maxUniqueEmailsNumber}).`,
);
}
const maxEmailLength = maxAdjectiveLength + maxFirstNameLength + maxEmailDomainLength + 2;
if (this.stringLength !== undefined && this.stringLength < maxEmailLength) {
throw new Error(
`You can't use email generator with a db column length restriction of ${this.stringLength}. Set the maximum string length to at least ${maxEmailLength}.`,
);
}
const arraysToGenerateFrom = [adjectivesArray, namesArray, domainsArray];
const genIndicesObj = new GenerateUniqueInt({
minValue: 0,
maxValue: maxUniqueEmailsNumber - 1,
});
genIndicesObj.init({ count, seed });
this.state = { genIndicesObj, arraysToGenerateFrom };
}
generate() {
if (this.state === undefined) {
throw new Error('state is not defined.');
}
const t0 = new Date();
const emailIndex = this.state.genIndicesObj.generate() as number;
this.timeSpent += (Date.now() - t0.getTime()) / 1000;
const tokens = fastCartesianProduct(
this.state.arraysToGenerateFrom,
emailIndex,
) as string[];
const [adjective, name, domain] = [tokens[0] as string, tokens[1] as string, tokens[2] as string];
const email = `${adjective}_${name.toLowerCase()}@${domain}`;
return email;
}
}
Domain
Defined In
Source
Frequently Asked Questions
What is the GenerateEmail class?
GenerateEmail is a class in the drizzle-orm codebase, defined in drizzle-seed/src/services/Generators.ts.
Where is GenerateEmail defined?
GenerateEmail is defined in drizzle-seed/src/services/Generators.ts at line 1823.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free