Skip to content

Commit feddd5a

Browse files
committed
Add missing conversion for Option[T] types
Option[T] types should be allowed in proc arguments and return value inside tuples to signify a NULL value.
1 parent 2f14a0b commit feddd5a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/easy_sqlite3/bindings.nim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ proc `[]=`*(st: ref Statement, idx: int, val: type(nil)) =
491491
proc `[]=`*(st: ref Statement, idx: int, val: string) =
492492
st.raw.sqliteCheck sqlite3_bind_text(st.raw, idx, val, int32 val.len, TransientDestructor)
493493
494+
proc `[]=`*[T](st: ref Statement, idx: int, val: Option[T]) =
495+
if val.is_none:
496+
st.raw.sqliteCheck sqlite3_bind_null(st.raw, idx)
497+
else:
498+
st[idx] = val.get
499+
494500
proc reset*(st: ref Statement) =
495501
st.raw.sqliteCheck sqlite3_reset(st.raw)
496502
@@ -534,7 +540,7 @@ proc getColumn*[T](st: ref Statement, idx: int, _: typedesc[Option[T]]): Option[
534540
if st.getColumnType(idx) == dt_null:
535541
none(T)
536542
else:
537-
st.getColumn(idx, T)
543+
some(st.getColumn(idx, T))
538544
539545
proc unpack*[T: tuple](st: ref Statement, _: typedesc[T]): T =
540546
var idx = 0

0 commit comments

Comments
 (0)