Skip to content

Commit

Permalink
Adding Apply method for query to DB.
Browse files Browse the repository at this point in the history
  • Loading branch information
susyo committed Apr 16, 2018
1 parent b365cc5 commit 65aef97
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ type DBQuery struct {
Select string
}

// Apply applies the query input on a database instance
func (q *DBQuery) Apply(db *gorm.DB) *gorm.DB {
if q == nil {
return db
}
if q.Offset != 0 {
db = db.Offset(q.Offset)
}
if q.Limit != 0 {
db = db.Limit(q.Limit)
}
if q.Select != "" {
db = db.Select(q.Select)
}
if q.Sort != "" {
db = db.Order(q.Sort)
}
if q.CondExp != "" {
db = db.Where(q.CondExp, q.CondVal...)
}
return db
}

// Wrapper is the interface that wraps the wrap method.
type Wrapper interface {
Wrap(string) string
Expand Down

0 comments on commit 65aef97

Please sign in to comment.