Skip to content

Commit 5d65ce4

Browse files
committed
test: improve coverage by adding missing cases
1 parent b08075e commit 5d65ce4

File tree

4 files changed

+383
-311
lines changed

4 files changed

+383
-311
lines changed

bunfig.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[test]
2+
coverage = true
3+
coverageThreshold = 0.9

index.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ export default async function bunSqliteStore({
8989
}
9090
};
9191

92-
const get = async <T>(key: string): Promise<T | undefined> => {
93-
await purgeExpired();
94-
const statement = db.prepare(
95-
`SELECT * FROM ${name} WHERE key = ? AND expire_at > ? LIMIT 1`
96-
);
97-
const rows = statement.all(key, Date.now()) as CacheRow[];
98-
if (rows.length > 0) {
99-
return serializerAdapter.deserialize(rows[0].val) as T;
100-
}
101-
};
102-
10392
const set = async (key: string, value: unknown, ttl?: number) => {
10493
const ttlValue = ttl !== undefined ? ttl * 1000 : defaultTtl;
10594
if (ttlValue < 0) {
@@ -119,6 +108,22 @@ export default async function bunSqliteStore({
119108
statement.run(key, serializedVal, Date.now(), expireAt);
120109
};
121110

111+
const get = async <T>(key: string): Promise<T | undefined> => {
112+
await purgeExpired();
113+
const statement = db.prepare(
114+
`SELECT * FROM ${name} WHERE key = ? AND expire_at > ? LIMIT 1`
115+
);
116+
const rows = statement.all(key, Date.now()) as CacheRow[];
117+
if (rows.length > 0) {
118+
return serializerAdapter.deserialize(rows[0].val) as T;
119+
}
120+
};
121+
122+
const del = async (key: string) => {
123+
const statement = db.prepare(`DELETE FROM ${name} WHERE key = ?`);
124+
statement.run(key);
125+
};
126+
122127
const mset = async (pairs: [string, unknown][], ttl?: number) => {
123128
const ttlValue = ttl !== undefined ? ttl * 1000 : defaultTtl;
124129
if (ttlValue < 0) {
@@ -152,11 +157,6 @@ export default async function bunSqliteStore({
152157
});
153158
};
154159

155-
const del = async (key: string) => {
156-
const statement = db.prepare(`DELETE FROM ${name} WHERE key = ?`);
157-
statement.run(key);
158-
};
159-
160160
const mdel = async (...keys: string[]) => {
161161
const placeholders = keys.map(() => '?').join(', ');
162162
const statement = db.prepare(`DELETE FROM ${name} WHERE key IN (${placeholders})`);

tests/cacheManager.test.ts

Lines changed: 0 additions & 295 deletions
This file was deleted.

0 commit comments

Comments
 (0)