stephenafamo / bob

SQL query builder and ORM/Factory generator for Go with support for PostgreSQL, MySQL and SQLite
https://bob.stephenafamo.com
MIT License
701 stars 37 forks source link

No way to build a "not like" or "not ilike" query #203

Closed gottafixthat closed 2 months ago

gottafixthat commented 2 months ago

Perhaps I'm missing something, but the only modifier that I've been able to find is psql.Not().

Ideally, I'd like to be able to build a query like so (note the made up NotILike):

q := psql.Select(
    sm.Columns("*"),
    sm.From(psql.Quote(models.TableNames.Orders)),
    sm.Where(psql.Quote("status").NotILike(psql.Arg("%/complete"))),
)

Since in this case status has a prefix of "Sales/" or "Support/", so I'm looking for all "open" orders.

In sqlboiler I was able do to this:

qm.Where("status NOT LIKE ?", "%/complete)

Which wasn't ideal, but worked. I'm unable to find a "clean" equivalent in Bob.

stephenafamo commented 2 months ago

You should be able to do something like this

q := psql.Select(
    sm.Columns("*"),
    sm.From(psql.Quote(models.TableNames.Orders)),
    sm.Where(psql.Not(psql.Quote("status").ILike(psql.Arg("%/complete")))),
)
gottafixthat commented 2 months ago

That worked! I'd swear I tried that permutation.

Thanks for your help.