mirror of https://github.com/status-im/nim-eth.git
Merge pull request #287 from status-im/ula
use sqlite3 write-ahead logging to avoid excessive fsync()
This commit is contained in:
commit
8f1fd9890b
|
@ -120,9 +120,7 @@ proc init*(
|
|||
discard sqlite3_close(env)
|
||||
s
|
||||
|
||||
template checkExec(q: string) =
|
||||
let s = prepare(q): discard
|
||||
|
||||
template checkExec(s: ptr sqlite3_stmt) =
|
||||
if (let x = sqlite3_step(s); x != SQLITE_DONE):
|
||||
discard sqlite3_finalize(s)
|
||||
discard sqlite3_close(env)
|
||||
|
@ -132,9 +130,34 @@ proc init*(
|
|||
discard sqlite3_close(env)
|
||||
return err($sqlite3_errstr(x))
|
||||
|
||||
template checkExec(q: string) =
|
||||
let s = prepare(q): discard
|
||||
checkExec(s)
|
||||
|
||||
template checkWalPragmaResult(journalModePragma: ptr sqlite3_stmt) =
|
||||
if (let x = sqlite3_step(journalModePragma); x != SQLITE_ROW):
|
||||
discard sqlite3_finalize(journalModePragma)
|
||||
discard sqlite3_close(env)
|
||||
return err($sqlite3_errstr(x))
|
||||
|
||||
if (let x = sqlite3_column_type(journalModePragma, 0); x != SQLITE3_TEXT):
|
||||
discard sqlite3_finalize(journalModePragma)
|
||||
discard sqlite3_close(env)
|
||||
return err($sqlite3_errstr(x))
|
||||
|
||||
if (let x = sqlite3_column_text(journalModePragma, 0);
|
||||
x != "memory" and x != "wal"):
|
||||
discard sqlite3_finalize(journalModePragma)
|
||||
discard sqlite3_close(env)
|
||||
return err("Invalid pragma result: " & $x)
|
||||
|
||||
# TODO: check current version and implement schema versioning
|
||||
checkExec "PRAGMA user_version = 1;"
|
||||
|
||||
let journalModePragma = prepare("PRAGMA journal_mode = WAL;"): discard
|
||||
checkWalPragmaResult(journalModePragma)
|
||||
checkExec(journalModePragma)
|
||||
|
||||
checkExec """
|
||||
CREATE TABLE IF NOT EXISTS kvstore(
|
||||
key BLOB PRIMARY KEY,
|
||||
|
|
Loading…
Reference in New Issue