Settings

Theme

Show HN: Go 1.22 range functions with database/sql

github.com

4 points by achille-roussel 2 years ago · 0 comments · 1 min read

Reader

Hello HN!

I published a package exploring how to use the experimental range functions coming to Go 1.22 with database/sql to stream values in and out of SQL databases.

One interesting benefit of range functions I found is they enable automatic resource management (no risk of forgetting to close a sql.Rows, or missing a call to Err to check errors).

The use of generics adds type safety and simplifies exchanging values between the Go application and the database.

The resulting code is also quite efficient, the compiler can inline the call sites that create the range functions, which helps escape analysis and allow most values to be allocated on the stack.

Let me know if you have any feedback, I hope it will be useful!

No comments yet.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection