예제 #1
0
 async def test_annotation_field_priorior_to_model_field(self):
     # Sometimes, field name in annotates also exist in model field sets
     # and may need lift the former's priority in select query construction.
     t1 = await Tournament.create(name="1")
     ret = await Tournament.filter(pk=t1.pk).annotate(id=RawSQL("id + 1")
                                                      ).values("id")
     self.assertEqual(ret, [{"id": t1.pk + 1}])
예제 #2
0
 async def test_raw_sql_select(self):
     t1 = await Tournament.create(id=1, name="1")
     ret = (await
            Tournament.filter(pk=t1.pk).annotate(idp=RawSQL("id + 1")
                                                 ).filter(idp=2
                                                          ).values("idp"))
     self.assertEqual(ret, [{"idp": 2}])
예제 #3
0
 async def test_raw_sql_filter(self):
     ret = await Tournament.filter(pk=RawSQL("id + 1"))
     self.assertEqual(ret, [])
예제 #4
0
 async def test_raw_sql_count(self):
     t1 = await Tournament.create(name="1")
     ret = await Tournament.filter(pk=t1.pk
                                   ).annotate(count=RawSQL("count(*)")
                                              ).values("count")
     self.assertEqual(ret, [{"count": 1}])