mirror of https://github.com/status-im/nim-eth.git
Allow Sqlite keystores to be used in read-only mode
This is useful for tools such as `ncli_db` that can work with the database of a running Nimbus instances.
This commit is contained in:
parent
73d9bf4c80
commit
fe1bb4c4e7
|
@ -29,6 +29,7 @@ type
|
||||||
# can be created
|
# can be created
|
||||||
env: Sqlite
|
env: Sqlite
|
||||||
managedStmts: seq[RawStmtPtr]
|
managedStmts: seq[RawStmtPtr]
|
||||||
|
readOnly*: bool
|
||||||
|
|
||||||
SqStoreCheckpointKind* {.pure.} = enum
|
SqStoreCheckpointKind* {.pure.} = enum
|
||||||
passive, full, restart, truncate
|
passive, full, restart, truncate
|
||||||
|
@ -509,6 +510,7 @@ proc init*(
|
||||||
|
|
||||||
ok(SqStoreRef(
|
ok(SqStoreRef(
|
||||||
env: env.release,
|
env: env.release,
|
||||||
|
readOnly: readOnly
|
||||||
))
|
))
|
||||||
|
|
||||||
proc openKvStore*(db: SqStoreRef, name = "kvstore", withoutRowid = false): KvResult[SqKeyspaceRef] =
|
proc openKvStore*(db: SqStoreRef, name = "kvstore", withoutRowid = false): KvResult[SqKeyspaceRef] =
|
||||||
|
@ -519,15 +521,15 @@ proc openKvStore*(db: SqStoreRef, name = "kvstore", withoutRowid = false): KvRes
|
||||||
## rows (the row being the sum of key and value) - see
|
## rows (the row being the sum of key and value) - see
|
||||||
## https://www.sqlite.org/withoutrowid.html
|
## https://www.sqlite.org/withoutrowid.html
|
||||||
##
|
##
|
||||||
let
|
|
||||||
createSql = """
|
if not db.readOnly:
|
||||||
|
let createSql = """
|
||||||
CREATE TABLE IF NOT EXISTS """ & name & """ (
|
CREATE TABLE IF NOT EXISTS """ & name & """ (
|
||||||
key BLOB PRIMARY KEY,
|
key BLOB PRIMARY KEY,
|
||||||
value BLOB
|
value BLOB
|
||||||
)"""
|
)"""
|
||||||
|
checkExec db.env,
|
||||||
checkExec db.env,
|
if withoutRowid: createSql & " WITHOUT ROWID;" else: createSql & ";"
|
||||||
if withoutRowid: createSql & " WITHOUT ROWID;" else: createSql & ";"
|
|
||||||
|
|
||||||
var
|
var
|
||||||
tmp: SqKeyspace
|
tmp: SqKeyspace
|
||||||
|
|
Loading…
Reference in New Issue