Add support for IN queries

This commit is contained in:
Andrew Brookins 2021-10-13 17:16:20 -07:00
parent bb08fb9eb5
commit 389a6ea878
3 changed files with 111 additions and 54 deletions

View file

@ -360,9 +360,15 @@ def test_numeric_queries(members):
actual = Member.find(Member.age >= 100).all()
assert actual == [member3]
actual = Member.find(Member.age != 34).all()
assert actual == [member1, member3]
actual = Member.find(~(Member.age == 100)).all()
assert actual == [member1, member2]
actual = Member.find(Member.age > 30, Member.age < 40).all()
assert actual == [member1, member2]
def test_sorting(members):
member1, member2, member3 = members

View file

@ -12,7 +12,7 @@ from redis_developer.orm import (
JsonModel,
Field,
)
from redis_developer.orm.model import RedisModelError, QueryNotSupportedError, NotFoundError, embedded
from redis_developer.orm.model import QueryNotSupportedError, NotFoundError
r = redis.Redis()
today = datetime.date.today()
@ -240,6 +240,24 @@ def test_access_result_by_index_not_cached(members):
assert query[2] == member3
def test_in_query(members):
member1, member2, member3 = members
actual = Member.find(Member.pk << [member1.pk, member2.pk, member3.pk]).all()
assert actual == [member1, member2, member3]
@pytest.mark.skip("Not implemented yet")
def test_update_query(members):
member1, member2, member3 = members
Member.find(Member.pk << [member1.pk, member2.pk, member3.pk]).update(
first_name="Bobby"
)
actual = Member.find(
Member.pk << [member1.pk, member2.pk, member3.pk]).sort_by('age').all()
assert actual == [member1, member2, member3]
assert all([m.name == "Bobby" for m in actual])
def test_exact_match_queries(members):
member1, member2, member3 = members
@ -458,6 +476,12 @@ def test_numeric_queries(members):
actual = Member.find(~(Member.age == 100)).all()
assert actual == [member1, member2]
actual = Member.find(Member.age > 30, Member.age < 40).all()
assert actual == [member1, member2]
actual = Member.find(Member.age != 34).all()
assert actual == [member1, member3]
def test_sorting(members):
member1, member2, member3 = members