2020-02-22 14:41:01 +03:00
|
|
|
package callbacks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jinzhu/gorm"
|
|
|
|
"github.com/jinzhu/gorm/clause"
|
|
|
|
)
|
|
|
|
|
|
|
|
func RowQuery(db *gorm.DB) {
|
2020-02-22 15:57:29 +03:00
|
|
|
if db.Statement.SQL.String() == "" {
|
|
|
|
db.Statement.AddClauseIfNotExists(clause.Select{})
|
|
|
|
db.Statement.AddClauseIfNotExists(clause.From{})
|
2020-02-22 14:41:01 +03:00
|
|
|
|
2020-02-22 15:57:29 +03:00
|
|
|
db.Statement.Build("SELECT", "FROM", "WHERE", "GROUP BY", "ORDER BY", "LIMIT", "FOR")
|
|
|
|
}
|
2020-02-22 14:41:01 +03:00
|
|
|
|
|
|
|
if _, ok := db.Get("rows"); ok {
|
|
|
|
db.Statement.Dest, db.Error = db.DB.QueryContext(db.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
|
|
|
} else {
|
|
|
|
db.Statement.Dest = db.DB.QueryRowContext(db.Context, db.Statement.SQL.String(), db.Statement.Vars...)
|
|
|
|
}
|
|
|
|
}
|