vrischmann / zig-sqlite

zig-sqlite is a small wrapper around sqlite's C API, making it easier to use with Zig.
MIT License
367 stars 49 forks source link

Bind runtime slices to queries #82

Closed lun-4 closed 2 years ago

lun-4 commented 2 years ago

When using execDynamic, you can have a runtime-known number of parameters in the query, however the current way of binding the parameters requires the values to be comptime-known.

This PR allows slices of form []T to be passed as the values parameter, binding it to the statement with a runtime loop instead. Not sure how I should approach setting the field_name parameter to bindField, as it is comptime (so I'm just setting it to empty string). Any suggestions?

This was manually tested, but if this idea moves forward on being upstreamed, I plan to add it to the test suite.

vrischmann commented 2 years ago

Hi,

thank you for working on this ! unfortunately I didn't have much time lately to review your PRs but I'll get around to it, probably in the coming weeks.

vrischmann commented 2 years ago

I like this feature, thanks for working on it ! Overall LGTM, only one small comment. With some tests I think it will be ok to merge.

As for this question:

Not sure how I should approach setting the field_name parameter to bindField, as it is comptime (so I'm just setting it to empty string). Any suggestions?

IIRC it's only used for debugging in comptime errors, in the case of a dynamic slice it's doesn't make sense so something like "unknown" is fine.

vrischmann commented 2 years ago

Looks good ! One last thing, could you remove the commit 9ef7561e02a0b4b08b13a6836202c0b13b509948 from the PR and then I can merge