Proposal: Adding ScanRow Method to database/sql in Go

2023/07/28
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

The article proposes adding a new method called ScanRow to the Row and Rows types in the database/sql package in Go. This method would allow developers to conveniently populate a row from a struct. The motivation for this proposal comes from the popularity of the github.com/jmoiron/sqlx package, which provides similar enhancements to database/sql. The addition of ScanRow would bring database/sql closer to parity with encoding/json, which is widely used for unmarshaling into structs and other data types. Another motivation for this proposal is the likely addition of iterators to the language, where an iterator over a DB query could deliver a single value holding the entire row. The details of the ScanRow method are explained, including how it handles array pointers, slice pointers, map pointers, and struct pointers. This proposal does not include the iterator, but it serves as motivation for the ScanRow method.