duckdb / duckdb-node-neo

Second iteration on a DuckDB Node.js client
MIT License
30 stars 1 forks source link

Deno 2.0 FFI #39

Open ggpwnkthx opened 4 weeks ago

ggpwnkthx commented 4 weeks ago

This isn't an issue with the node-neo package, but I'm unsure where else would have a community that is the most knowledgable of this topic since there don't seem to be any active Deno specific DuckDB repos. Probably because the node DuckDB package already works just fine with Deno 2.0. That said, I'm in the process of learning how to use the updated Foriegn Function Interface with DuckDB. I'm getting stuck due to my limited C/C++ understanding.

I have a repo that can successfully open, connect, query, get column names and types, as well as disconnect and close. However, I'm really struggling to understand how to get the data chunks from the duckdb_result pointer - or honestly if I'm even using the pointers vs buffers correctly at all.

I was hoping someone might be willing to look over my shoulder and push me in the right direction. Thank you!

elefeint commented 4 weeks ago

whenever I have to work with C API, I like to look at how DuckDB's own tests use it, for example this test

But also, DuckDB improved its C API documentation a lot, so this might be a better resource by now -- https://duckdb.org/docs/api/c/query#value-extraction

ggpwnkthx commented 4 weeks ago

I feel dumb for not diving deeper into the API docs. I jumped to the reference page and assumed the majority of what I'd need to know would be there. And checking the tests is a great idea, too. Thank you!

ggpwnkthx commented 3 weeks ago

@elefeint, thanks again for pointing me in the right direction. I realized I was mistakenly treating buffers as pointers and not defining the structs for those buffers. What confused me was that the duckdb.h often shows pointers as expected parameters or results, but in DuckDB some structs are actually just an internal pointer. This meant that treating those values as a u64 (when they were internal pointer structs) worked fine, but failed for other types of structured buffers, like duckdb_results. This now makes a lot more sense to me.