Get kuzu blob -> nim seq working.

FossilOrigin-Name: 93f0981fe0a2dbbcd455ebf69b5042e70503f215bb78c8730e12d57d3e884db0
This commit is contained in:
Mahlon E. Smith 2025-04-19 00:42:05 +00:00
parent cf00df149d
commit 7a85bfc7ac
2 changed files with 16 additions and 12 deletions

View file

@ -2,6 +2,7 @@
const KUZU_VERSION* = "0.2.0" const KUZU_VERSION* = "0.2.0"
const KUZU_EXPECTED_LIBVERSION* = "0.9.0" const KUZU_EXPECTED_LIBVERSION* = "0.9.0"
const BLOB_MAXSIZE = 4096
let KUZU_DEFAULT_CONFIG* = kuzu_default_system_config() let KUZU_DEFAULT_CONFIG* = kuzu_default_system_config()

View file

@ -186,17 +186,20 @@ func `$`*( struct: KuzuStructValue ): string =
result = $kuzu_value_to_string( addr struct.value.handle ) result = $kuzu_value_to_string( addr struct.value.handle )
# func toBlob*( value: KuzuValue ): array[ 4096, byte ] = proc toBlob*( value: KuzuValue ): seq[ byte ] =
# ## Conversion from Kuzu type to Nim. ## Conversion from Kuzu type to Nim - returns a BLOB as a sequence of bytes.
# if value.kind != KUZU_BLOB: if value.kind != KUZU_BLOB:
# raise newException( KuzuTypeError, &"Mismatched types: {value.kind} != blob" ) raise newException( KuzuTypeError, &"Mismatched types: {value.kind} != blob" )
# var rv: array[ 4096, byte ]
# assert( kuzu_value_get_blob( addr value.handle, addr rv[0] ) == KuzuSuccess ) result = @[]
# return rv var data: ptr byte
assert( kuzu_value_get_blob( addr value.handle, addr data ) == KuzuSuccess )
for idx in 0 .. BLOB_MAXSIZE:
var byte = cast[ptr byte](cast[uint](data) + idx.uint)[]
if byte == 0: break
result.add( byte )
kuzu_destroy_blob( data )
#[
BLOB
MAP
]#