Ejemplo n.º 1
0
def test_where_and(engine):
    sql = c.Where(
        e.And(
            e.Like(e.Identifier('name'), 'Mo%'),
            e.GreaterThan(e.Identifier('age'), 18),
        ))
    assert sql.__sql__(engine) == Sql('''
        WHERE "name" LIKE 'Mo%' AND "age" > 18
    '''.strip())
Ejemplo n.º 2
0
def test_select_order_by_desc(engine):
    statement = s.Select(
        c.Select(n.star),
        c.From(e.Identifier('person')),
        c.Where(e.Like(e.Identifier('name'), 'Mosky%')),
        c.OrderBy(m.Ordering(e.Identifier('age'), 'desc')),
    )
    assert statement.__sql__(engine) == Sql('''
        SELECT * FROM "person" WHERE "name" LIKE 'Mosky%' ORDER BY "age" DESC
    '''.strip())
Ejemplo n.º 3
0
def test_select_where_like(engine):
    statement = s.Select(
        c.Select(n.star),
        c.From(e.Identifier('person')),
        c.Where(e.Like(e.Identifier('name'), 'Mosky%')),
        c.Limit(3), c.Offset(1),
    )
    assert statement.__sql__(engine) == Sql('''
        SELECT * FROM "person" WHERE "name" LIKE 'Mosky%' LIMIT 3 OFFSET 1
    '''.strip())
Ejemplo n.º 4
0
def test_select_where_greater_than_like(engine):
    statement = s.Select(
        c.Select(n.star),
        c.From(e.Identifier('person')),
        c.Where(e.And(
            e.GreaterThan(e.Identifier('age'), 20),
            e.Like(e.Identifier('name'), 'Mosky%'),
        )),
    )
    assert statement.__sql__(engine) == Sql('''
        SELECT * FROM "person" WHERE "age" > 20 AND "name" LIKE 'Mosky%'
    '''.strip())
Ejemplo n.º 5
0
def test_select_where_condition(engine):
    sql = s.Select(
        c.Select(e.Identifier('name')),
        c.From(e.Identifier('person')),
        c.Where(
            e.Or(
                e.Like(e.Identifier('name'), 'Mo%'),
                e.GreaterThanOrEqual(e.Identifier('age'), 18),
            )),
    )
    assert sql.__sql__(engine) == Sql('''
        SELECT "name" FROM "person" WHERE "name" LIKE 'Mo%' OR "age" >= 18
    '''.strip())