예제 #1
0
def test_column_selection_alias(table_a, dialect_cls):
    q = (Q.select(table_a["col1"].alias("col1_alias")).from_(table_a).compile(
        dialect_cls))

    assert q == "select col1 as col1_alias from table_a;"
예제 #2
0
def test_select_table_star(table_a, dialect_cls):
    q = Q.select(table_a.all()).from_(table_a).compile(dialect_cls)

    assert q == "select table_a.* from table_a;"
예제 #3
0
def test_column_selection(table_a, dialect_cls):
    q = Q.select(table_a["col1"],
                 table_a["col2"]).from_(table_a).compile(dialect_cls)

    assert q == "select col1, col2 from table_a;"
예제 #4
0
def test_select_star(table_a, dialect_cls):
    q = Q.select().from_(table_a).compile(dialect_cls)

    assert q == "select * from table_a;"
예제 #5
0
def test_empty_select_query_raises_compile_error(table_a, dialect_cls):
    with pytest.raises(CompilationError):
        # This should raise a CompilationError
        Q.select().compile(dialect_cls)
예제 #6
0
def test_distinct(dialect_cls):
    q = Q.select().from_(test_table).distinct()
    expected = "select distinct * from test_table;"
    assert q.compile(dialect_cls) == expected
예제 #7
0
    assert q == "select col1, col2 from table_a;"


def test_column_selection_alias(table_a, dialect_cls):
    q = (Q.select(table_a["col1"].alias("col1_alias")).from_(table_a).compile(
        dialect_cls))

    assert q == "select col1 as col1_alias from table_a;"


@pytest.mark.parametrize(
    ["q", "expected"],
    [
        (
            Q.select().from_(test_table).where(test_table["col1"] == 120),
            "select * from test_table where col1 = 120;",
        ),
        (
            Q.select().from_(test_table).where(120 == test_table["col1"]),
            "select * from test_table where col1 = 120;",
        ),
        (
            Q.select().from_(test_table).where(
                test_table["col1"].like("%abc")),
            "select * from test_table where col1 like '%abc';",
        ),
        (
            Q.select().from_(test_table).where(
                test_table["col1"] < test_table["col2"]),
            "select * from test_table where col1 < col2;",
예제 #8
0
import pytest

from fluentql import GenericSQLDialect, Q
from fluentql.types import Table

test_table = Table("test_table")


@pytest.fixture
def dialect_cls():
    return GenericSQLDialect


@pytest.mark.parametrize(
    ["q", "expected"],
    [
        (Q.delete().from_(test_table), "delete from test_table;"),
        (
            Q.delete().from_(test_table).where(test_table["col1"] > 100),
            "delete from test_table where col1 > 100;",
        ),
    ],
)
def test_delete_query(q, expected, dialect_cls):
    assert q.compile(dialect_cls) == expected