Example #1
0
    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)
Example #2
0
    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)
Example #3
0
 def cast_to_set(value):
     if not isinstance(value, xtuml.QuerySet):
         return xtuml.QuerySet([value])
     else:
         return value
Example #4
0
 def test_one_item(self):
     q = xtuml.QuerySet([2])
     self.assertEqual(q.first, 2)
     self.assertEqual(q.last, 2)
Example #5
0
 def test_last(self):
     q = xtuml.QuerySet([1, 2, 3])
     self.assertEqual(q.last, 3)
     
     q = xtuml.QuerySet()
     self.assertIsNone(q.last)
Example #6
0
 def test_first(self):
     q = xtuml.QuerySet([1, 2, 3])
     self.assertEqual(q.first, 1)
     
     q = xtuml.QuerySet()
     self.assertIsNone(q.first)
Example #7
0
 def select_many_in(inst_set, where_cond):
     s = filter(where_cond, inst_set)
     return xtuml.QuerySet(s)