tests() — drizzle-orm Function Reference
Architecture documentation for the tests() function in pg-common-cache.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 77f58cd1_7a44_c716_4519_0bad2b6a13b9["tests()"] d5adb833_7300_4c6b_c5fd_f6bf2ac5b0d3["pg-common-cache.ts"] 77f58cd1_7a44_c716_4519_0bad2b6a13b9 -->|defined in| d5adb833_7300_4c6b_c5fd_f6bf2ac5b0d3 style 77f58cd1_7a44_c716_4519_0bad2b6a13b9 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
integration-tests/tests/pg/pg-common-cache.ts lines 108–400
export function tests() {
describe('common', () => {
beforeEach(async (ctx) => {
const { db, dbGlobalCached } = ctx.cachedPg;
await db.execute(sql`drop schema if exists public cascade`);
await db.$cache?.invalidate({ tables: 'users' });
await dbGlobalCached.$cache?.invalidate({ tables: 'users' });
await db.execute(sql`create schema public`);
// public users
await db.execute(
sql`
create table users (
id serial primary key,
name text not null,
verified boolean not null default false,
jsonb jsonb,
created_at timestamptz not null default now()
)
`,
);
});
test('test force invalidate', async (ctx) => {
const { db } = ctx.cachedPg;
const spyInvalidate = vi.spyOn(db.$cache, 'invalidate');
await db.$cache?.invalidate({ tables: 'users' });
expect(spyInvalidate).toHaveBeenCalledTimes(1);
});
test('default global config - no cache should be hit', async (ctx) => {
const { db } = ctx.cachedPg;
// @ts-expect-error
const spyPut = vi.spyOn(db.$cache, 'put');
// @ts-expect-error
const spyGet = vi.spyOn(db.$cache, 'get');
// @ts-expect-error
const spyInvalidate = vi.spyOn(db.$cache, 'onMutate');
await db.select().from(usersTable);
expect(spyPut).toHaveBeenCalledTimes(0);
expect(spyGet).toHaveBeenCalledTimes(0);
expect(spyInvalidate).toHaveBeenCalledTimes(0);
});
test('default global config + enable cache on select: get, put', async (ctx) => {
const { db } = ctx.cachedPg;
// @ts-expect-error
const spyPut = vi.spyOn(db.$cache, 'put');
// @ts-expect-error
const spyGet = vi.spyOn(db.$cache, 'get');
// @ts-expect-error
const spyInvalidate = vi.spyOn(db.$cache, 'onMutate');
await db.select().from(usersTable).$withCache();
expect(spyPut).toHaveBeenCalledTimes(1);
expect(spyGet).toHaveBeenCalledTimes(1);
expect(spyInvalidate).toHaveBeenCalledTimes(0);
});
test('default global config + enable cache on select + write: get, put, onMutate', async (ctx) => {
const { db } = ctx.cachedPg;
// @ts-expect-error
const spyPut = vi.spyOn(db.$cache, 'put');
// @ts-expect-error
const spyGet = vi.spyOn(db.$cache, 'get');
// @ts-expect-error
const spyInvalidate = vi.spyOn(db.$cache, 'onMutate');
await db.select().from(usersTable).$withCache({ config: { ex: 1 } });
expect(spyPut).toHaveBeenCalledTimes(1);
expect(spyGet).toHaveBeenCalledTimes(1);
expect(spyInvalidate).toHaveBeenCalledTimes(0);
spyPut.mockClear();
Domain
Subdomains
Source
Frequently Asked Questions
What does tests() do?
tests() is a function in the drizzle-orm codebase, defined in integration-tests/tests/pg/pg-common-cache.ts.
Where is tests() defined?
tests() is defined in integration-tests/tests/pg/pg-common-cache.ts at line 108.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free