Repository: kayak/pypika (python)

Issue:
Alias for Criterions
Criterion expressions cannot be given an alias due to missing .as_ function

Pull request:
Fixes #22 Changed Criterion to extend Term
Extended Term to provide the missing functions on Criterion.

Patch:
diff --git a/pypika/terms.py b/pypika/terms.py
index 47043a3..eba423a 100644
--- a/pypika/terms.py
+++ b/pypika/terms.py
@@ -263,7 +263,7 @@ class ListField(object):
         )
 
 
-class Criterion(object):
+class Criterion(Term):
     def __and__(self, other):
         return ComplexCriterion(Boolean.and_, self, other)
 


Test patch:
diff --git a/pypika/tests/test_criterions.py b/pypika/tests/test_criterions.py
index 782526b..12001de 100644
--- a/pypika/tests/test_criterions.py
+++ b/pypika/tests/test_criterions.py
@@ -12,6 +12,11 @@ __email__ = "theys@kayak.com"
 class CriterionTests(unittest.TestCase):
     t = Table('test', alias = 'crit')
 
+    def test__criterion_with_alias(self):
+        c1 = (Field('foo') == Field('bar')).as_('criterion')
+
+        self.assertEqual('"foo"="bar"', str(c1))
+
     def test__criterion_eq_number(self):
         c1 = Field('foo') == 1
         c2 = Field('foo', table=self.t).eq(0)