diff options
Diffstat (limited to 'src/dbUtils.nim')
-rw-r--r-- | src/dbUtils.nim | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/dbUtils.nim b/src/dbUtils.nim new file mode 100644 index 0000000..bdbcf14 --- /dev/null +++ b/src/dbUtils.nim @@ -0,0 +1,13 @@ +import std/times +import tiny_sqlite + +proc toDbValue*(t: DateTime): DbValue {.raises: [].}= + DbValue(kind: sqliteText, strVal: $t) + +proc fromDbValue*(value: DbValue, T: typedesc[DateTime]): DateTime {.raises: [].}= + try: + case value.kind: + of sqliteText: return times.parse(value.strVal, "yyyy-MM-dd'T'HH:mm:sszzz") + else: return + except TimeParseError: + return |