This commit is contained in:
Jaremy Creechley 2023-09-28 17:37:44 -07:00
parent 01ccbb5798
commit 82bf1f1a3c
No known key found for this signature in database
GPG Key ID: 4E66FB67B21D3300
2 changed files with 17 additions and 22 deletions

View File

@ -19,55 +19,55 @@ push: {.upraises: [].}
type
SQLiteDatastore* = ref object of Datastore
FSDatastore* = ref object of Datastore
db: ThreadDatastore[SQLiteBackend[KeyId, DataBuffer]]
proc path*(self: SQLiteDatastore): string =
proc path*(self: FSDatastore): string =
self.db.backend.path()
proc readOnly*(self: SQLiteDatastore): bool =
proc readOnly*(self: FSDatastore): bool =
self.db.backend.readOnly()
method has*(self: SQLiteDatastore,
method has*(self: FSDatastore,
key: Key): Future[?!bool] {.async.} =
await self.db.has(key)
method delete*(self: SQLiteDatastore,
method delete*(self: FSDatastore,
key: Key): Future[?!void] {.async.} =
await self.db.delete(key)
method delete*(self: SQLiteDatastore,
method delete*(self: FSDatastore,
keys: seq[Key]): Future[?!void] {.async.} =
await self.db.delete(keys)
method get*(self: SQLiteDatastore,
method get*(self: FSDatastore,
key: Key): Future[?!seq[byte]] {.async.} =
await self.db.get(key)
method put*(self: SQLiteDatastore,
method put*(self: FSDatastore,
key: Key,
data: seq[byte]): Future[?!void] {.async.} =
await self.db.put(key, data)
method put*(self: SQLiteDatastore,
method put*(self: FSDatastore,
batch: seq[BatchEntry]): Future[?!void] {.async.} =
await self.db.put(batch)
method close*(self: SQLiteDatastore): Future[?!void] {.async.} =
method close*(self: FSDatastore): Future[?!void] {.async.} =
await self.db.close()
method query*(self: SQLiteDatastore,
method query*(self: FSDatastore,
q: Query): Future[?!QueryIter] {.async.} =
await self.db.query(q)
proc new*(
T: type SQLiteDatastore,
T: type FSDatastore,
path: string,
readOnly = false,
tp: Taskpool,
): ?!SQLiteDatastore =
): ?!FSDatastore =
let
backend = ? newSQLiteBackend[KeyId, DataBuffer](path, readOnly)
db = ? ThreadDatastore.new(backend, tp = tp)
success SQLiteDatastore(db: db)
success FSDatastore(db: db)

View File

@ -60,14 +60,10 @@ for i in 1..N:
suite "Test Query ThreadDatastore with SQLite " & $i:
var
sqlStore: SQLiteBackend[KeyId, DataBuffer]
# taskPool: Taskpool
ds: ThreadDatastore[SQLiteBackend[KeyId, DataBuffer]]
ds: SQLiteDatastore
setup:
sqlStore = newSQLiteBackend[KeyId, DataBuffer](Memory).tryGet()
# taskPool = Taskpool.new(NumThreads)
ds = ThreadDatastore.new(sqlStore, tp = taskPool).tryGet()
ds = SQLiteDatastore.new(Memory, tp = taskPool).tryGet()
teardown:
GC_fullCollect()
@ -88,8 +84,7 @@ suite "Test Basic ThreadDatastore with fsds":
otherBytes = "some other bytes".toBytes
var
fsStore: FSDatastore[KeyId, DataBuffer]
ds: ThreadDatastore[FSDatastore[KeyId, DataBuffer]]
ds: SQLiteDatastore
setupAll:
removeDir(basePathAbs)