Search code examples
pythonormsqlobject

Filter "value in list" with SQLObject ORM


I wanted to use SQLObject to allow my co-workers to get some data from my MySQL database. Now I need to use filter "value in list" but I don't know how can I do that.

I choosed SQLObject because it looks simpler than for example Django ORM, but is there option to use filter "value in list"? In Django it is simply Class.objects.filter(value__in=list). I did not find an equivalent in the documentation of SQLObject but it is hard to believe that there is no such feature.

My list is not a range of values so

AND(Class.q.value>list[0], Class.q.value<list[-1])

...does not solve my problem. I need something that works like this code in Django:

Class.objects.filter(id__in=[1,13,100,17])

How can I do this using SQLObject? Can I?


Solution

  • from sqlobject.sqlbuilder import IN
    

    and use in your query:

    IN(Class.q.value, list)
    

    See the docs and tests.