• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

u-wave / core / 19327648999

13 Nov 2025 09:59AM UTC coverage: 85.015%. First build
19327648999

Pull #657

github

web-flow
Merge bb29c4618 into cc369fe03
Pull Request #657: SQLite Key-value store to replace Redis

953 of 1129 branches covered (84.41%)

Branch coverage included in aggregate %.

173 of 228 new or added lines in 7 files covered. (75.88%)

10002 of 11757 relevant lines covered (85.07%)

92.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.31
/src/KeyValue.js
1
import { fromJson, json, jsonb } from './utils/sqlite.js';
1✔
2

1✔
3
export default class KeyValue {
1✔
4
  #db;
144✔
5

144✔
6
  /** @param {import('./schema.js').Kysely} db */
144✔
7
  constructor(db) {
144✔
8
    this.#db = db;
144✔
9
  }
144✔
10

144✔
11
  /** @param {string} key */
144✔
12
  async get(key, db = this.#db) {
144✔
13
    const row = await db.selectFrom('keyval')
145✔
14
      .select((eb) => json(eb.ref('value')).as('value'))
145✔
15
      .where('key', '=', key)
145✔
16
      .executeTakeFirst();
145✔
17
    if (row == null) {
145✔
18
      return undefined;
60✔
19
    }
60✔
20
    return fromJson(row.value);
85✔
21
  }
145✔
22

144✔
23
  /**
144✔
24
   * @param {string} key
144✔
25
   * @param {import('type-fest').JsonValue} value
144✔
26
   */
144✔
27
  async set(key, value, db = this.#db) {
144✔
28
    await db.insertInto('keyval')
65✔
29
      .values({ key, value: jsonb(value) })
65✔
30
      .onConflict((oc) => oc.column('key').doUpdateSet({ value: jsonb(value) }))
65✔
31
      .execute();
65✔
32
  }
65✔
33

144✔
34
  /**
144✔
35
   * Delete a key, returning its previous value if any.
144✔
36
   *
144✔
37
   * @param {string} key
144✔
38
   * @returns {Promise<import('type-fest').JsonValue | undefined>}
144✔
39
   */
144✔
40
  async delete(key, db = this.#db) {
144✔
41
    const existing = await db.deleteFrom('keyval')
30✔
42
      .where('key', '=', key)
30✔
43
      .returning((eb) => json(eb.ref('value')).as('value'))
30✔
44
      .executeTakeFirst();
30✔
45

30✔
46
    if (existing == null) {
30✔
47
      return undefined;
30✔
48
    }
30✔
NEW
49

×
NEW
50
    return fromJson(existing.value);
×
51
  }
30✔
52
}
144✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc