Add fetch_where, a single conditional wrapper around fetch_if, similar to fetch_equals

This commit is contained in:
Ege Emir Özkan
2020-08-10 06:29:20 +03:00
parent a3eed28f42
commit f0aac81209
3 changed files with 19 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import unittest
from datalite import datalite, fetch_if, fetch_all, fetch_range, fetch_from, fetch_equals
from datalite import datalite, fetch_if, fetch_all, fetch_range, fetch_from, fetch_equals, fetch_where
from sqlite3 import connect
from dataclasses import dataclass, asdict
from os import remove
@@ -94,6 +94,10 @@ class DatabaseFetchCalls(unittest.TestCase):
t_objs = fetch_if(FetchClass, "str_ = \"b\"")
self.assertEqual(tuple(self.objs[1:]), t_objs)
def testFetchWhere(self):
t_objs = fetch_where(FetchClass, 'str_', 'b')
self.assertEqual(tuple(self.objs[1:]), t_objs)
def testFetchRange(self):
t_objs = fetch_range(FetchClass, range(self.objs[0].obj_id, self.objs[2].obj_id))
self.assertEqual(tuple(self.objs[0:2]), t_objs)