Query concatination in GORM

Can anyone tell me how to append where conditions in Gorm query according to the parameters conditions?

The docs note that you can chain queries like this:

db.Where("name <> ?","jinzhu").Where("age >= ? and role <> ?",20,"admin").Find(&users)

Is that what you’re looking for? Alternately you could conditionally construct structs to pass to the query:

func query(name, age) {
  var user *User
  if someCondition {
    user = &User{name: name, age: age}
  } else {
    user = &User{name: name} 
  db.Where(user).First(&user)
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.