2024-03-05 03:12:37 +00:00
|
|
|
# Nim-RocksDB
|
|
|
|
# Copyright 2024 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)
|
|
|
|
# * GPL license, version 2.0, ([LICENSE-GPLv2](LICENSE-GPLv2) or https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
|
|
|
|
#
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
|
|
|
{.used.}
|
|
|
|
|
2024-07-08 14:18:30 +00:00
|
|
|
import std/sequtils, ../rocksdb/[backup, rocksdb, transactiondb, optimistictxdb]
|
2024-03-05 03:12:37 +00:00
|
|
|
|
|
|
|
proc initReadWriteDb*(
|
2024-06-26 15:00:10 +00:00
|
|
|
path: string, columnFamilyNames: openArray[string] = @[]
|
|
|
|
): RocksDbReadWriteRef =
|
2024-03-05 03:12:37 +00:00
|
|
|
let res = openRocksDb(
|
2024-06-28 02:04:37 +00:00
|
|
|
path,
|
|
|
|
columnFamilies = columnFamilyNames.mapIt(
|
|
|
|
initColFamilyDescriptor(it, defaultColFamilyOptions(autoClose = true))
|
|
|
|
),
|
2024-06-26 15:00:10 +00:00
|
|
|
)
|
2024-03-05 03:12:37 +00:00
|
|
|
if res.isErr():
|
|
|
|
echo res.error()
|
|
|
|
doAssert res.isOk()
|
|
|
|
res.value()
|
|
|
|
|
|
|
|
proc initReadOnlyDb*(
|
2024-06-26 15:00:10 +00:00
|
|
|
path: string, columnFamilyNames: openArray[string] = @[]
|
|
|
|
): RocksDbReadOnlyRef =
|
2024-03-05 03:12:37 +00:00
|
|
|
let res = openRocksDbReadOnly(
|
2024-06-28 02:04:37 +00:00
|
|
|
path,
|
|
|
|
columnFamilies = columnFamilyNames.mapIt(
|
|
|
|
initColFamilyDescriptor(it, defaultColFamilyOptions(autoClose = true))
|
|
|
|
),
|
2024-06-26 15:00:10 +00:00
|
|
|
)
|
2024-03-05 03:12:37 +00:00
|
|
|
if res.isErr():
|
|
|
|
echo res.error()
|
|
|
|
doAssert res.isOk()
|
|
|
|
res.value()
|
|
|
|
|
|
|
|
proc initBackupEngine*(path: string): BackupEngineRef =
|
|
|
|
let res = openBackupEngine(path)
|
|
|
|
doAssert res.isOk()
|
|
|
|
res.value()
|
|
|
|
|
|
|
|
proc initTransactionDb*(
|
2024-06-26 15:00:10 +00:00
|
|
|
path: string, columnFamilyNames: openArray[string] = @[]
|
|
|
|
): TransactionDbRef =
|
2024-03-05 03:12:37 +00:00
|
|
|
let res = openTransactionDb(
|
2024-06-26 17:31:39 +00:00
|
|
|
path,
|
2024-06-28 02:04:37 +00:00
|
|
|
columnFamilies = columnFamilyNames.mapIt(
|
|
|
|
initColFamilyDescriptor(it, defaultColFamilyOptions(autoClose = true))
|
|
|
|
),
|
2024-06-26 15:00:10 +00:00
|
|
|
)
|
2024-03-05 03:12:37 +00:00
|
|
|
if res.isErr():
|
|
|
|
echo res.error()
|
|
|
|
doAssert res.isOk()
|
2024-03-07 01:02:24 +00:00
|
|
|
res.value()
|
2024-07-08 14:18:30 +00:00
|
|
|
|
|
|
|
proc initOptimisticTxDb*(
|
|
|
|
path: string, columnFamilyNames: openArray[string] = @[]
|
|
|
|
): OptimisticTxDbRef =
|
|
|
|
let res = openOptimisticTxDb(
|
|
|
|
path,
|
|
|
|
columnFamilies = columnFamilyNames.mapIt(
|
|
|
|
initColFamilyDescriptor(it, defaultColFamilyOptions(autoClose = true))
|
|
|
|
),
|
|
|
|
)
|
|
|
|
if res.isErr():
|
|
|
|
echo res.error()
|
|
|
|
doAssert res.isOk()
|
|
|
|
res.value()
|