Clean up and fixes
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import Database from 'better-sqlite3';
|
||||
import { decodeExtendedJsonObject, encodeExtendedJsonObject } from '../utils/ext-json.js';
|
||||
import { decodeExtendedJson, encodeExtendedJson } from '../utils/ext-json.js';
|
||||
|
||||
export class Storage {
|
||||
static async create(dbPath: string): Promise<Storage> {
|
||||
@@ -35,10 +35,12 @@ export class Storage {
|
||||
|
||||
async set(key: string, value: any): Promise<void> {
|
||||
// Encode the extended json object
|
||||
const encodedValue = encodeExtendedJsonObject(value);
|
||||
const encodedValue = encodeExtendedJson(value);
|
||||
console.log('Encoded value:', encodedValue);
|
||||
|
||||
// Insert or replace the value into the database with full key (including basePath)
|
||||
const fullKey = this.getFullKey(key);
|
||||
console.log('Full key:', fullKey);
|
||||
this.database.prepare('INSERT OR REPLACE INTO storage (key, value) VALUES (?, ?)').run(fullKey, encodedValue);
|
||||
}
|
||||
|
||||
@@ -68,7 +70,7 @@ export class Storage {
|
||||
// Decode the extended json objects and strip basePath from keys
|
||||
return filteredRows.map(row => ({
|
||||
key: this.stripBasePath(row.key),
|
||||
value: decodeExtendedJsonObject(row.value)
|
||||
value: decodeExtendedJson(row.value)
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -81,7 +83,7 @@ export class Storage {
|
||||
if (!row) return null;
|
||||
|
||||
// Decode the extended json object
|
||||
return decodeExtendedJsonObject(row.value);
|
||||
return decodeExtendedJson(row.value);
|
||||
}
|
||||
|
||||
async remove(key: string): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user