MCPcopy
hub / github.com/drizzle-team/drizzle-orm / tests

Function tests

integration-tests/tests/sqlite/sqlite-common-cache.ts:103–380  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

101});
102
103export function tests() {
104 describe('common_cache', () => {
105 beforeEach(async (ctx) => {
106 const { db, dbGlobalCached } = ctx.cachedSqlite;
107 await db.run(sql`drop table if exists users`);
108 await db.run(sql`drop table if exists posts`);
109 await db.$cache?.invalidate({ tables: 'users' });
110 await dbGlobalCached.$cache?.invalidate({ tables: 'users' });
111 // public users
112 await db.run(
113 sql`
114 create table users (
115 id integer primary key AUTOINCREMENT,
116 name text not null,
117 verified integer not null default 0,
118 jsonb text,
119 created_at integer
120 )
121 `,
122 );
123 await db.run(
124 sql`
125 create table posts (
126 id integer primary key AUTOINCREMENT,
127 description text not null,
128 user_id int
129 )
130 `,
131 );
132 });
133
134 test('test force invalidate', async (ctx) => {
135 const { db } = ctx.cachedSqlite;
136
137 const spyInvalidate = vi.spyOn(db.$cache, 'invalidate');
138 await db.$cache?.invalidate({ tables: 'users' });
139 expect(spyInvalidate).toHaveBeenCalledTimes(1);
140 });
141
142 test('default global config - no cache should be hit', async (ctx) => {
143 const { db } = ctx.cachedSqlite;
144
145 // @ts-expect-error
146 const spyPut = vi.spyOn(db.$cache, 'put');
147 // @ts-expect-error
148 const spyGet = vi.spyOn(db.$cache, 'get');
149 // @ts-expect-error
150 const spyInvalidate = vi.spyOn(db.$cache, 'onMutate');
151
152 await db.select().from(usersTable);
153
154 expect(spyPut).toHaveBeenCalledTimes(0);
155 expect(spyGet).toHaveBeenCalledTimes(0);
156 expect(spyInvalidate).toHaveBeenCalledTimes(0);
157 });
158
159 test('default global config + enable cache on select: get, put', async (ctx) => {
160 const { db } = ctx.cachedSqlite;

Callers 3

libsql.test.tsFile · 0.90
d1.test.tsFile · 0.90

Calls 11

sqlFunction · 0.90
eqFunction · 0.90
aliasFunction · 0.90
runMethod · 0.45
fromMethod · 0.45
selectMethod · 0.45
$withCacheMethod · 0.45
valuesMethod · 0.45
insertMethod · 0.45
asMethod · 0.45
whereMethod · 0.45

Tested by

no test coverage detected