How to use the pypika.Field function in PyPika

To help you get started, we’ve selected a few PyPika examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kayak / pypika / test / test_criterions.py View on Github external
def test__criterion_gte_right(self):
        c1 = 1 <= Field('foo')
        c2 = -1 <= Field('foo', table=self.t)

        self.assertEqual('foo>=1', str(c1))
        self.assertEqual('t0.foo>=-1', str(c2))
github kayak / pypika / test / test_criterions.py View on Github external
def test__criterion_gt_date(self):
        c1 = Field('foo') > date(2000, 1, 1)
        c2 = Field('foo', table=self.t).gt(date(2000, 1, 1))

        self.assertEqual("foo>'2000-01-01'", str(c1))
        self.assertEqual("t0.foo>'2000-01-01'", str(c2))
github kayak / pypika / test / test_criterions.py View on Github external
def test__criterion_gte_datetime(self):
        c1 = Field('foo') >= datetime(2000, 1, 1, 12, 30, 55)
        c2 = Field('foo', table=self.t).gte(datetime(2000, 1, 1, 12, 30, 55))

        self.assertEqual("foo>='2000-01-01T12:30:55'", str(c1))
        self.assertEqual("t0.foo>='2000-01-01T12:30:55'", str(c2))
github kayak / pypika / test / test_functions.py View on Github external
def test__exponent__decimal(self):
        q1 = Q.from_('abc').select(F('a') ** 0.5)
        q2 = Q.from_(self.t).select(self.t.a ** 0.5)

        self.assertEqual('SELECT POW(a,0.5) FROM abc', str(q1))
        self.assertEqual('SELECT POW(a,0.5) FROM abc', str(q2))
github kayak / pypika / test / test_criterions.py View on Github external
def test__between_number(self):
        c1 = Field('foo').isin([0, 1])
        c2 = Field('foo', table=self.t).isin([0, 1])

        self.assertEqual('foo IN (0,1)', str(c1))
        self.assertEqual('t0.foo IN (0,1)', str(c2))
github kayak / pypika / test / test_criterions.py View on Github external
def test__criterion_lte_datetime(self):
        c1 = Field('foo') <= datetime(2000, 1, 1, 12, 30, 55)
        c2 = Field('foo', table=self.t).lte(datetime(2000, 1, 1, 12, 30, 55))

        self.assertEqual("foo<='2000-01-01T12:30:55'", str(c1))
        self.assertEqual("t0.foo<='2000-01-01T12:30:55'", str(c2))
github kayak / pypika / test / test_criterions.py View on Github external
def test__nested__or(self):
        c = (Field('foo') == 1) | (Field('bar') == 2) | (Field('buz') == 3)

        self.assertEqual('foo=1 OR bar=2 OR buz=3', str(c))
github kayak / pypika / test / test_selects.py View on Github external
def test_join(self):
        subquery = Query.from_('efg').select('fiz', 'buz').where(F('buz') == 0)
        q = Query.from_(self.t).join(subquery).on(
            self.t.bar == subquery.buz
        ).select(self.t.foo, subquery.fiz)

        self.assertEqual('SELECT t0.foo,t1.fiz FROM abc t0 '
                         'JOIN (SELECT fiz,buz FROM efg WHERE buz=0) t1 '
                         'ON t0.bar=t1.buz', str(q))
github kayak / pypika / test / test_criterions.py View on Github external
def test__criterion_eq_right(self):
        c1 = 1 == Field('foo')
        c2 = -1 == Field('foo', table=self.t)

        self.assertEqual('foo=1', str(c1))
        self.assertEqual('t0.foo=-1', str(c2))
github kayak / pypika / test / test_criterions.py View on Github external
def test__criterion_lt_datetime(self):
        c1 = Field('foo') < datetime(2000, 1, 1, 12, 30, 55)
        c2 = Field('foo', table=self.t).lt(datetime(2000, 1, 1, 12, 30, 55))

        self.assertEqual("foo<'2000-01-01T12:30:55'", str(c1))
        self.assertEqual("t0.foo<'2000-01-01T12:30:55'", str(c2))