2018-04-06 14:52:10 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2018-06-24 15:39:03 +00:00
|
|
|
import tables
|
|
|
|
import ranges
|
|
|
|
import ../storage_types
|
2018-02-12 16:59:12 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
MemoryDB* = ref object
|
2018-06-24 15:39:03 +00:00
|
|
|
kvStore*: Table[DbKey, ByteRange]
|
2018-02-12 16:59:12 +00:00
|
|
|
|
|
|
|
proc newMemoryDB*: MemoryDB =
|
2018-06-24 15:39:03 +00:00
|
|
|
MemoryDB(kvStore: initTable[DbKey, ByteRange]())
|
2018-02-12 16:59:12 +00:00
|
|
|
|
2018-06-24 15:39:03 +00:00
|
|
|
proc get*(db: MemoryDB, key: DbKey): ByteRange =
|
2018-02-12 16:59:12 +00:00
|
|
|
db.kvStore[key]
|
|
|
|
|
2018-06-24 15:39:03 +00:00
|
|
|
proc set*(db: var MemoryDB, key: DbKey, value: ByteRange) =
|
2018-02-12 16:59:12 +00:00
|
|
|
db.kvStore[key] = value
|
|
|
|
|
2018-05-30 16:11:15 +00:00
|
|
|
proc contains*(db: MemoryDB, key: DbKey): bool =
|
2018-02-12 16:59:12 +00:00
|
|
|
db.kvStore.hasKey(key)
|
|
|
|
|
2018-05-30 16:11:15 +00:00
|
|
|
proc delete*(db: var MemoryDB, key: DbKey) =
|
2018-02-12 16:59:12 +00:00
|
|
|
db.kvStore.del(key)
|
2018-06-24 15:39:03 +00:00
|
|
|
|