Add cases for converting bool from int and string

This commit is contained in:
emizzle 2020-11-23 17:26:37 +11:00 committed by Michael Bradley
parent a8cd7c5c57
commit eca1111a11
1 changed files with 7 additions and 1 deletions

View File

@ -134,7 +134,13 @@ proc nilDbValue(): DbValue =
## we use this internally.
DbValue(kind: sqliteNull)
proc fromDbValue*(val: DbValue, T: typedesc[Ordinal]): T = val.intval.T
proc fromDbValue*(val: DbValue, T: typedesc[Ordinal]): T =
when T is bool:
if val.kind == DbValueKind.sqliteInteger:
return if val.intVal == 0: false else: true
elif val.kind == DbValueKind.sqliteText:
return val.strVal.parseBool
return val.intVal.T
proc fromDbValue*(val: DbValue, T: typedesc[SomeFloat]): float64 = val.floatVal