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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”() => T
The callback to run inside the scope. Its return value is forwarded back to the caller.
cache?
Section titled “cache?”LookupCache = ...
Optional pre-existing cache to install. Defaults to a fresh empty cache.
Returns
Section titled “Returns”T
Example
Section titled “Example”// 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});