create skeleton SlopStore class for operations on the slop object store
This commit is contained in:
@@ -1,39 +1,5 @@
|
|||||||
import { openDB, IDBPDatabase, unwrap } from "idb/index.js"
|
import { openDB, IDBPDatabase, unwrap } from "idb/index.js"
|
||||||
|
|
||||||
export class IDBCursorValueIterator {
|
|
||||||
cursor: IDBCursorWithValue
|
|
||||||
|
|
||||||
constructor(cursor: IDBCursorWithValue) {
|
|
||||||
this.cursor = cursor
|
|
||||||
}
|
|
||||||
|
|
||||||
next(): IteratorResult<any> {
|
|
||||||
const key = this.cursor.key
|
|
||||||
const value = this.cursor.value
|
|
||||||
let done = false
|
|
||||||
|
|
||||||
try {
|
|
||||||
this.cursor.continue()
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
if (error.name === "InvalidStateError") {
|
|
||||||
done = true
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
return { value: {key: key, value: value}, done: done }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Symbol.iterator]() {
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export class CheckCache {
|
export class CheckCache {
|
||||||
slopdb: IDBPDatabase
|
slopdb: IDBPDatabase
|
||||||
cache_capacity: number
|
cache_capacity: number
|
||||||
@@ -82,13 +48,22 @@ export class CheckCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class SlopStore {
|
||||||
|
slopdb: IDBPDatabase
|
||||||
|
static slop_objectstore_name = "slop"
|
||||||
|
|
||||||
|
constructor(slopdb: IDBPDatabase) {
|
||||||
|
this.slopdb = slopdb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class SlopDB {
|
export class SlopDB {
|
||||||
version: number
|
version: number
|
||||||
open_promise: Promise<any>
|
open_promise: Promise<any>
|
||||||
db: IDBPDatabase
|
db: IDBPDatabase
|
||||||
|
|
||||||
// slop_store: SlopStore
|
|
||||||
check_cache: CheckCache
|
check_cache: CheckCache
|
||||||
|
slop_store: SlopStore
|
||||||
|
|
||||||
static apply_db_upgrade(db: IDBPDatabase, idb_version: number) {
|
static apply_db_upgrade(db: IDBPDatabase, idb_version: number) {
|
||||||
switch (idb_version) {
|
switch (idb_version) {
|
||||||
@@ -121,6 +96,9 @@ export class SlopDB {
|
|||||||
this.db = db
|
this.db = db
|
||||||
// create a CheckCache object to handle the check_cache object store
|
// create a CheckCache object to handle the check_cache object store
|
||||||
this.check_cache = new CheckCache(this.db, 512)
|
this.check_cache = new CheckCache(this.db, 512)
|
||||||
|
|
||||||
|
// create a SlopStore object to handle the slop object store
|
||||||
|
this.slop_store = new SlopStore(this.db)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user