upper/db

[support] Is there a way to use `not` operator in SQL builder

ianhe8x opened this issue · 2 comments

I'm offering a flexible way for my end user to do query, and therefore seeking a programmatical way to be able to add the NOT operator to all the different db.Cond I've been assembled.

Thanks for any hints.

Asday commented

https://upper.io/v4/getting-started/sql-builder-api/#where-clause

q = q.Where("id = ? OR id = ?", 5, 4) // Two place holders and two values.

Not that I've tried it, but couldn't you simply do q.Where("NOT id = ?", x)?

The problem is how to do this programmatically, I can give an example a snippet of code I used,

case "lessThanInsensitive":
			cond = db.Cond{db.Raw(fmt.Sprintf("lower(%s)", field)): db.Lt(db.Raw("lower(?)", input.Field(i).Interface()))}
			break
case "not":
  // if there's something like below?
  // wrappedCond is another db.Cond{}
   cond = db.Not(wrappedCond)