Add basic tuple and value fetching from queries.

Add safeties for =destroy hooks.

FossilOrigin-Name: 2fae5297a0d0598cc3580777688b4f4307de008d4f379d2fb224c8a74cb9b708
This commit is contained in:
mahlon 2025-03-22 22:28:22 +00:00
parent 1ed442a68a
commit 7850a79372
14 changed files with 237 additions and 17 deletions

23
src/kuzu/tuple.nim Normal file
View file

@ -0,0 +1,23 @@
# vim: set et sta sw=4 ts=4 :
proc `=destroy`*( tpl: KuzuFlatTupleObj ) =
## Graceful cleanup for out of scope tuples.
if tpl.valid:
kuzu_flat_tuple_destroy( addr tpl.handle )
proc `$`*( tpl: KuzuFlatTuple ): string =
## Stringify a tuple.
result = $kuzu_flat_tuple_to_string( addr tpl.handle )
result.removeSuffix( "\n" )
proc `[]`*( tpl: KuzuFlatTuple, idx: int ): KuzuValue =
## Returns a KuzuValue at the given +idx+.
result = new KuzuValue
if kuzu_flat_tuple_get_value( addr tpl.handle, idx.uint64, addr result.handle ) == KuzuSuccess:
result.valid = true
else:
raise newException( KuzuIndexException,
&"Unable to fetch tuple value at idx {idx}. ({tpl.num_columns} column(s).)" )