nim-codex/tests/helpers/templeveldb.nim
Ben Bierens bd8fedaf28
Metadata in LevelDB (#806)
* 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>
2024-05-30 06:57:10 +00:00

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 = ""