def test_remove_query(): from arangodb import query a = query.Alias("foo") c = query.Collection("bar") q = query.Query(a, c).action(query.Remove(a, c)) qstr, params = q.query() assert qstr == "FOR foo IN @@c_0 REMOVE foo IN @@c_0"
def test_query(): from arangodb import query alias = query.Alias("foo") q = query.Query(alias, query.Collection("bar"), query.Return(alias)) qstr, params = q.query() assert qstr == "FOR foo IN @@c_0 RETURN foo" assert params == { "@c_0": "bar", }
def test_remove(): from arangodb import query a = query.Alias("foo") q = query.Remove(a, query.Collection("bar")) qstr, params = q.query() assert qstr == "REMOVE foo IN @@c_0" assert params == { '@c_0': 'bar' }
def test_sort_query(): from arangodb import query a = query.Alias("foo") q = query.Query(a, query.Collection("bar")).action(a).sort(a.foo, query.Desc(a.bar)).limit(10) qstr, params = q.query() assert qstr == "FOR foo IN @@c_0 SORT foo.`foo`, foo.`bar` DESC LIMIT 10 RETURN foo" assert params == { "@c_0": "bar" }
def test_for_expr(): from arangodb import query q = query.For(query.Alias("foo"), query.Collection("bar")) assert list(q) == [ query.FOR, query.SPACE, q.alias, query.SPACE, query.IN, query.SPACE, q.list_expr, ]
def test_query_filter_and(): from arangodb import query alias = query.Alias("foo") alias2 = query.Alias("bar") q = query.Query( alias, query.Collection("bar"), query.Return(alias.bar), query.Filter(alias == "1", alias2 <= 1) ) qstr, params = q.query() assert qstr == 'FOR foo IN @@c_0 FILTER foo == @value_0 AND bar <= @value_1 RETURN foo.`bar`' assert params == { "@c_0": "bar", "value_0": "1", "value_1": 1 }
def test_fast_query(): from arangodb import query alias = query.Alias("foo") alias2 = query.Alias("bar") q = query.Query(alias, query.Collection("bar"))\ .filter(alias == "1", alias2 <= 1)\ .filter(alias != 1, alias > 1, alias < 2, alias >= 2)\ .action(alias.bar) qstr, params = q.query() assert qstr == 'FOR foo IN @@c_0 FILTER foo == @value_0 AND bar <= @value_1'\ ' AND foo != @value_2 AND foo > @value_3 AND foo < @value_4 AND foo >= @value_5 RETURN foo.`bar`' assert params == { "@c_0": "bar", "value_0": "1", "value_1": 1, 'value_2': 1, 'value_3': 1, 'value_4': 2, 'value_5': 2 }