Skip to content

runWithLookupCache

runWithLookupCache<T>(fn, cache?): T

Defined in: packages/db/src/utils.ts:106

Runs fn inside a fresh per-request lookup cache scope.

Use this when you need to reuse a single Db across multiple logical requests (e.g. in tests that insert new grants mid-run) and want each logical request to see a clean cache. All nested Db operations inside fn (and any async work they start) share the same cache.

T

() => T

The callback to run inside the scope. Its return value is forwarded back to the caller.

LookupCache = ...

Optional pre-existing cache to install. Defaults to a fresh empty cache.

T

// Test setup reusing a single Db:
const db = createDb({ ... });
await runWithLookupCache(async () => {
await db.insert(friendGrants).values(...).run();
await db.query(posts).findMany().run(); // sees the new grant
});