Created
May 13, 2021 13:05
-
-
Save Solution/45211581836f74266ef71394bf975199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type QueryObject struct { | |
query *gorm.DB | |
} | |
func NewQueryObject(database *gorm.DB) *QueryObject { | |
return &QueryObject{query: database.Model(&User{})} | |
} | |
func (qo *QueryObject) FilterByUsername(username string) *QueryObject { | |
qo.query = qo.query.Where("username = ?", username) | |
return qo | |
} | |
func (qo *QueryObject) FilterByActive() *QueryObject { | |
qo.query = qo.query.Where("active = ?", true) | |
return qo | |
} | |
func (qo *QueryObject) GetQuery() *gorm.DB { | |
return qo.query | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment