db icon indicating copy to clipboard operation
db copied to clipboard

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

Open ianhe8x opened this issue 2 years ago • 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.

ianhe8x avatar Jan 27 '23 03:01 ianhe8x

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)?

Asday avatar Jan 27 '23 12:01 Asday

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)

ianhe8x avatar Jan 27 '23 20:01 ianhe8x