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
func main() { | |
// init the repository based on gorm instance | |
repository := NewRepository(database) | |
// create qo from repository, you can do it again and again | |
qo := repository.NewQueryObject(). | |
FilterByUsername("myUsername"). // compose your q. | |
FilterByActive() | |
// and than fetch it |
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 Repository struct { | |
database *gorm.DB | |
} | |
func NewRepository(database *gorm.DB) Repository { | |
return Repository{database: database} | |
} | |
func (r Repository) NewQueryObject() *QueryObject { | |
return NewQueryObject(r.database.Session(&gorm.Session{NewDB: true})) |
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
func main() { | |
// always use new session | |
qo := NewQueryObject(database.Session(&gorm.Session{NewDB: true})). | |
FilterByUsername("myUsername"). | |
FilterByActive() | |
// and now retrieve the model | |
var user model.User | |
qo.GetQuery().First(&user) |
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) |
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 User struct { | |
gorm.Model | |
Firstname string | |
Surname string | |
Email string | |
Phone string | |
Password string | |
Role string | |
Active bool |
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 interface { | |
GetQuery() *gorm.DB | |
} |
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 User struct { | |
gorm.Model | |
Username string | |
Firstname string | |
Surname string | |
Email string | |
Phone string | |
Password string | |
Role string |
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
package transportServiceClient | |
import ( | |
"net/http" | |
"strconv" | |
"fmt" | |
) | |
type Client struct { | |
*client.Client |
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
package client | |
import ( | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"github.com/Solution/go-httpwares" | |
"github.com/Solution/go-httpwares/metrics" | |
"github.com/Solution/go-httpwares/tags" |
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
package client | |
import ( | |
"net/http" | |
"strings" | |
"github.com/pkg/errors" | |
) | |
type RequestFactory struct { | |
schema Schema |
NewerOlder