nitter/src/prefs.nim

37 lines
775 B
Nim
Raw Normal View History

2019-08-17 19:49:41 +00:00
import strutils
2019-08-13 17:44:29 +00:00
import types
2019-08-17 19:49:41 +00:00
import prefs_impl
2019-08-13 17:44:29 +00:00
2019-08-17 19:49:41 +00:00
export genUpdatePrefs
2019-08-13 17:44:29 +00:00
withCustomDb("prefs.db", "", "", ""):
try:
createTables()
except DbError:
discard
proc cache*(prefs: var Prefs) =
withCustomDb("prefs.db", "", "", ""):
try:
doAssert prefs.id != 0
discard Prefs.getOne("id = ?", prefs.id)
prefs.update()
except AssertionError, KeyError:
prefs.insert()
proc getPrefs*(id: string): Prefs =
if id.len == 0: return genDefaultPrefs()
withCustomDb("prefs.db", "", "", ""):
try:
result.getOne("id = ?", id)
except KeyError:
result = genDefaultPrefs()
cache(result)
2019-08-15 17:13:54 +00:00
proc resetPrefs*(prefs: var Prefs) =
var defPrefs = genDefaultPrefs()
defPrefs.id = prefs.id
cache(defPrefs)
prefs = defPrefs