예제 #1
0
def test_parameters_reuse():
    p = Parameters(list=[1, 2, 3])
    q = Q(lambda: f"select 1 where abc = {p['list']} or def in {p['list']}", p)

    assert q.build() == RenderedQuery(
        sql="select 1 where abc = ( :1,:2,:3 ) or def in ( :1,:2,:3 )",
        parameters=[1, 2, 3])
예제 #2
0
def test_parameters_list():
    p = Parameters(abc='abc', list=[1, 2, 3])
    q = Q(lambda: f"select 1 where abc = {p['abc']} or def in {p['list']}", p)

    assert q.build() == RenderedQuery(
        sql="select 1 where abc = :1 or def in ( :2,:3,:4 )",
        parameters=['abc', 1, 2, 3])
예제 #3
0
def test_Q_lambda_fstr_in_fn() -> None:
    # test what happens when Q call is inside another function...
    # yet another thing that broke my AST walker. I'm sure there
    # will be many more.
    ident = lambda x: x
    q = ident(Q(lambda: f"select 1"))

    assert q.build() == RenderedQuery(sql="select 1", parameters=[])
예제 #4
0
def test_parameters_getattr():
	p = Parameters(
		abc='abc'
	)
	q = Q(lambda: f"select 1 where abc = {p.abc}", p)

	assert q.build() == RenderedQuery(
		sql="select 1 where abc = :1",
		parameters=['abc']
	)
예제 #5
0
def test_Q_lambda_str() -> None:
    q = Q(lambda: "select 1")
    assert q.build() == RenderedQuery(sql="select 1", parameters=[])
예제 #6
0
def test_Q_str():
	q = Q("select 1")
	assert q.build() == RenderedQuery(
		sql="select 1",
		parameters=[]
	)