mirror of
https://github.com/logos-storage/nim-datastore.git
synced 2026-04-18 17:13:11 +00:00
query fixes
This commit is contained in:
parent
84cdc1d8ca
commit
0c72ad8478
@ -19,7 +19,7 @@ push: {.upraises: [].}
|
||||
|
||||
type
|
||||
SQLiteDatastore* = ref object of Datastore
|
||||
db: SQLiteBackend
|
||||
db: SQLiteBackend[KeyId, DataBuffer]
|
||||
|
||||
proc path*(self: SQLiteDatastore): string =
|
||||
self.db.path()
|
||||
@ -27,23 +27,30 @@ proc path*(self: SQLiteDatastore): string =
|
||||
proc readOnly*(self: SQLiteDatastore): bool =
|
||||
self.db.readOnly()
|
||||
|
||||
method has*(self: SQLiteDatastore, key: Key): Future[?!bool] {.async.} =
|
||||
method has*(self: SQLiteDatastore,
|
||||
key: Key): Future[?!bool] {.async.} =
|
||||
return self.db.has(KeyId.new key.id())
|
||||
|
||||
method delete*(self: SQLiteDatastore, key: Key): Future[?!void] {.async.} =
|
||||
method delete*(self: SQLiteDatastore,
|
||||
key: Key): Future[?!void] {.async.} =
|
||||
return self.db.delete(KeyId.new key.id())
|
||||
|
||||
method delete*(self: SQLiteDatastore, keys: seq[Key]): Future[?!void] {.async.} =
|
||||
method delete*(self: SQLiteDatastore,
|
||||
keys: seq[Key]): Future[?!void] {.async.} =
|
||||
let dkeys = keys.mapIt(KeyId.new it.id())
|
||||
return self.db.delete(dkeys)
|
||||
|
||||
method get*(self: SQLiteDatastore, key: Key): Future[?!seq[byte]] {.async.} =
|
||||
method get*(self: SQLiteDatastore,
|
||||
key: Key): Future[?!seq[byte]] {.async.} =
|
||||
self.db.get(KeyId.new key.id())
|
||||
|
||||
method put*(self: SQLiteDatastore, key: Key, data: seq[byte]): Future[?!void] {.async.} =
|
||||
method put*(self: SQLiteDatastore,
|
||||
key: Key,
|
||||
data: seq[byte]): Future[?!void] {.async.} =
|
||||
self.db.put(KeyId.new key.id(), DataBuffer.new data)
|
||||
|
||||
method put*(self: SQLiteDatastore, batch: seq[BatchEntry]): Future[?!void] {.async.} =
|
||||
method put*(self: SQLiteDatastore,
|
||||
batch: seq[BatchEntry]): Future[?!void] {.async.} =
|
||||
var dbatch: seq[tuple[key: string, data: seq[byte]]]
|
||||
for entry in batch:
|
||||
dbatch.add((entry.key.id(), entry.data))
|
||||
|
||||
@ -81,13 +81,14 @@ proc get*[K,V](self: SQLiteBackend[K,V], key: K): ?!seq[byte] =
|
||||
proc put*[K,V](self: SQLiteBackend[K,V], key: K, data: V): ?!void =
|
||||
return self.db.putStmt.exec((key, data, timestamp()))
|
||||
|
||||
proc put*[K,V](self: SQLiteBackend[K,V], batch: openArray[DbBatchEntry]): ?!void =
|
||||
proc put*[K,V](self: SQLiteBackend[K,V], batch: openArray[DbBatchEntry[K,V]]): ?!void =
|
||||
if err =? self.db.beginStmt.exec().errorOption:
|
||||
return failure err
|
||||
|
||||
for entry in batch:
|
||||
let putStmt = self.db.putStmt
|
||||
if err =? putStmt.exec((entry.key, entry.data, timestamp())).errorOption:
|
||||
let item = (entry.key, entry.data, timestamp())
|
||||
if err =? putStmt.exec(item).errorOption:
|
||||
if err =? self.db.rollbackStmt.exec().errorOption:
|
||||
return failure err
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user