-
Notifications
You must be signed in to change notification settings - Fork 127
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
Does Jet support QueryRow? #20
Comments
QueryRow isn't part of jet API but it is possible to retrieve raw sql with arguments from the query := SELECT(...)
sql, args := query.Sql()
row := db.QueryRow(sql, args...) // db can be sql.DB, sql.Tx .... This also applies for the other methods from Query into slice
dest := []model.Film{}
err := query.Query(db, &dest)
if len(dest) == 0 {
// no rows in result set
} Query into structThere is also an option to pass a single struct pointer to dest := model.Film{}
err := query.Query(db, &dest) This is not the same as QueryRow, because in a case when destination struct contains slices, multiple rows can be mapped into single struct destination. Currently in a case of empty result set, it doesn't returns an error, but most likely it should. Also note that All this will be part of the new release v.2.2.0. |
@go-jet Great! So, probably, we need two versions: error and no error for different use cases. For those who are familiar to Go sql, it is better to add an extra QueryRow function instead of returning an error in "Query into struct", which seems confusing to them. |
More appropriate name for Jet Also neither "database/sql" Even if there is a separate method in Jet, that will query into struct, it wouldn't be called If the idea behind new |
@go-jet Yes, you are right. Jet should use another query (QueryOne or QueryResultMapping) to return the error ErrNoRows, not in Query. |
Whether there will be two methods QueryResultMapping and QueryRestulMappingOne or just one Query(QueryResultMapping) is just a a matter of preference. |
@go-jet Good. Make sense. Thanks. Sorry, this issue is related to the Version 2.2.0 Milestones . So, I cannot close it. Reopen it again. |
Does Jet support QueryRow for only one row.
The text was updated successfully, but these errors were encountered: