I am new to Go, is there any one who knows how to query the int64 filed with between and in Go/gorm?
I would like to use below sql select * from porject where created_at between ? and ?;, but I don't know how to do it? thanks so much for any advice.
type Project struct {
Id int64 `json:"id" gorm:"primary_key;AUTO_INCREMENT;comment:'id'"`
Email string `json:"email" gorm:"type:varchar(255);comment:'email'"`
CreatedAt int64 `json:"created_at" gorm:"type:bigint(20);comment:'created_time'"`
}
func (p *Project) ProjectList(pageInfo cts.PageInfo) ([]Project, int, error) {
if p.Email != "" {
db = db.Where("email like ?", "%"+p.Email+"%")
}
if p.CreatedAt != 0 {
db = db.Where("created_at <> ?", p.CreatedAt)
}
err1 := db.Offset((pageInfo.Page - 1) * pageInfo.PageSize).Limit(pageInfo.PageSize).Order("id desc").Find(&List).Error
db.Count(&total)
return List, total, err1
}
I need to pass front end to query data by below json
{
"page": 1,
"page_size": 20,
"email":"test@test",
"create_at_st": 1654176767,
"create_at_end": 1654896767
}
or
{
"page": 1,
"page_size": 20,
"email":"test@test",
"create_at": ['1654176767','1654896767']
}
or other json, as long as it can achieve the desired effect.