我如何在 Go*sql.Rows中使用一种解析(扫描)方法?*sql.Row解析(扫描)方法使用一个代码解析一行...row := r.stmOne.QueryRow(id)rows, err := r.stmOther.Query(ids, params)parseRow(row, &item)for rows.Next(){ parseRows(rows, &item)}...func parseRows(row *sql.Rows, item *typeItem) error { err := row.Scan(....) /// same}func parseRow(row *sql.Row, item *typeItem) error { err := row.Scan(....) /// same}
1 回答
海绵宝宝撒
TA贡献1809条经验 获得超8个赞
type RowScanner interface {
Scan(dest ...interface{}) error
}
func scanRowIntoItem(row RowScanner, item *typeItem) error {
err := row.Scan(...)
}
row := r.stmOne.QueryRow(id)
rows, err := r.stmOther.Query(ids, params)
scanRowIntoItem(row, &item)
for rows.Next(){
scanRowIntoItem(rows, &item)
}
- 1 回答
- 0 关注
- 100 浏览
添加回答
举报
0/150
提交
取消