tests() — drizzle-orm Function Reference
Architecture documentation for the tests() function in singlestore-cache.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 9e6ad3a7_9dcb_b1d4_3392_962710879b70["tests()"] 366a8840_7045_c01f_5bc2_0e3563a812f0["singlestore-cache.ts"] 9e6ad3a7_9dcb_b1d4_3392_962710879b70 -->|defined in| 366a8840_7045_c01f_5bc2_0e3563a812f0 style 9e6ad3a7_9dcb_b1d4_3392_962710879b70 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
integration-tests/tests/singlestore/singlestore-cache.ts lines 112–390
export function tests() {
describe('common_cache', () => {
beforeEach(async (ctx) => {
const { db, dbGlobalCached } = ctx.cachedSingleStore;
await db.execute(sql`drop table if exists users`);
await db.execute(sql`drop table if exists posts`);
await db.$cache?.invalidate({ tables: 'users' });
await dbGlobalCached.$cache?.invalidate({ tables: 'users' });
// public users
await db.execute(
sql`
create table users (
id serial primary key,
name text not null,
verified boolean not null default false,
jsonb json,
created_at timestamp not null default now()
)
`,
);
await db.execute(
sql`
create table posts (
id serial primary key,
description text not null,
user_id int
)
`,
);
});
test('test force invalidate', async (ctx) => {
const { db } = ctx.cachedSingleStore;
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.cachedSingleStore;
// @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.cachedSingleStore;
// @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.cachedSingleStore;
// @ts-expect-error
const spyPut = vi.spyOn(db.$cache, 'put');
// @ts-expect-error
const spyGet = vi.spyOn(db.$cache, 'get');
// @ts-expect-error
Domain
Subdomains
Source
Frequently Asked Questions
What does tests() do?
tests() is a function in the drizzle-orm codebase, defined in integration-tests/tests/singlestore/singlestore-cache.ts.
Where is tests() defined?
tests() is defined in integration-tests/tests/singlestore/singlestore-cache.ts at line 112.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free