tests() — drizzle-orm Function Reference
Architecture documentation for the tests() function in sqlite-common-cache.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 1fb7c294_0b28_add4_155b_1659a26ba166["tests()"] 7f26f618_3381_4763_89e6_6503ea1e3ebd["sqlite-common-cache.ts"] 1fb7c294_0b28_add4_155b_1659a26ba166 -->|defined in| 7f26f618_3381_4763_89e6_6503ea1e3ebd style 1fb7c294_0b28_add4_155b_1659a26ba166 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
integration-tests/tests/sqlite/sqlite-common-cache.ts lines 103–380
export function tests() {
describe('common_cache', () => {
beforeEach(async (ctx) => {
const { db, dbGlobalCached } = ctx.cachedSqlite;
await db.run(sql`drop table if exists users`);
await db.run(sql`drop table if exists posts`);
await db.$cache?.invalidate({ tables: 'users' });
await dbGlobalCached.$cache?.invalidate({ tables: 'users' });
// public users
await db.run(
sql`
create table users (
id integer primary key AUTOINCREMENT,
name text not null,
verified integer not null default 0,
jsonb text,
created_at integer
)
`,
);
await db.run(
sql`
create table posts (
id integer primary key AUTOINCREMENT,
description text not null,
user_id int
)
`,
);
});
test('test force invalidate', async (ctx) => {
const { db } = ctx.cachedSqlite;
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.cachedSqlite;
// @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.cachedSqlite;
// @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.cachedSqlite;
// @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/sqlite/sqlite-common-cache.ts.
Where is tests() defined?
tests() is defined in integration-tests/tests/sqlite/sqlite-common-cache.ts at line 103.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free