createUserLoader
Function: createUserLoader()
createUserLoader(
db,cache,perf?):DataLoader<string, {addressLine1:string|null;addressLine2:string|null;avatarMimeType:string|null;avatarName:string|null;birthDate:Date|null;city:string|null;countryCode:string|null;createdAt:Date;creatorId:string|null;description:string|null;educationGrade:string|null;emailAddress:string;employmentStatus:string|null;failedLoginAttempts:number;homePhoneNumber:string|null;id:string;isEmailAddressVerified:boolean;lastFailedLoginAt:Date|null;lockedUntil:Date|null;maritalStatus:string|null;mobilePhoneNumber:string|null;name:string;natalSex:string|null;naturalLanguageCode:string|null;passwordHash:string;postalCode:string|null;role:string;state:string|null;updatedAt:Date|null;updaterId:string|null;workPhoneNumber:string|null; } |null,string>
Defined in: src/utilities/dataloaders/userLoader.ts:36
Creates a DataLoader for batching user lookups by ID. When a cache service is provided, wraps the batch function with cache-first logic. When a performance tracker is provided, wraps the batch function with performance metrics.
Parameters
db
The Drizzle client instance for database operations.
cache
Optional cache service for cache-first lookups. Pass null to disable caching.
CacheService | null
perf?
Optional performance tracker for monitoring database operation durations.
Returns
DataLoader<string, { addressLine1: string | null; addressLine2: string | null; avatarMimeType: string | null; avatarName: string | null; birthDate: Date | null; city: string | null; countryCode: string | null; createdAt: Date; creatorId: string | null; description: string | null; educationGrade: string | null; emailAddress: string; employmentStatus: string | null; failedLoginAttempts: number; homePhoneNumber: string | null; id: string; isEmailAddressVerified: boolean; lastFailedLoginAt: Date | null; lockedUntil: Date | null; maritalStatus: string | null; mobilePhoneNumber: string | null; name: string; natalSex: string | null; naturalLanguageCode: string | null; passwordHash: string; postalCode: string | null; role: string; state: string | null; updatedAt: Date | null; updaterId: string | null; workPhoneNumber: string | null; } | null, string>
A DataLoader that batches and caches user lookups within a single request.
Example
const userLoader = createUserLoader(drizzleClient, cacheService, perfTracker);
const user = await userLoader.load(userId);