def select_one_in(inst_set, where_cond): inst_set = xtuml.QuerySet(inst_set) cardinality = Runtime.cardinality(inst_set) if cardinality > 1: raise RuntimeException( 'select one from a set with cardinality %d' % cardinality) return Runtime.select_any_in(inst_set, where_cond)
def select_many_in(inst_set, where_cond, order_by): s = filter(where_cond, inst_set) if order_by: s = order_by(s) return xtuml.QuerySet(s)
def cast_to_set(value): if not isinstance(value, xtuml.QuerySet): return xtuml.QuerySet([value]) else: return value
def test_one_item(self): q = xtuml.QuerySet([2]) self.assertEqual(q.first, 2) self.assertEqual(q.last, 2)
def test_last(self): q = xtuml.QuerySet([1, 2, 3]) self.assertEqual(q.last, 3) q = xtuml.QuerySet() self.assertIsNone(q.last)
def test_first(self): q = xtuml.QuerySet([1, 2, 3]) self.assertEqual(q.first, 1) q = xtuml.QuerySet() self.assertIsNone(q.first)
def select_many_in(inst_set, where_cond): s = filter(where_cond, inst_set) return xtuml.QuerySet(s)