New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iteration doesn't support parsing raw data into struct? #59
Comments
Hi @Mattieuga Yes, we don't have this function now. ;( The But if gorm will support this feature, do you have any suggestions for the API naming? |
Something with a similar API to
Error handling can be tricky with the |
@jinzhu I actually would like to see this support not because I dislike the syntax of Gorm but because I don't want to load every object into memory at once. If I have a table with a large number of rows I use the iterator to process them. Iterating with the Rows is less that ideals since I can't Scan with a struct. Would it be possible to either add Iter support as @Mattieuga suggested or exposing the function that unmarshals Rows into Structs? |
Usage rows, err := db.Model(&User{}).Where("name = ?", "jinzhu").Select("name, age, email").Rows() // (*sql.Rows, error)
defer rows.Close()
for rows.Next() {
var user User
db.ScanRows(rows, &user)
// do something
} |
I may be missing something, but the docs aren't really clear on this. They mention the
Rows()
function can be used to iterate over table but since this returns*sql.Row
, I'm not sure how to scan this into the struct for this row. The great thing about gorm is that it handles parsing the sql data into a struct, but this seems to be missing for iteration.The example shows this, which really isn't great given how easy all of the other functions are to use.
The text was updated successfully, but these errors were encountered: