mirror of
https://github.com/status-im/nim-codex.git
synced 2025-01-10 19:06:28 +00:00
bd8fedaf28
* pulls in datastore-leveldb update * bump * Applies LevelDb as metadata store. Adds option for repostore. * Sets submodule to main branch * I can do syntax, me * Removes wildcard from metadata query key * Applies leveldb instead of sqlite-in-memory for tests * Restores query key wildcard. * Pins nim-datastore to latest master * bumps leveldb to 0.1.4 --------- Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com>
31 lines
772 B
Nim
31 lines
772 B
Nim
import os
|
|
import std/monotimes
|
|
import pkg/datastore
|
|
import pkg/chronos
|
|
import pkg/questionable/results
|
|
|
|
type
|
|
TempLevelDb* = ref object
|
|
currentPath: string
|
|
ds: LevelDbDatastore
|
|
|
|
var number = 0
|
|
|
|
proc newDb*(self: TempLevelDb): Datastore =
|
|
if self.currentPath.len > 0:
|
|
raiseAssert("TempLevelDb already active.")
|
|
self.currentPath = getTempDir() / "templeveldb" / $number / $getmonotime()
|
|
inc number
|
|
createdir(self.currentPath)
|
|
self.ds = LevelDbDatastore.new(self.currentPath).tryGet()
|
|
return self.ds
|
|
|
|
proc destroyDb*(self: TempLevelDb): Future[void] {.async.} =
|
|
if self.currentPath.len == 0:
|
|
raiseAssert("TempLevelDb not active.")
|
|
try:
|
|
(await self.ds.close()).tryGet()
|
|
finally:
|
|
removedir(self.currentPath)
|
|
self.currentPath = ""
|