code
stringlengths 26
870k
| docstring
stringlengths 1
65.6k
| func_name
stringlengths 1
194
| language
stringclasses 1
value | repo
stringlengths 8
68
| path
stringlengths 5
194
| url
stringlengths 46
254
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
async def test_edgeql_group_duplicate_rejected_02(self):
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"BY clause cannot refer to link property and object property with "
"the same name",
):
await self.con.execute('''
WITH MODULE cards
SELECT Card {
invalid := (
GROUP .avatar
BY @text, .text
)
}
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"BY clause cannot refer to link property and object property with "
"the same name",
):
await self.con.execute('''
WITH MODULE cards
SELECT Card {
invalid := (
GROUP .avatar
BY .text, @text
)
}
''') | )
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"BY clause cannot refer to link property and object property with "
"the same name",
):
await self.con.execute( | test_edgeql_group_duplicate_rejected_02 | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_by_group_by_02(self):
res = tb.bag([
{
"elements": tb.bag([
{"key": {"cost": 1, "element": None}, "n": 3},
{"key": {"cost": 2, "element": None}, "n": 2},
{"key": {"cost": 3, "element": None}, "n": 2},
{"key": {"cost": 4, "element": None}, "n": 1},
{"key": {"cost": 5, "element": None}, "n": 1},
]),
"key": {"grouping": ["cost"]}
},
{
"elements": tb.bag([
{"key": {"cost": None, "element": "Water"}, "n": 2},
{"key": {"cost": None, "element": "Earth"}, "n": 2},
{"key": {"cost": None, "element": "Fire"}, "n": 2},
{"key": {"cost": None, "element": "Air"}, "n": 3},
]),
"key": {"grouping": ["element"]}
}
])
await self.assert_query_result(
'''
WITH MODULE cards, G := (
GROUP (
GROUP Card
BY {.element, .cost}
)
USING grouping := array_agg(.grouping)
BY grouping),
SELECT G {
key: {grouping},
elements: { n := count(.elements), key: {element, cost}}
}
''',
res,
)
await self.assert_query_result(
'''
WITH MODULE cards,
SELECT (
GROUP (
GROUP Card
BY {.element, .cost}
)
USING grouping := array_agg(.grouping)
BY grouping) {
key: {grouping},
elements: { n := count(.elements), key: {element, cost}}
}
''',
res,
) | WITH MODULE cards, G := (
GROUP (
GROUP Card
BY {.element, .cost}
)
USING grouping := array_agg(.grouping)
BY grouping),
SELECT G {
key: {grouping},
elements: { n := count(.elements), key: {element, cost}}
}
''',
res,
)
await self.assert_query_result( | test_edgeql_group_by_group_by_02 | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_by_group_by_03a(self):
await self._test_edgeql_group_by_group_by_03(
'''
with module cards
select (group Card by .element) {
el := .key.element,
groups := (
with z := (group .elements using x := .cost%2 by x)
for z in z union (
even := z.key.x,
elements := array_agg(z.elements{name, cost}),
)
)
};
'''
) | with module cards
select (group Card by .element) {
el := .key.element,
groups := (
with z := (group .elements using x := .cost%2 by x)
for z in z union (
even := z.key.x,
elements := array_agg(z.elements{name, cost}),
)
)
}; | test_edgeql_group_by_group_by_03a | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_by_group_by_03b(self):
await self._test_edgeql_group_by_group_by_03(
'''
with module cards
select (group Card by .element) {
el := .key.element,
groups := (
with z := (group .elements using x := .cost%2 by x)
select (
even := z.key.x,
elements := array_agg(z.elements{name, cost}),
)
)
};
'''
) | with module cards
select (group Card by .element) {
el := .key.element,
groups := (
with z := (group .elements using x := .cost%2 by x)
select (
even := z.key.x,
elements := array_agg(z.elements{name, cost}),
)
)
}; | test_edgeql_group_by_group_by_03b | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_by_group_by_03c(self):
await self._test_edgeql_group_by_group_by_03(
'''
with module cards
select (group Card by .element) {
el := .key.element,
groups := (
for z in (group .elements using x := .cost%2 by x) union (
even := z.key.x,
elements := array_agg(z.elements{name, cost}),
)
)
};
'''
) | with module cards
select (group Card by .element) {
el := .key.element,
groups := (
for z in (group .elements using x := .cost%2 by x) union (
even := z.key.x,
elements := array_agg(z.elements{name, cost}),
)
)
}; | test_edgeql_group_by_group_by_03c | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_errors_id(self):
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"may not name a grouping alias 'id'"
):
await self.con.execute('''
group cards::Card{name} using id := .id by id
''')
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"may not group by a field named id",
_position=44,
):
await self.con.execute('''
group cards::Card{name} by .id
''') | )
async with self.assertRaisesRegexTx(
edgedb.UnsupportedFeatureError,
r"may not group by a field named id",
_position=44,
):
await self.con.execute( | test_edgeql_group_errors_id | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_tuple_01(self):
await self.con.execute('''
create type tup {
create multi property tup -> tuple<int64, int64> ;
};
insert tup { tup := {(1, 1), (1, 2), (1, 1), (2, 1)} };
''')
await self.assert_query_result(
'''
with X := tup.tup,
group X using z := X by z;
''',
tb.bag([
{"elements": [[1, 2]], "key": {"z": [1, 2]}},
{"elements": [[2, 1]], "key": {"z": [2, 1]}},
{"elements": tb.bag([[1, 1], [1, 1]]), "key": {"z": [1, 1]}}
])
) | )
await self.assert_query_result( | test_edgeql_group_tuple_01 | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_ordering_01(self):
res = [
{
"elements": tb.bag([
{"name": "Sprite"},
{"name": "Giant eagle"},
{"name": "Djinn"}
]),
},
{
"elements": tb.bag([{"name": "Dwarf"}, {"name": "Golem"}]),
},
{
"elements": tb.bag([{"name": "Imp"}, {"name": "Dragon"}]),
},
{
"elements": tb.bag(
[{"name": "Bog monster"}, {"name": "Giant turtle"}]),
},
]
await self.assert_query_result(
'''
with GR := (group cards::Card BY .element)
select GR {
elements: {name},
}
order by .key.element;
''',
res,
)
await self.assert_query_result(
'''
with GR := (group cards::Card BY .element)
select GR {
key: {element},
elements: {name},
}
order by .key.element;
''',
res,
) | with GR := (group cards::Card BY .element)
select GR {
elements: {name},
}
order by .key.element;
''',
res,
)
await self.assert_query_result( | test_edgeql_group_ordering_01 | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_policies_01(self):
await self.con.execute('''
with module cards
alter type User {
create access policy ok allow select, delete, update read;
create access policy two_elements allow insert, update write
using (count((group .deck by .element)) = 2);
}
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"access policy violation on insert"):
await self.con.query('''
with module cards
insert User {
name := 'Sully',
deck := (select Card filter .element = 'Water')
};
''')
await self.con.query('''
with module cards
insert User {
name := 'Sully',
deck := (select Card filter .element IN {'Water', 'Air'})
};
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"access policy violation on update"):
await self.con.query('''
with module cards
update User filter .name = 'Sully' set {
deck += (select Card filter .element = 'Earth')
};
''')
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"access policy violation on update"):
await self.con.query('''
with module cards
update User filter .name = 'Sully' set {
deck -= (select Card filter .element = 'Water')
};
''') | )
async with self.assertRaisesRegexTx(
edgedb.InvalidValueError,
r"access policy violation on insert"):
await self.con.query( | test_edgeql_group_policies_01 | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_policies_02(self):
await self.con.execute(
'''
create type T {
create multi property vals -> int64;
create access policy foo allow all using (
# This is pretty pointless but should always be true
sum(((
(group x := .vals using v := x by v))
{ x := count(.elements) }).x)
= count(.vals)
)
};
insert T { vals := {1,1,2,3} };
'''
)
await self.assert_query_result(
r'''select T { vals }''',
[{'vals': tb.bag([1, 1, 2, 3])}],
) | create type T {
create multi property vals -> int64;
create access policy foo allow all using (
# This is pretty pointless but should always be true
sum(((
(group x := .vals using v := x by v))
{ x := count(.elements) }).x)
= count(.vals)
)
};
insert T { vals := {1,1,2,3} }; | test_edgeql_group_policies_02 | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_group_link_property_01(self):
await self.assert_query_result(
r'''
with module cards
select User {
cards_by_count := (group .deck by @count) {
key : {count},
elements: {name},
}
}
filter .name = 'Alice';
''',
[
{
"cards_by_count": [
{
"key": {"count": 2},
"elements": [
{"name": "Imp"},
{"name": "Dragon"}
]
},
{
"key": {"count": 3},
"elements": [
{"name": "Bog monster"},
{"name": "Giant turtle"}
]
}
]
}
],
)
await self.assert_query_result(
r'''
with module cards
select User {
cards_by_count := (group .deck by (@count, @count)) {
key : {count},
elements: {name},
}
}
filter .name = 'Alice';
''',
[
{
"cards_by_count": [
{
"key": {"count": 2},
"elements": [
{"name": "Imp"},
{"name": "Dragon"}
]
},
{
"key": {"count": 3},
"elements": [
{"name": "Bog monster"},
{"name": "Giant turtle"}
]
}
]
}
],
) | ,
[
{
"cards_by_count": [
{
"key": {"count": 2},
"elements": [
{"name": "Imp"},
{"name": "Dragon"}
]
},
{
"key": {"count": 3},
"elements": [
{"name": "Bog monster"},
{"name": "Giant turtle"}
]
}
]
}
],
)
await self.assert_query_result(
r | test_edgeql_group_link_property_01 | python | geldata/gel | tests/test_edgeql_group.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_group.py | Apache-2.0 |
async def test_edgeql_tree_delete_01(self):
await self.con.execute(r"""
DELETE Tree;
""")
await self.assert_query_result(
r"""
SELECT Tree;
""",
[],
) | )
await self.assert_query_result(
r | test_edgeql_tree_delete_01 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_delete_02(self):
await self.con.execute(r"""
DELETE Eert FILTER .val = '0';
""")
await self.assert_query_result(
r"""
SELECT Eert FILTER .val = '0';
""",
[],
) | )
await self.assert_query_result(
r | test_edgeql_tree_delete_02 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_insert_01(self):
# Test nested insert of a tree branch.
await self.con.execute(r"""
INSERT Tree {
val := 'i2',
parent := (
INSERT Tree {
val := 'i1',
parent := (
INSERT Tree {
val := 'i0',
}
),
}
),
};
""")
await self.assert_query_result(
r"""
SELECT Tree {
val,
children: {
val,
children: {
val,
children: {
val,
},
},
},
}
FILTER .val = 'i0';
""",
[{
'val': 'i0',
'children': [{
'val': 'i1',
'children': [{
'val': 'i2',
}],
}],
}],
) | )
await self.assert_query_result(
r | test_edgeql_tree_insert_01 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_insert_02(self):
# Test nested insert of a tree branch.
await self.con.execute(r"""
INSERT Eert {
val := 'i0',
children := (
INSERT DETACHED Eert {
val := 'i1',
children := (
INSERT DETACHED Eert {
val := 'i2',
}
),
}
),
};
""")
await self.assert_query_result(
r"""
SELECT Eert {
val,
children: {
val,
children: {
val,
children: {
val,
},
},
},
}
FILTER .val = 'i0';
""",
[{
'val': 'i0',
'children': [{
'val': 'i1',
'children': [{
'val': 'i2',
}],
}],
}],
) | )
await self.assert_query_result(
r | test_edgeql_tree_insert_02 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_insert_03(self):
# Test nested insert of a tree branch.
await self.con.execute(r"""
WITH
T1 := Tree,
T2 := Tree,
INSERT Tree {
val := 'i2',
parent := (
INSERT T1 {
val := 'i1',
parent := (
INSERT T2 {
val := 'i0',
}
),
}
),
};
""")
await self.assert_query_result(
r"""
SELECT Tree {
val,
children: {
val,
children: {
val,
children: {
val,
},
},
},
}
FILTER .val = 'i0';
""",
[{
'val': 'i0',
'children': [{
'val': 'i1',
'children': [{
'val': 'i2',
}],
}],
}],
) | )
await self.assert_query_result(
r | test_edgeql_tree_insert_03 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_update_01(self):
# Update all the tree nodes to base their val on the children
# vals.
await self.con.execute(
r"""
UPDATE Tree
SET {
val := array_join(
[.val, 'c'] ++ array_agg((
SELECT _ := .children.val
ORDER BY _
)),
'_'
)
}
"""
)
await self.assert_query_result(
r"""
SELECT Tree {
val,
children: {
val,
children: {
val,
children: {
val,
} ORDER BY .val,
} ORDER BY .val,
} ORDER BY .val,
}
FILTER NOT EXISTS .parent
ORDER BY .val;
""",
[
{
'val': '0_c_00_01_02',
'children': [
{
'val': '00_c_000',
'children': [{'val': '000_c', 'children': []}]
},
{
'val': '01_c_010',
'children': [{'val': '010_c', 'children': []}]
},
{
'val': '02_c',
'children': []
},
],
},
{
'val': '1_c_10_11_12_13',
'children': [
{'val': '10_c', 'children': []},
{'val': '11_c', 'children': []},
{'val': '12_c', 'children': []},
{'val': '13_c', 'children': []},
],
},
],
) | )
await self.assert_query_result(
r | test_edgeql_tree_update_01 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_update_02(self):
# Update all the tree nodes to base their val on the children
# vals.
await self.con.execute(
r"""
UPDATE Eert
SET {
val := array_join(
[.val, 'c'] ++ array_agg((
SELECT _ := .children.val
ORDER BY _
)),
'_'
)
}
"""
)
await self.assert_query_result(
r"""
SELECT Eert {
val,
children: {
val,
children: {
val,
children: {
val,
} ORDER BY .val,
} ORDER BY .val,
} ORDER BY .val,
}
FILTER NOT EXISTS .parent
ORDER BY .val;
""",
[
{
'val': '0_c_00_01_02',
'children': [
{
'val': '00_c_000',
'children': [{'val': '000_c', 'children': []}]
},
{
'val': '01_c_010',
'children': [{'val': '010_c', 'children': []}]
},
{
'val': '02_c',
'children': []
},
],
},
{
'val': '1_c_10_11_12_13',
'children': [
{'val': '10_c', 'children': []},
{'val': '11_c', 'children': []},
{'val': '12_c', 'children': []},
{'val': '13_c', 'children': []},
],
},
],
) | )
await self.assert_query_result(
r | test_edgeql_tree_update_02 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_update_03(self):
# Update all the tree nodes to base their val on the parent
# val.
await self.con.execute(
r"""
UPDATE Tree
SET {
val := .val ++ '_p' ++ (('_' ++ .parent.val) ?? '')
};
"""
)
await self.assert_query_result(
r"""
SELECT Tree {val}
ORDER BY .val;
""",
[
{'val': '000_p_00'},
{'val': '00_p_0'},
{'val': '010_p_01'},
{'val': '01_p_0'},
{'val': '02_p_0'},
{'val': '0_p'},
{'val': '10_p_1'},
{'val': '11_p_1'},
{'val': '12_p_1'},
{'val': '13_p_1'},
{'val': '1_p'},
]
) | )
await self.assert_query_result(
r | test_edgeql_tree_update_03 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_update_04(self):
# Update all the tree nodes to base their val on the parent
# val.
await self.con.execute(
r"""
UPDATE Eert
SET {
val := .val ++ '_p' ++ (('_' ++ .parent.val) ?? '')
};
"""
)
await self.assert_query_result(
r"""
SELECT Eert {val}
ORDER BY .val;
""",
[
{'val': '000_p_00'},
{'val': '00_p_0'},
{'val': '010_p_01'},
{'val': '01_p_0'},
{'val': '02_p_0'},
{'val': '0_p'},
{'val': '10_p_1'},
{'val': '11_p_1'},
{'val': '12_p_1'},
{'val': '13_p_1'},
{'val': '1_p'},
]
) | )
await self.assert_query_result(
r | test_edgeql_tree_update_04 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_update_05(self):
# Swap around a tree node and its first child as an atomic operation.
#
# The same basic principle might be used to swap around 2
# nodes in a linked-list, but we'll use trees since we have
# them already.
await self.con.execute(
r"""
WITH
# start with node '00'
T00 := (
SELECT Tree
FILTER .val = '00'
),
# update its first child node ('000')
TC := (
UPDATE (SELECT T00.children
ORDER BY .val
LIMIT 1)
SET {parent := T00.parent}
),
UPDATE T00
SET {parent := TC};
"""
)
await self.assert_query_result(
r"""
SELECT Tree {
val,
children: {
val,
children: {
val,
children: {
val,
} ORDER BY .val,
} ORDER BY .val,
} ORDER BY .val,
}
FILTER .val = '0'
ORDER BY .val;
""",
[
{
'val': '0',
'children': [
{
'val': '000',
'children': [{'val': '00', 'children': []}]
},
{
'val': '01',
'children': [{'val': '010', 'children': []}]
},
{
'val': '02',
'children': []
},
],
},
],
) | )
await self.assert_query_result(
r | test_edgeql_tree_update_05 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_update_06(self):
# Swap around a tree node and its first child as an atomic operation.
#
# The same basic principle might be used to swap around 2
# nodes in a linked-list, but we'll use trees since we have
# them already.
#
# With this particular structure swapping nodes is awkward
# because children lists for 3 nodes must be updated. The
# whole point of this exercise it to try and express this as a
# single command to make it atomic without needing to use
# transactions.
await self.con.execute(
r"""
WITH
# start with node '00'
T00 := (
SELECT Eert
FILTER .val = '00'
),
# grab the parent of '00'
TP := T00.parent,
# update its first child node ('000')
TC := (
UPDATE (
SELECT T00.children
ORDER BY .val
LIMIT 1
)
SET {
children := {.children, T00}
}
),
T00_up := (
UPDATE T00
SET {
children := (
SELECT _ := T00.children
FILTER _ != TC
)
}
),
# update the original parent of '00'
UPDATE TP
SET {
children := (
SELECT _ := {.children, T00_up}
FILTER _ != T00
)
}
"""
)
await self.assert_query_result(
r"""
SELECT Eert {
val,
children: {
val,
children: {
val,
children: {
val,
} ORDER BY .val,
} ORDER BY .val,
} ORDER BY .val,
}
FILTER .val = '0'
ORDER BY .val;
""",
[
{
'val': '0',
'children': [
{
'val': '000',
'children': [{'val': '00', 'children': []}]
},
{
'val': '01',
'children': [{'val': '010', 'children': []}]
},
{
'val': '02',
'children': []
},
],
},
],
) | )
await self.assert_query_result(
r | test_edgeql_tree_update_06 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_update_07(self):
# Swap around a tree node and its parent as an atomic operation.
#
# The same basic principle might be used to swap around 2
# nodes in a linked-list, but we'll use trees since we have
# them already.
await self.con.execute(
r"""
WITH
# start with node '000', get its parent
TP := (
SELECT Tree
FILTER .val = '000'
).parent,
# move the '000' node
T000 := (
UPDATE Tree
FILTER .val = '000'
SET {parent := .parent.parent}
)
UPDATE TP
SET {parent := T000};
"""
)
await self.assert_query_result(
r"""
SELECT Tree {
val,
children: {
val,
children: {
val,
children: {
val,
} ORDER BY .val,
} ORDER BY .val,
} ORDER BY .val,
}
FILTER .val = '0'
ORDER BY .val;
""",
[
{
'val': '0',
'children': [
{
'val': '000',
'children': [{'val': '00', 'children': []}]
},
{
'val': '01',
'children': [{'val': '010', 'children': []}]
},
{
'val': '02',
'children': []
},
],
},
],
) | )
await self.assert_query_result(
r | test_edgeql_tree_update_07 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
async def test_edgeql_tree_update_08(self):
# Swap around a tree node and its parent as an atomic operation.
#
# The same basic principle might be used to swap around 2
# nodes in a linked-list, but we'll use trees since we have
# them already.
#
# With this particular structure swapping nodes is awkward
# because children lists for 3 nodes must be updated. The
# whole point of this exercise it to try and express this as a
# single command to make it atomic without needing to use
# transactions.
await self.con.execute(
r"""
WITH
# start with node '000'
T000 := (
SELECT Eert
FILTER .val = '000'
),
# update the parent of '000'
TP := (
UPDATE (SELECT T000.parent)
SET {
children := (
SELECT _ := .children
FILTER _ != T000
)
}
),
# update the grand-parent of '000'
TPP := (
UPDATE (SELECT TP.parent)
SET {
children := (
SELECT _ := assert_distinct({.children, T000})
FILTER _ != TP
)
}
)
# update node '000'
UPDATE (SELECT _ := TPP.children FILTER _ = T000)
SET {
children := assert_distinct({.children, TP})
};
"""
)
await self.assert_query_result(
r"""
SELECT Eert {
val,
children: {
val,
children: {
val,
children: {
val,
} ORDER BY .val,
} ORDER BY .val,
} ORDER BY .val,
}
FILTER .val = '0'
ORDER BY .val;
""",
[
{
'val': '0',
'children': [
{
'val': '000',
'children': [{'val': '00', 'children': []}]
},
{
'val': '01',
'children': [{'val': '010', 'children': []}]
},
{
'val': '02',
'children': []
},
],
},
],
) | )
await self.assert_query_result(
r | test_edgeql_tree_update_08 | python | geldata/gel | tests/test_edgeql_tree.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_tree.py | Apache-2.0 |
def test_http_edgeql_query_04(self):
with self.assertRaisesRegex(
edgedb.QueryError,
r'parameter \$name is required'):
self.edgeql_query(
r"""
SELECT Setting {
name,
value
}
FILTER .name = <str>$name;
"""
)
with self.assertRaisesRegex(
edgedb.QueryError,
r'parameter \$name is required'):
self.edgeql_query(
r"""
SELECT Setting {
name,
value
}
FILTER .name = <str>$name;
""",
variables={'name': None}) | )
with self.assertRaisesRegex(
edgedb.QueryError,
r'parameter \$name is required'):
self.edgeql_query(
r | test_http_edgeql_query_04 | python | geldata/gel | tests/test_http_edgeql.py | https://github.com/geldata/gel/blob/master/tests/test_http_edgeql.py | Apache-2.0 |
async def test_http_edgeql_cors(self):
try:
req = urllib.request.Request(self.http_addr, method='OPTIONS')
req.add_header('Origin', 'https://example.edgedb.com')
response = urllib.request.urlopen(
req, context=self.tls_context
)
self.assertNotIn('Access-Control-Allow-Origin', response.headers)
_, response = self.edgeql_query(
r"""
SELECT User {
name,
age,
groups: { name }
}
FILTER .name = <str>$name AND .age = <int64>$age;
""",
variables=dict(name='Bob', age=21),
origin='https://example.edgedb.com'
)
self.assertNotIn('Access-Control-Allow-Origin', response.headers)
await self.con.execute(
'configure current database '
'set cors_allow_origins := {"https://example.edgedb.com"}')
await self._wait_for_db_config('cors_allow_origins')
req = urllib.request.Request(self.http_addr, method='OPTIONS')
req.add_header('Origin', 'https://other.edgedb.com')
response = urllib.request.urlopen(
req, context=self.tls_context
)
self.assertNotIn('Access-Control-Allow-Origin', response.headers)
req = urllib.request.Request(self.http_addr, method='OPTIONS')
req.add_header('Origin', 'https://example.edgedb.com')
response = urllib.request.urlopen(
req, context=self.tls_context
)
headers = response.headers
self.assertIn('Access-Control-Allow-Origin', headers)
self.assertEqual(
headers['Access-Control-Allow-Origin'],
'https://example.edgedb.com'
)
self.assertIn('POST', headers['Access-Control-Allow-Methods'])
self.assertIn('GET', headers['Access-Control-Allow-Methods'])
self.assertIn(
'Authorization', headers['Access-Control-Allow-Headers']
)
self.assertIn(
'X-EdgeDB-User', headers['Access-Control-Allow-Headers']
)
self.assertEqual(
headers['Access-Control-Allow-Credentials'], 'true'
)
await self.con.execute(
'configure current database '
'set cors_allow_origins := {"https://other.edgedb.com"}')
await self._wait_for_db_config(
'cors_allow_origins', value=["https://other.edgedb.com"])
req = urllib.request.Request(self.http_addr, method='OPTIONS')
req.add_header('Origin', 'https://example.edgedb.com')
response = urllib.request.urlopen(
req, context=self.tls_context
)
self.assertNotIn('Access-Control-Allow-Origin', response.headers)
req = urllib.request.Request(self.http_addr, method='OPTIONS')
req.add_header('Origin', 'https://other.edgedb.com')
response = urllib.request.urlopen(
req, context=self.tls_context
)
self.assertIn('Access-Control-Allow-Origin', response.headers)
_, response = self.edgeql_query(
r"""
SELECT User {
name,
age,
groups: { name }
}
FILTER .name = <str>$name AND .age = <int64>$age;
""",
variables=dict(name='Bob', age=21),
origin='https://other.edgedb.com'
)
self.assertIn('Access-Control-Allow-Origin', response.headers)
finally:
await self.con.execute(
'configure current database reset cors_allow_origins') | ,
variables=dict(name='Bob', age=21),
origin='https://example.edgedb.com'
)
self.assertNotIn('Access-Control-Allow-Origin', response.headers)
await self.con.execute(
'configure current database '
'set cors_allow_origins := {"https://example.edgedb.com"}')
await self._wait_for_db_config('cors_allow_origins')
req = urllib.request.Request(self.http_addr, method='OPTIONS')
req.add_header('Origin', 'https://other.edgedb.com')
response = urllib.request.urlopen(
req, context=self.tls_context
)
self.assertNotIn('Access-Control-Allow-Origin', response.headers)
req = urllib.request.Request(self.http_addr, method='OPTIONS')
req.add_header('Origin', 'https://example.edgedb.com')
response = urllib.request.urlopen(
req, context=self.tls_context
)
headers = response.headers
self.assertIn('Access-Control-Allow-Origin', headers)
self.assertEqual(
headers['Access-Control-Allow-Origin'],
'https://example.edgedb.com'
)
self.assertIn('POST', headers['Access-Control-Allow-Methods'])
self.assertIn('GET', headers['Access-Control-Allow-Methods'])
self.assertIn(
'Authorization', headers['Access-Control-Allow-Headers']
)
self.assertIn(
'X-EdgeDB-User', headers['Access-Control-Allow-Headers']
)
self.assertEqual(
headers['Access-Control-Allow-Credentials'], 'true'
)
await self.con.execute(
'configure current database '
'set cors_allow_origins := {"https://other.edgedb.com"}')
await self._wait_for_db_config(
'cors_allow_origins', value=["https://other.edgedb.com"])
req = urllib.request.Request(self.http_addr, method='OPTIONS')
req.add_header('Origin', 'https://example.edgedb.com')
response = urllib.request.urlopen(
req, context=self.tls_context
)
self.assertNotIn('Access-Control-Allow-Origin', response.headers)
req = urllib.request.Request(self.http_addr, method='OPTIONS')
req.add_header('Origin', 'https://other.edgedb.com')
response = urllib.request.urlopen(
req, context=self.tls_context
)
self.assertIn('Access-Control-Allow-Origin', response.headers)
_, response = self.edgeql_query(
r | test_http_edgeql_cors | python | geldata/gel | tests/test_http_edgeql.py | https://github.com/geldata/gel/blob/master/tests/test_http_edgeql.py | Apache-2.0 |
async def test_edgeql_coalesce_scalar_09(self):
await self.assert_query_result(
r'''
# Only values present in the graph will be selected.
SELECT Issue.time_estimate ?= 60;
''',
[
False, False, True,
],
sort=True
)
await self.assert_query_result(
r'''
SELECT Issue.time_estimate ?= <int64>{};
''',
[
False, False, False,
],
sort=True
) | ,
[
False, False, True,
],
sort=True
)
await self.assert_query_result(
r | test_edgeql_coalesce_scalar_09 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_scalar_11(self):
await self.assert_query_result(
r'''
# No open issue has a time_estimate, so the first argument
# to ?!= is an empty set.
WITH
I := (SELECT Issue
FILTER Issue.status.name = 'Open')
SELECT I.time_estimate ?!= <int64>{};
''',
[
False
]
)
await self.assert_query_result(
r'''
WITH
I := (SELECT Issue
FILTER Issue.status.name = 'Open')
SELECT I.time_estimate ?!= 60;
''',
[
True
]
) | ,
[
False
]
)
await self.assert_query_result(
r | test_edgeql_coalesce_scalar_11 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_scalar_12(self):
await self.assert_query_result(
r'''
SELECT Issue {
number,
time_estimate,
related_to: {time_estimate},
}
ORDER BY Issue.number;
''',
[
{'number': '1', 'related_to': [], 'time_estimate': 60},
{'number': '2', 'related_to': [], 'time_estimate': 90},
{'number': '3', 'related_to': [], 'time_estimate': 90},
{'number': '4', 'related_to': [], 'time_estimate': None},
{
'number': '5',
'related_to': [{'time_estimate': 60}],
'time_estimate': None,
},
{
'number': '6',
'related_to': [{'time_estimate': 90}],
'time_estimate': None,
},
]
)
await self.assert_query_result(
r'''
# now test a combination of several coalescing operators
SELECT
Issue.time_estimate ??
Issue.related_to.time_estimate ?=
<int64>Issue.number * 12
ORDER BY Issue.number;
''',
[
False, False, False, False, True, False,
]
) | ,
[
{'number': '1', 'related_to': [], 'time_estimate': 60},
{'number': '2', 'related_to': [], 'time_estimate': 90},
{'number': '3', 'related_to': [], 'time_estimate': 90},
{'number': '4', 'related_to': [], 'time_estimate': None},
{
'number': '5',
'related_to': [{'time_estimate': 60}],
'time_estimate': None,
},
{
'number': '6',
'related_to': [{'time_estimate': 90}],
'time_estimate': None,
},
]
)
await self.assert_query_result(
r | test_edgeql_coalesce_scalar_12 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_dependent_20(self):
await self.assert_query_result(
r'''
WITH
I := (
SELECT Issue
FILTER Issue.status.name = 'Open'
)
# `I.time_estimate` is now a LCP
SELECT I.time_estimate ?= I.time_estimate * 2;
''',
[
True,
],
)
await self.assert_query_result(
r'''
WITH
I := (
SELECT Issue
FILTER Issue.status.name = 'Open'
)
# `I.time_estimate` is now a LCP
SELECT I.time_estimate ?= (I.time_estimate,).0;
''',
[
True,
],
)
await self.assert_query_result(
r'''
WITH
I := (
SELECT Issue
FILTER Issue.status.name = 'Open'
)
# `I.time_estimate` is now a LCP
SELECT (I.time_estimate,).0 ?= (I.time_estimate,).0;
''',
[
True,
],
)
await self.assert_query_result(
r'''
WITH
I := (
SELECT Issue
FILTER Issue.status.name = 'Open'
)
# `I.time_estimate` is now a LCP
SELECT ((I.time_estimate,).0,).0 ?= (I.time_estimate,).0;
''',
[
True,
],
)
await self.assert_query_result(
r'''
WITH
I := (
SELECT Issue
FILTER Issue.status.name = 'Open'
)
# `I.time_estimate` is now a LCP
SELECT
({I.time_estimate} = 0) ?=
(({I.time_estimate} = 0) = (I.time_estimate = 0));
''',
[
True,
],
)
await self.assert_query_result(
r'''
WITH
I := (
SELECT Issue
FILTER Issue.status.name = 'Open'
)
# `I.time_estimate` is now a LCP
SELECT {I.time_estimate} ?= (I.time_estimate,).0;
''',
[
True,
],
) | ,
[
True,
],
)
await self.assert_query_result(
r | test_edgeql_coalesce_dependent_20 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_dependent_22(self):
await self.assert_query_result(
r'''
WITH
X := {Priority, Status}
SELECT X[IS Priority].name[0] ?? X[IS Status].name;
''',
{'H', 'L', 'Open', 'Closed'},
)
await self.assert_query_result(
r'''
WITH
X := {Priority, Status}
SELECT X[IS Priority].name ?? X[IS Status].name[0];
''',
{'High', 'Low', 'O', 'C'},
)
await self.assert_query_result(
r'''
WITH
X := {Priority, Status}
SELECT X[IS Priority].name[0] ?? X[IS Status].name[0];
''',
{'H', 'L', 'O', 'C'},
) | ,
{'H', 'L', 'Open', 'Closed'},
)
await self.assert_query_result(
r | test_edgeql_coalesce_dependent_22 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_dependent_23(self):
await self.assert_query_result(
r'''
WITH
X := {Priority, Status}
SELECT X {
foo := X[IS Priority].name ?? X[IS Status].name
};
''',
[
{'foo': 'Closed'},
{'foo': 'High'},
{'foo': 'Low'},
{'foo': 'Open'}
],
sort=lambda x: x['foo']
)
await self.assert_query_result(
r'''
WITH
X := {Priority, Status}
SELECT X {
foo := X[IS Priority].name[0] ?? X[IS Status].name
};
''',
[
{'foo': 'Closed'},
{'foo': 'H'},
{'foo': 'L'},
{'foo': 'Open'}
],
sort=lambda x: x['foo']
)
await self.assert_query_result(
r'''
WITH
X := {Priority, Status}
SELECT X {
foo := X[IS Priority].name ?? X[IS Status].name[0]
};
''',
[
{'foo': 'C'},
{'foo': 'High'},
{'foo': 'Low'},
{'foo': 'O'}
],
sort=lambda x: x['foo']
)
await self.assert_query_result(
r'''
WITH
X := {Priority, Status}
SELECT X {
foo := X[IS Priority].name[0] ?? X[IS Status].name[0]
};
''',
[
{'foo': 'C'},
{'foo': 'H'},
{'foo': 'L'},
{'foo': 'O'}
],
sort=lambda x: x['foo']
) | ,
[
{'foo': 'Closed'},
{'foo': 'High'},
{'foo': 'Low'},
{'foo': 'Open'}
],
sort=lambda x: x['foo']
)
await self.assert_query_result(
r | test_edgeql_coalesce_dependent_23 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_wrapping_optional(self):
await self.con.execute(
r'''
CREATE FUNCTION optfunc(
a: std::str, b: OPTIONAL std::str) -> OPTIONAL std::str
USING EdgeQL $$
SELECT b IF a = 'foo' ELSE a
$$;
'''
)
await self.assert_query_result(
r'''
SELECT optfunc('foo', <str>{}) ?? 'N/A';
''',
['N/A'],
)
await self.assert_query_result(
r'''
SELECT optfunc('foo', 'b') ?? 'N/A';
''',
['b'],
)
await self.assert_query_result(
r'''
SELECT optfunc('a', <str>{}) ?? 'N/A';
''',
['a'],
) | )
await self.assert_query_result(
r | test_edgeql_coalesce_wrapping_optional | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_set_of_11(self):
await self.assert_query_result(
r'''
SELECT (Publication.title ?= "", count(Publication))
''',
[[False, 0]],
)
await self.assert_query_result(
r'''
SELECT (count(Publication), Publication.title ?= "")
''',
[[False, 0]],
) | ,
[[False, 0]],
)
await self.assert_query_result(
r | test_edgeql_coalesce_set_of_11 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_set_of_nonempty_01(self):
await self.con.execute(
'''INSERT Publication { title := "1" }''')
await self.con.execute(
'''INSERT Publication { title := "asdf" }''')
await self.assert_query_result(
r'''
SELECT Publication.title ?= <str>count(Publication)
''',
[True, False],
) | INSERT Publication { title := "1" }''')
await self.con.execute(
'''INSERT Publication { title := "asdf" }''')
await self.assert_query_result(
r | test_edgeql_coalesce_set_of_nonempty_01 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_correlation_03(self):
# TODO: add this to the schema if we want more like it
await self.con.execute('''
CREATE FUNCTION opts(x: OPTIONAL str) -> OPTIONAL str {
USING (x) };
''')
await self.assert_query_result(
r'''
SELECT _ := (
count(Issue),
opts((SELECT (<str>Issue.time_estimate))),
) ORDER BY _;
''',
[[6, "60"], [6, "90"], [6, "90"]],
) | )
await self.assert_query_result(
r | test_edgeql_coalesce_correlation_03 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_tuple_07(self):
await self.assert_query_result(
r'''
SELECT (SELECT () FILTER false) ?? {(), ()};
''',
[
[], []
],
)
await self.assert_query_result(
r'''
SELECT (SELECT () FILTER true) ?? {(), ()};
''',
[
[]
],
)
await self.assert_query_result(
r'''
SELECT (SELECT ((), ()) FILTER true) ?? {((), ()), ((), ())}
''',
[
[[], []]
],
) | ,
[
[], []
],
)
await self.assert_query_result(
r | test_edgeql_coalesce_tuple_07 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_tuple_08(self):
await self.con.execute('''
CREATE TYPE Foo {
CREATE PROPERTY bar -> tuple<int64, int64>;
CREATE PROPERTY baz -> tuple<tuple<int64, int64>, str>;
};
''')
await self.assert_query_result(
r'''
SELECT Foo.bar ?? (1, 2)
''',
[[1, 2]],
)
await self.assert_query_result(
r'''
SELECT Foo.bar UNION (1, 2)
''',
[[1, 2]],
)
await self.assert_query_result(
r'''
SELECT (Foo.bar ?? (1, 2)).0
''',
[1],
)
await self.assert_query_result(
r'''
SELECT (Foo.bar UNION (1, 2)).0
''',
[1],
)
await self.assert_query_result(
r'''
SELECT (Foo.baz ?? ((1, 2), 'huh')).0.1
''',
[2],
)
# Insert some data and mess around some more
await self.con.execute('''
INSERT Foo { bar := (3, 4), baz := ((3, 4), 'test') }
''')
await self.assert_query_result(
r'''
SELECT ([Foo.bar], array_agg(Foo.bar));
''',
[[[[3, 4]], [[3, 4]]]],
)
await self.assert_query_result(
r'''
SELECT Foo.bar ?? (1, 2)
''',
[[3, 4]],
)
await self.assert_query_result(
r'''
SELECT _ := Foo.bar UNION (1, 2) ORDER BY _;
''',
[[1, 2], [3, 4]],
)
await self.assert_query_result(
r'''
SELECT (Foo.bar ?? (1, 2)).1
''',
[4],
)
await self.assert_query_result(
r'''
SELECT _ := (Foo.bar UNION (1, 2)).0 ORDER BY _;
''',
[1, 3],
)
await self.assert_query_result(
r'''
SELECT (Foo.baz ?? ((1, 2), 'huh')).0.1
''',
[4],
)
await self.assert_query_result(
r'''
WITH W := (Foo.baz UNION ((1, 2), 'huh')),
SELECT (W, W.1, W.0.0) ORDER BY W;
''',
[
[[[1, 2], "huh"], "huh", 1],
[[[3, 4], "test"], "test", 3],
],
) | )
await self.assert_query_result(
r | test_edgeql_coalesce_tuple_08 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_overload_01(self):
# first argument bool -> optional second arg
await self.assert_query_result(
r'''
SELECT Issue.name ++ opt_test(false, <str>Issue.time_estimate)
''',
{
"Issue 160", "Issue 290", "Issue 390",
"Issue 4", "Issue 5", "Issue 6",
},
)
await self.assert_query_result(
r'''
SELECT (Issue.name, opt_test(false, Issue.time_estimate))
''',
{
("Issue 1", 60),
("Issue 2", 90),
("Issue 3", 90),
("Issue 4", -1),
("Issue 5", -1),
("Issue 6", -1),
},
)
await self.assert_query_result(
r'''
SELECT opt_test(true, <str>Issue.time_estimate)
''',
tb.bag(["60", "90", "90"]),
)
await self.assert_query_result(
r'''
SELECT opt_test(true, Issue.time_estimate)
''',
tb.bag([60, 90, 90]),
)
await self.assert_query_result(
r'''
select Issue { z := opt_test(true, .time_estimate) }
''',
tb.bag([
{"z": 60}, {"z": 90}, {"z": 90},
{"z": -1}, {"z": -1}, {"z": -1}
]),
)
await self.assert_query_result(
r'''
select Issue { z := opt_test(true, .time_estimate, 1) }
''',
tb.bag([
{"z": 1}, {"z": 1}, {"z": 1},
{"z": 1}, {"z": 1}, {"z": 1},
]),
) | ,
{
"Issue 160", "Issue 290", "Issue 390",
"Issue 4", "Issue 5", "Issue 6",
},
)
await self.assert_query_result(
r | test_edgeql_coalesce_overload_01 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_overload_02(self):
# first argument int -> singleton second arg
await self.assert_query_result(
r'''
SELECT Issue.name ++ opt_test(0, <str>Issue.time_estimate)
''',
{
"Issue 160", "Issue 290", "Issue 390",
},
)
await self.assert_query_result(
r'''
SELECT (Issue.name, opt_test(0, Issue.time_estimate))
''',
{
("Issue 1", 60),
("Issue 2", 90),
("Issue 3", 90),
},
)
await self.assert_query_result(
r'''
SELECT opt_test(0, <str>Issue.time_estimate)
''',
tb.bag(["60", "90", "90"]),
)
await self.assert_query_result(
r'''
SELECT opt_test(0, Issue.time_estimate)
''',
tb.bag([60, 90, 90]),
)
await self.assert_query_result(
r'''
select Issue { z := opt_test(0, .time_estimate) }
''',
tb.bag([
{"z": 60}, {"z": 90}, {"z": 90},
{"z": None}, {"z": None}, {"z": None}
]),
)
await self.assert_query_result(
r'''
select Issue { z := opt_test(0, .time_estimate, 1) }
''',
tb.bag([
{"z": 1}, {"z": 1}, {"z": 1},
{"z": None}, {"z": None}, {"z": None}
]),
) | ,
{
"Issue 160", "Issue 290", "Issue 390",
},
)
await self.assert_query_result(
r | test_edgeql_coalesce_overload_02 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_coalesce_single_links_01(self):
await self.con.execute(
'''
CREATE TYPE default::Content;
CREATE TYPE default::Noob {
CREATE LINK primary: default::Content;
CREATE LINK secondary: default::Content;
};
insert Noob {
primary := (insert Content)
};
insert Noob {
secondary := (insert Content)
};
'''
)
await self.assert_query_result(
r'''
select Noob {
coalesce := (.primary ?? .secondary),
};
''',
[
{'coalesce': {'id': str}},
{'coalesce': {'id': str}},
],
implicit_limit=100,
)
await self.assert_query_result(
r'''
select Noob {
coalesce := (select (.primary ?? .secondary) limit 100),
};
''',
[
{'coalesce': {'id': str}},
{'coalesce': {'id': str}},
],
)
await self.assert_query_result(
r'''
select Noob {
coalesce := {.primary ?? .secondary},
};
''',
[
{'coalesce': {'id': str}},
{'coalesce': {'id': str}},
],
) | CREATE TYPE default::Content;
CREATE TYPE default::Noob {
CREATE LINK primary: default::Content;
CREATE LINK secondary: default::Content;
};
insert Noob {
primary := (insert Content)
};
insert Noob {
secondary := (insert Content)
}; | test_edgeql_coalesce_single_links_01 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_optional_leakage_01(self):
await self.con.execute(
r'''
insert Comment {
body := "a",
owner := assert_single(User),
issue := (select Issue limit 1),
};
'''
)
await self.assert_query_result(
'''
select (
Comment,
(select (
<str>Comment.parent.id ?= '',
Comment.body
)),
);
''',
[({}, (False, 'a'))],
)
await self.assert_query_result(
r'''
select (
Comment.body,
(select (
<str>Comment.parent.id ?= '' or
Comment.id ?= <uuid>{}
)),
) filter .1;
''',
[],
) | )
await self.assert_query_result( | test_edgeql_optional_leakage_01 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_optional_ensure_source_01(self):
await self.assert_query_result(
r'''
with x := array_unpack(<array<Issue>>[])
select (x.name ?= x.body);
''',
[True],
)
await self.assert_query_result(
r'''
with user := array_unpack(<array<Object>>[])
select
(<str>user.id ?? "") ++ <str>(exists user);
''',
["false"],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_optional_ensure_source_01 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_edgeql_optional_ensure_source_02(self):
await self.con.execute('''
create function test(x: optional Issue) -> bool using (
(x.name ?= x.body)
)
''')
await self.assert_query_result(
r'''
select test(<Issue>{})
''',
[True],
) | )
await self.assert_query_result(
r | test_edgeql_optional_ensure_source_02 | python | geldata/gel | tests/test_edgeql_coalesce.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_coalesce.py | Apache-2.0 |
async def test_index_01(self):
await self.migrate(r"""
type Person {
property first_name -> str;
property last_name -> str;
index on ((.first_name, .last_name));
};
type Person2 extending Person;
""")
await self.assert_query_result(
r"""
SELECT
schema::ObjectType {
indexes: {
expr
}
}
FILTER schema::ObjectType.name = 'default::Person';
""",
[{
'indexes': [{
'expr': '(.first_name, .last_name)',
}]
}],
)
await self.con.execute(r"""
INSERT Person {
first_name := 'Elon',
last_name := 'Musk'
};
""")
await self.assert_query_result(
r"""
SELECT
Person {
first_name
}
FILTER
Person.first_name = 'Elon' AND Person.last_name = 'Musk';
""",
[{
'first_name': 'Elon'
}]
)
await self.con.execute(
"""
ALTER TYPE Person
DROP INDEX ON ((.first_name, .last_name));
"""
)
await self.assert_query_result(
r"""
SELECT
schema::ObjectType {
indexes: {
expr
}
}
FILTER schema::ObjectType.name = 'default::Person';
""",
[{
'indexes': []
}],
) | )
await self.assert_query_result(
r | test_index_01 | python | geldata/gel | tests/test_indexes.py | https://github.com/geldata/gel/blob/master/tests/test_indexes.py | Apache-2.0 |
async def test_index_02(self):
await self.con.execute(r"""
# setup delta
CREATE TYPE User {
CREATE PROPERTY title -> str;
CREATE INDEX ON (.title);
};
""")
await self.assert_query_result(
r"""
SELECT
schema::ObjectType {
indexes: {
expr
}
}
FILTER .name = 'default::User';
""",
[{
'indexes': [{
'expr': '.title'
}]
}],
)
# simply test that the type can be dropped
await self.con.execute(r"""
DROP TYPE User;
""") | )
await self.assert_query_result(
r | test_index_02 | python | geldata/gel | tests/test_indexes.py | https://github.com/geldata/gel/blob/master/tests/test_indexes.py | Apache-2.0 |
async def test_index_03(self):
await self.con.execute(r"""
CREATE TYPE User {
CREATE PROPERTY name -> str;
CREATE PROPERTY title -> str;
CREATE INDEX ON (.title);
}
""")
with self.assertRaisesRegex(
edgedb.InvalidReferenceError,
r"index on \(.name\) does not exist on object type "
r"'default::User'",
):
await self.con.execute("""
ALTER TYPE User DROP INDEX ON (.name)
""") | )
with self.assertRaisesRegex(
edgedb.InvalidReferenceError,
r"index on \(.name\) does not exist on object type "
r"'default::User'",
):
await self.con.execute( | test_index_03 | python | geldata/gel | tests/test_indexes.py | https://github.com/geldata/gel/blob/master/tests/test_indexes.py | Apache-2.0 |
async def test_index_05(self):
await self.con.execute(
"""
CREATE TYPE ObjIndex1 {
CREATE PROPERTY name -> str;
};
CREATE TYPE ObjIndex2 {
CREATE MULTI PROPERTY first_name -> str;
CREATE PROPERTY last_name -> str;
CREATE LINK foo -> ObjIndex1 {
CREATE PROPERTY p -> str;
};
CREATE INDEX ON (__subject__.last_name);
};
"""
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
"cannot use SET OF operator 'std::EXISTS' "
"in an index expression",
):
await self.con.execute(
"""
ALTER TYPE ObjIndex2 {
CREATE INDEX on (EXISTS .first_name);
};
"""
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
"cannot use SET OF function 'std::count' "
"in an index expression",
):
await self.con.execute(
"""
ALTER TYPE ObjIndex2 {
CREATE PROPERTY first_name_count
:= count(.first_name);
CREATE INDEX ON (.first_name_count);
};
"""
)
await self.con.execute(
"""
ALTER TYPE ObjIndex2 {
CREATE PROPERTY last_name_len := len(.last_name);
CREATE INDEX ON (.last_name_len);
};
"""
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
"index expressions must be immutable",
):
await self.con.execute(
"""
ALTER TYPE ObjIndex2 {
CREATE INDEX ON (.foo@p);
};
"""
)
async with self.assertRaisesRegexTx(
edgedb.SchemaDefinitionError,
"index expressions must be immutable",
):
await self.con.execute(
"""
ALTER TYPE ObjIndex2 {
CREATE INDEX ON (.foo.name);
};
"""
) | CREATE TYPE ObjIndex1 {
CREATE PROPERTY name -> str;
};
CREATE TYPE ObjIndex2 {
CREATE MULTI PROPERTY first_name -> str;
CREATE PROPERTY last_name -> str;
CREATE LINK foo -> ObjIndex1 {
CREATE PROPERTY p -> str;
};
CREATE INDEX ON (__subject__.last_name);
}; | test_index_05 | python | geldata/gel | tests/test_indexes.py | https://github.com/geldata/gel/blob/master/tests/test_indexes.py | Apache-2.0 |
async def test_index_08(self):
await self.con.execute(
r"""
# setup delta
create type ObjIndex3 {
create property name -> str;
create index fts::index on (
fts::with_options(.name, language := fts::Language.eng)
);
};
"""
)
await self.assert_query_result(
r"""
select
schema::ObjectType {
indexes: {
name,
kwargs,
expr,
abstract,
}
}
filter .name = 'default::ObjIndex3';
""",
[
{
'indexes': [
{
'name': 'fts::index',
'kwargs': [],
'expr': (
'std::fts::with_options(.name, '
'language := std::fts::Language.eng)'
),
'abstract': False,
}
]
}
],
) | )
await self.assert_query_result(
r | test_index_08 | python | geldata/gel | tests/test_indexes.py | https://github.com/geldata/gel/blob/master/tests/test_indexes.py | Apache-2.0 |
async def test_index_09(self):
await self.con.execute(
r"""
# setup delta
create abstract index MyIndex extending fts::index;
create type ObjIndex4 {
create property name -> str;
create index MyIndex on (
fts::with_options(.name, language := fts::Language.eng)
);
};
"""
)
await self.assert_query_result(
r"""
select
schema::ObjectType {
indexes: {
name,
kwargs,
expr,
abstract,
}
}
filter .name = 'default::ObjIndex4';
""",
[
{
'indexes': [
{
'name': 'default::MyIndex',
'kwargs': [],
'expr': (
'std::fts::with_options(.name, '
'language := std::fts::Language.eng)'
),
'abstract': False,
}
]
}
],
)
await self.assert_query_result(
r"""
select
schema::Index {
name,
kwargs,
abstract,
ancestors[is schema::Index]: {
name,
params: {
name,
type_name := .type.name,
default,
},
abstract,
},
}
filter .name = 'default::MyIndex' and .abstract = true;
""",
[
{
'name': 'default::MyIndex',
'kwargs': [],
'abstract': True,
'ancestors': [
{
'name': 'std::fts::index',
'params': [],
'abstract': True,
}
],
}
],
) | )
await self.assert_query_result(
r | test_index_09 | python | geldata/gel | tests/test_indexes.py | https://github.com/geldata/gel/blob/master/tests/test_indexes.py | Apache-2.0 |
async def test_index_11(self):
# indexes should not be rebased, but should be dropped and recreated
await self.con.execute(
'''
create type Hello {
create required property world: str;
create index pg::btree on (.world);
};
'''
)
await self.migrate(
r"""
type Hello {
property world: str;
index pg::hash on (.world);
};
"""
)
await self.migrate(
r"""
type Hello {
property world: str;
index pg::btree on (.world);
};
"""
) | create type Hello {
create required property world: str;
create index pg::btree on (.world);
}; | test_index_11 | python | geldata/gel | tests/test_indexes.py | https://github.com/geldata/gel/blob/master/tests/test_indexes.py | Apache-2.0 |
async def test_edgeql_introspection_meta_13(self):
res = await self.con.query_single(r"""
SELECT count(schema::Object);
""")
# make sure that ALL schema Objects are std::BaseObjects
await self.assert_query_result(
r"""
SELECT schema::Object IS std::BaseObject;
""",
[True] * res
)
# ...but not std::Objects
await self.assert_query_result(
r"""
SELECT schema::Object IS NOT std::Object;
""",
[True] * res
)
# Try it in a sub scope!
await self.assert_query_result(
r"""
SELECT {schema::Object} IS std::BaseObject;
""",
[True] * res
)
# ...but not std::Objects
await self.assert_query_result(
r"""
SELECT {schema::Object} IS NOT std::Object;
""",
[True] * res
) | )
# make sure that ALL schema Objects are std::BaseObjects
await self.assert_query_result(
r | test_edgeql_introspection_meta_13 | python | geldata/gel | tests/test_edgeql_introspection.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_introspection.py | Apache-2.0 |
async def test_edgeql_introspection_meta_18(self):
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT DISTINCT (`Function` IS VolatilitySubject);
''',
[True]
)
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT DISTINCT (Cast IS VolatilitySubject);
''',
[True]
)
await self.assert_query_result(
r'''
WITH MODULE schema
SELECT DISTINCT (Operator IS VolatilitySubject);
''',
[True]
) | ,
[True]
)
await self.assert_query_result(
r | test_edgeql_introspection_meta_18 | python | geldata/gel | tests/test_edgeql_introspection.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_introspection.py | Apache-2.0 |
async def test_edgeql_introspection_count_01(self):
await self.con.execute(r"""
INSERT Priority {
name := 'High'
};
INSERT Priority {
name := 'Low'
};
INSERT Status {
name := 'Open'
};
INSERT Status {
name := 'Closed'
};
INSERT Status {
name := 'Flagged'
};
INSERT User {
name := 'Elvis'
};
INSERT User {
name := 'Yury'
};
""")
await self.assert_query_result(
r"""
# Count the number of objects for each object type in module
# test. This is impossible to do without introspection for
# object types that have 0 objects.
WITH MODULE schema
SELECT ObjectType {
name,
count := (
SELECT std::count(ObjectType.<__type__)
)
}
FILTER
.name LIKE 'default::%'
AND NOT .compound_type
ORDER BY
.name;
""",
[
{'name': 'default::BooleanTest', 'count': 0},
{'name': 'default::Comment', 'count': 0},
{'name': 'default::Dictionary', 'count': 0},
{'name': 'default::File', 'count': 0},
{'name': 'default::Issue', 'count': 0},
{'name': 'default::LogEntry', 'count': 0},
{'name': 'default::Named', 'count': 0},
{'name': 'default::Owned', 'count': 0},
{'name': 'default::Priority', 'count': 2},
{'name': 'default::Publication', 'count': 0},
{'name': 'default::Status', 'count': 3},
{'name': 'default::Text', 'count': 0},
{'name': 'default::URL', 'count': 0},
{'name': 'default::User', 'count': 2},
]
)
await self.con.execute(r"""
DELETE Priority;
DELETE Status;
DELETE User;
""") | )
await self.assert_query_result(
r | test_edgeql_introspection_count_01 | python | geldata/gel | tests/test_edgeql_introspection.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_introspection.py | Apache-2.0 |
async def test_edgeql_introspection_reverse_leaks_01(self):
res1 = await self.con.query(r"""
WITH MODULE schema
SELECT ScalarType { z := count(.<target) }
FILTER .name = 'std::str';
""")
res2 = await self.con.query_single(r"""
WITH MODULE schema
SELECT count((SELECT Property FILTER .target.name = 'std::str'));
""")
self.assertEqual(res1[0].z, res2) | )
res2 = await self.con.query_single(r | test_edgeql_introspection_reverse_leaks_01 | python | geldata/gel | tests/test_edgeql_introspection.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_introspection.py | Apache-2.0 |
async def test_edgeql_introspection_reverse_03(self):
# just some ones that crashed; can clean up later
await self.con.query(r'''
with module schema
SELECT Type.<type[IS std::Object][IS schema::TupleElement];
''')
await self.con.query(r'''
with module schema
SELECT Type.<type[IS std::Object]
''')
await self.con.query(r'''
with module schema
SELECT Type.<type[IS schema::Object]
''')
res = await self.con.query(r'''
with module schema
SELECT Type { name, z := count(.<type[IS Object]) };
''')
count1 = res[0].z
self.assertFalse(all(row.z == count1 for row in res)) | )
await self.con.query(r | test_edgeql_introspection_reverse_03 | python | geldata/gel | tests/test_edgeql_introspection.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_introspection.py | Apache-2.0 |
async def test_edgeql_introspection_cfg_objects_01(self):
await self.assert_query_result(
r'''
SELECT count(sys::Branch)
= count(BaseObject[is sys::Branch])
''',
[True],
)
await self.assert_query_result(
r'''
SELECT count(cfg::AbstractConfig)
= count(BaseObject[is cfg::AbstractConfig])
''',
[True],
)
await self.assert_query_result(
r'''
SELECT count(cfg::ConfigObject)
= count(BaseObject[is cfg::ConfigObject])
''',
[True],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_introspection_cfg_objects_01 | python | geldata/gel | tests/test_edgeql_introspection.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_introspection.py | Apache-2.0 |
async def test_edgeql_introspection_cfg_objects_02(self):
await self.assert_query_result(
r'''
SELECT count(sys::Branch)
= count(sys::SystemObject[is sys::Branch])
''',
[True],
)
await self.assert_query_result(
r'''
SELECT count(cfg::AbstractConfig)
= count(cfg::ConfigObject[is cfg::AbstractConfig])
''',
[True],
) | ,
[True],
)
await self.assert_query_result(
r | test_edgeql_introspection_cfg_objects_02 | python | geldata/gel | tests/test_edgeql_introspection.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_introspection.py | Apache-2.0 |
async def test_edgeql_functions_inline_global_02(self):
await self.con.execute('''
create global a -> int64;
create function foo() -> optional int64 {
set is_inlined := true;
using (global a);
};
''')
await self.assert_query_result(
'select foo()',
[],
)
await self.con.execute('''
set global a := 1;
''')
await self.assert_query_result(
'select foo()',
[1],
) | )
await self.assert_query_result(
'select foo()',
[],
)
await self.con.execute( | test_edgeql_functions_inline_global_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_global_04(self):
await self.con.execute('''
create global a -> int64;
create function foo(x: int64) -> optional int64 {
set is_inlined := true;
using (global a + x)
};
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute('''
set global a := 1;
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[2],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[2, 3, 4],
sort=True,
) | )
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute( | test_edgeql_functions_inline_global_04 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_nested_global_02(self):
# Use non-computed global in inner function
await self.con.execute('''
create global a -> int64;
create function inner(x: int64) -> optional int64 {
set is_inlined := true;
using (global a + x);
};
create function foo(x: int64) -> optional int64 {
set is_inlined := true;
using (inner(x));
};
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute('''
set global a := 1;
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[2],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[2, 3, 4],
sort=True,
) | )
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute( | test_edgeql_functions_inline_nested_global_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_nested_global_04(self):
# Pass non-computed global to inner function
await self.con.execute('''
create global a -> int64;
create function inner(x: int64, y: int64) -> optional int64 {
set is_inlined := true;
using (x + y);
};
create function foo(x: int64) -> optional int64 {
set is_inlined := true;
using (inner(global a, x));
};
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute('''
set global a := 1;
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[2],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[2, 3, 4],
sort=True,
) | )
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute( | test_edgeql_functions_inline_nested_global_04 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_nested_global_06(self):
# Use non-computed global in inner non-inlined function
# - inlined > non-inlined
await self.con.execute('''
create global a -> int64;
create function inner(x: int64) -> optional int64 {
using (global a + x);
};
create function foo(x: int64) -> optional int64 {
set is_inlined := true;
using (inner(x));
};
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute('''
set global a := 1;
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[2],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[2, 3, 4],
sort=True,
) | )
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute( | test_edgeql_functions_inline_nested_global_06 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_nested_global_08(self):
# Use non-computed global nested in non-inlined function
# - non-inlined > inlined > non-inlined
await self.con.execute('''
create global a -> int64;
create function inner1(x: int64) -> optional int64 {
using (global a + x);
};
create function inner2(x: int64) -> optional int64 {
set is_inlined := true;
using (inner1(x));
};
create function foo(x: int64) -> optional int64 {
using (inner2(x));
};
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute('''
set global a := 1;
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[2],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[2, 3, 4],
sort=True,
) | )
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute( | test_edgeql_functions_inline_nested_global_08 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_nested_global_10(self):
# Use computed global in deeply nested inner non-inlined function
# - inlined > inlined > inlined > non-inlined
await self.con.execute('''
create global a -> int64;
create function inner1(x: int64) -> optional int64 {
using (global a + x);
};
create function inner2(x: int64) -> optional int64 {
set is_inlined := true;
using (inner1(x));
};
create function inner3(x: int64) -> optional int64 {
set is_inlined := true;
using (inner2(x));
};
create function foo(x: int64) -> optional int64 {
set is_inlined := true;
using (inner3(x));
};
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute('''
set global a := 1;
''')
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[2],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[2, 3, 4],
sort=True,
) | )
await self.assert_query_result(
'select foo(<int64>{})',
[],
)
await self.assert_query_result(
'select foo(1)',
[],
)
await self.assert_query_result(
'select foo({1, 2, 3})',
[],
sort=True,
)
await self.con.execute( | test_edgeql_functions_inline_nested_global_10 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_modifying_cardinality_02(self):
await self.con.execute('''
create function foo(x: int64) -> int64 {
set volatility := schema::Volatility.Modifying;
using (x)
};
''')
with self.assertRaisesRegex(
edgedb.QueryError,
'possibly an empty set passed as non-optional argument '
'into modifying function'
):
await self.con.execute('''
select foo(<int64>{})
''') | )
with self.assertRaisesRegex(
edgedb.QueryError,
'possibly an empty set passed as non-optional argument '
'into modifying function'
):
await self.con.execute( | test_edgeql_functions_inline_modifying_cardinality_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_modifying_cardinality_03(self):
await self.con.execute('''
create function foo(x: int64) -> int64 {
set volatility := schema::Volatility.Modifying;
using (x)
};
''')
with self.assertRaisesRegex(
edgedb.QueryError,
'possibly more than one element passed into modifying function'
):
await self.con.execute('''
select foo({1, 2, 3})
''') | )
with self.assertRaisesRegex(
edgedb.QueryError,
'possibly more than one element passed into modifying function'
):
await self.con.execute( | test_edgeql_functions_inline_modifying_cardinality_03 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_modifying_cardinality_06(self):
await self.con.execute('''
create function foo(x: optional int64) -> optional int64 {
set volatility := schema::Volatility.Modifying;
using (x)
};
''')
with self.assertRaisesRegex(
edgedb.QueryError,
'possibly more than one element passed into modifying function'
):
await self.con.execute('''
select foo({1, 2, 3})
''') | )
with self.assertRaisesRegex(
edgedb.QueryError,
'possibly more than one element passed into modifying function'
):
await self.con.execute( | test_edgeql_functions_inline_modifying_cardinality_06 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_basic_01(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64) -> set of Bar {
set is_inlined := true;
using ((update Bar set { a := x }));
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(1).a',
[1, 1, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 1, 1],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_basic_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_basic_02(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64, y: int64) -> set of int64 {
set is_inlined := true;
using ((update Bar filter .a <= y set { a := x }).a);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(0, 0)',
[],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 1)',
[0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 2)',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 3)',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_basic_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_basic_03(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(
named only m: int64,
named only n: int64,
) -> set of int64 {
set is_inlined := true;
using ((update Bar filter .a <= n set { a := m }).a);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(m := 0, n := 0)',
[],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(m := 0, n := 1)',
[0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(m := 0, n := 2)',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(m := 0, n := 3)',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_basic_03 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_basic_04(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(
x: optional int64,
y: optional int64,
) -> set of int64 {
set is_inlined := true;
using ((update Bar filter .a <= y ?? 9 set { a := x ?? 9 }).a);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(<int64>{}, <int64>{})',
[9, 9, 9],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[9, 9, 9],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(<int64>{}, 2)',
[9, 9],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3, 9, 9],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2, <int64>{})',
[2, 2, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[2, 2, 2],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 0)',
[],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 1)',
[0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 2)',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 3)',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_basic_04 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_basic_05(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(
x: int64,
variadic y: int64,
) -> set of int64 {
set is_inlined := true;
using (
(
update Bar
filter .a <= sum(array_unpack(y))
set { a := x }
).a
);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(0)',
[],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 1)',
[0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 1, 2)',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_basic_05 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_basic_06(self):
# Check dml function in with clause has effect
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64, y: int64) -> set of Bar {
set is_inlined := true;
using ((update Bar filter .a <= y set { a := x }));
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
insert Bar{a := 4};
insert Bar{a := 5};
''')
await reset_data()
await self.assert_query_result(
'with temp := foo(0, 2)'
'select temp.a',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (for x in {1, 2, 3} union (select foo(x-1, x)))'
'select temp.a',
[0, 1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 2, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if true then foo(0, 2) else <Bar>{})'
'select temp.a',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if false then foo(0, 2) else <Bar>{})'
'select temp.a',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if true then <Bar>{} else foo(0, 2))'
'select temp.a',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if false then <Bar>{} else foo(0, 2))'
'select temp.a',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3, 4, 5],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_basic_06 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_basic_07(self):
# Check dml function in with clause has effect but is not used
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64, y: int64) -> set of Bar {
set is_inlined := true;
using ((update Bar filter .a <= y set { a := x }));
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
insert Bar{a := 4};
insert Bar{a := 5};
''')
await reset_data()
await self.assert_query_result(
'with temp := foo(0, 2)'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (for x in {1, 2, 3} union (select foo(x-1, x)))'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 2, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if true then foo(0, 2) else <Bar>{})'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if false then foo(0, 2) else <Bar>{})'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if true then <Bar>{} else foo(0, 2))'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if false then <Bar>{} else foo(0, 2))'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3, 4, 5],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_basic_07 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_iterator_01(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64, y: int64) -> set of int64 {
set is_inlined := true;
using ((update Bar filter .a <= y set { a := x }).a);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(0, 0)',
[],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 1)',
[0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 2)',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 3)',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {0, 1} union (select foo(0, x))',
[0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(0, x))',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(x - 1, 0))',
[],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(x - 1, 3))',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1} union (select foo(x - 1, x))',
[0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {2, 3} union (select foo(x - 1, x))',
[1, 1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 1, 2],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(x - 1, x))',
[0, 1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 2],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then foo(0, 2) else 99',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if false then foo(0, 2) else 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then 99 else foo(0, 2)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if false then 99 else foo(0, 2)',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 0) ?? 99',
[99],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 2) ?? 99',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo(0, 2)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_iterator_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_iterator_02(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64, y: int64) -> set of int64 {
set is_inlined := true;
using (
for z in {0, 1} union (
(update Bar filter .a <= y + z set { a := x + z }).a
)
);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(0, 0)',
[1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 1)',
[0, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 2)',
[0, 0, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 1],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 3)',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {0, 1} union (select foo(0, x))',
[1, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 1, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(0, x))',
[0, 1, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 1],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(x - 1, 0))',
[1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(x - 1, 3))',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1} union (select foo(x - 1, x))',
[0, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {2, 3} union (select foo(x - 1, x))',
[1, 1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 1, 2],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(x - 1, x))',
[0, 1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 2],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then foo(0, 1) else 99',
[0, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if false then foo(0, 1) else 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then 99 else foo(0, 1)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if false then 99 else foo(0, 1)',
[0, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, -1) ?? 99',
[99],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 1) ?? 99',
[0, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo(0, 1)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_iterator_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_iterator_03(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(
x: int64, y: int64, z: bool
) -> set of int64 {
set is_inlined := true;
using (
if z
then (update Bar filter .a <= y set { a := x }).a
else <int64>{}
);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(0, 2, false)',
[],
)
await self.assert_query_result(
'select foo(0, 3, false)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 2, true)',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 3, true)',
[0, 0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 0],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {0, 1} union (select foo(0, x, false))',
[],
sort=True,
)
await self.assert_query_result(
'for x in {2, 3} union (select foo(x - 1, x, false))',
[],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {0, 1} union (select foo(0, x, true))',
[0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {2, 3} union (select foo(x - 1, x, true))',
[1, 1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 1, 2],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then foo(0, 2, false) else 99',
[],
sort=True,
)
await self.assert_query_result(
'select if false then foo(0, 2, false) else 99',
[99],
)
await self.assert_query_result(
'select if true then 99 else foo(0, 2, false)',
[99],
)
await self.assert_query_result(
'select if false then 99 else foo(0, 2, false)',
[],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then foo(0, 2, true) else 99',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if false then foo(0, 2, true) else 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then 99 else foo(0, 2, true)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if false then 99 else foo(0, 2, true)',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 0, false) ?? 99',
[99],
sort=True,
)
await self.assert_query_result(
'select foo(0, 2, false) ?? 99',
[99],
sort=True,
)
await self.assert_query_result(
'select 99 ?? foo(0, 2, false)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 0, true) ?? 99',
[99],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 2, true) ?? 99',
[0, 0],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[0, 0, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo(0, 2, true)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_iterator_03 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_link_01(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create link bar -> Bar;
};
create function foo(n: int64, x: Bar) -> set of Baz {
set is_inlined := true;
using ((update Baz filter .b <= n set { bar := x }))
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
insert Baz{b := 4};
insert Baz{b := 5};
insert Baz{b := 6};
''')
await reset_data()
await self.assert_query_result(
'select foo('
' 4,'
' assert_exists((select Bar filter .a = 1 limit 1))'
'){a := .bar.a, b}',
[
{'a': 1, 'b': 4},
],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 1, 'b': 4},
{'a': None, 'b': 5},
{'a': None, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo('
' 5,'
' assert_exists((select Bar filter .a = 1 limit 1))'
'){a := .bar.a, b}',
[
{'a': 1, 'b': 4},
{'a': 1, 'b': 5},
],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 1, 'b': 4},
{'a': 1, 'b': 5},
{'a': None, 'b': 6},
],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_link_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_link_02(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create multi link bar -> Bar;
};
create function foo(x: int64, y: int64) -> set of Baz {
set is_inlined := true;
using (
(update Baz filter .b <= x set {
bar := (select Bar filter .a <= y),
})
);
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
insert Baz{b := 4};
insert Baz{b := 5};
insert Baz{b := 6};
''')
await reset_data()
await self.assert_query_result(
'select foo(4, 1){a := .bar.a, b}',
[
{'a': [1], 'b': 4},
],
)
await self.assert_query_result(
'select Baz {'
' a := (select .bar order by .a).a,'
' b,'
'} order by .b',
[
{'a': [1], 'b': 4},
{'a': [], 'b': 5},
{'a': [], 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(5, 2){a := .bar.a, b}',
[
{'a': [1, 2], 'b': 4},
{'a': [1, 2], 'b': 5},
],
)
await self.assert_query_result(
'select Baz {'
' a := (select .bar order by .a).a,'
' b,'
'} order by .b',
[
{'a': [1, 2], 'b': 4},
{'a': [1, 2], 'b': 5},
{'a': [], 'b': 6},
],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_link_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_link_03(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create optional link bar -> Bar;
};
create function foo(x: int64, y: int64) -> set of Baz {
set is_inlined := true;
using (
(update Baz filter .b <= x set {
bar := (insert Bar{a := y}),
})
);
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Baz{b := 4};
insert Baz{b := 5};
insert Baz{b := 6};
''')
await reset_data()
await self.assert_query_result(
'select foo(4, 1){a := .bar.a, b}',
[
{'a': 1, 'b': 4},
],
)
await self.assert_query_result(
'select Bar.a',
[1],
)
await self.assert_query_result(
'select Baz {'
' a := (select .bar order by .a).a,'
' b,'
'} order by .b',
[
{'a': 1, 'b': 4},
{'a': None, 'b': 5},
{'a': None, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(5, 2){a := .bar.a, b}',
[
{'a': 2, 'b': 4},
{'a': 2, 'b': 5},
],
)
await self.assert_query_result(
'select Bar.a',
[2, 2],
)
await self.assert_query_result(
'select Baz {'
' a := (select .bar order by .a).a,'
' b,'
'} order by .b',
[
{'a': 2, 'b': 4},
{'a': 2, 'b': 5},
{'a': None, 'b': 6},
],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_link_03 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_link_iterator_01(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create link bar -> Bar;
};
create function foo(n: int64, x: Bar) -> set of Baz {
set is_inlined := true;
using ((update Baz filter .b = n set { bar := x }))
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
insert Bar{a := 4};
insert Baz{b := 10};
insert Baz{b := 20};
insert Baz{b := 30};
''')
await reset_data()
await self.assert_query_result(
'select foo('
' 10,'
' assert_exists((select Bar filter .a = 1 limit 1))'
'){a := .bar.a, b}',
[
{'a': 1, 'b': 10},
],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 1, 'b': 10},
{'a': None, 'b': 20},
{'a': None, 'b': 30},
],
)
await reset_data()
await self.assert_query_result(
'select ('
' for x in {1, 2} union('
' select foo('
' x * 10,'
' assert_exists((select Bar filter .a = x limit 1))'
' ).b'
' )'
')',
[10, 20],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 1, 'b': 10},
{'a': 2, 'b': 20},
{'a': None, 'b': 30},
],
)
await reset_data()
await self.assert_query_result(
'select ('
' if true'
' then foo('
' 10,'
' assert_exists((select Bar filter .a = 1 limit 1)),'
' ).b'
' else 99'
')',
[10],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 1, 'b': 10},
{'a': None, 'b': 20},
{'a': None, 'b': 30},
],
)
await reset_data()
await self.assert_query_result(
'select ('
' if false'
' then foo('
' 10,'
' assert_exists((select Bar filter .a = 1 limit 1)),'
' ).b'
' else 99'
')',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 10},
{'a': None, 'b': 20},
{'a': None, 'b': 30},
],
)
await reset_data()
await self.assert_query_result(
'select ('
' if true'
' then 99'
' else foo('
' 10,'
' assert_exists((select Bar filter .a = 1 limit 1)),'
' ).b'
')',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 10},
{'a': None, 'b': 20},
{'a': None, 'b': 30},
],
)
await reset_data()
await self.assert_query_result(
'select ('
' if false'
' then 99'
' else foo('
' 10,'
' assert_exists((select Bar filter .a = 1 limit 1)),'
' ).b'
')',
[10],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 1, 'b': 10},
{'a': None, 'b': 20},
{'a': None, 'b': 30},
],
)
await reset_data()
await self.assert_query_result(
'select foo('
' 10,'
' assert_exists((select Bar filter .a = 1 limit 1)),'
').b ?? 99',
[10],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 1, 'b': 10},
{'a': None, 'b': 20},
{'a': None, 'b': 30},
],
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo('
' 10,'
' assert_exists((select Bar filter .a = 1 limit 1)),'
').b',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 10},
{'a': None, 'b': 20},
{'a': None, 'b': 30},
],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_link_iterator_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_link_iterator_02(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create multi link bar -> Bar;
};
create function foo(x: int64, y: int64) -> set of Baz {
set is_inlined := true;
using ((
update Baz filter .b = x set {
bar := (for z in {y, y + 1, y + 2} union (
insert Bar{a := z}
)
)
}
))
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Baz{b := 1};
insert Baz{b := 2};
insert Baz{b := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(1, 10){a := .bar.a, b}',
[
{'a': [10, 11, 12], 'b': 1},
],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': [10, 11, 12], 'b': 1},
{'a': [], 'b': 2},
{'a': [], 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2} union (select foo(x, x * 10){a := .bar.a, b})',
[
{'a': [10, 11, 12], 'b': 1},
{'a': [20, 21, 22], 'b': 2},
],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': [10, 11, 12], 'b': 1},
{'a': [20, 21, 22], 'b': 2},
{'a': [], 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if true then foo(1, 10).b else 99',
[1],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': [10, 11, 12], 'b': 1},
{'a': [], 'b': 2},
{'a': [], 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if false then foo(1, 10).b else 99',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': [], 'b': 1},
{'a': [], 'b': 2},
{'a': [], 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if true then 99 else foo(1, 10).b',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': [], 'b': 1},
{'a': [], 'b': 2},
{'a': [], 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if false then 99 else foo(1, 10).b',
[1],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': [10, 11, 12], 'b': 1},
{'a': [], 'b': 2},
{'a': [], 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select foo(1, 10).b ?? 99',
[1],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': [10, 11, 12], 'b': 1},
{'a': [], 'b': 2},
{'a': [], 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo(1, 10).b',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': [], 'b': 1},
{'a': [], 'b': 2},
{'a': [], 'b': 3},
],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_link_iterator_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_link_iterator_03(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create link bar -> Bar;
};
create function foo(x: int64, y: int64, flag: bool) -> set of Baz {
set is_inlined := true;
using ((
update Baz filter .b = x set {
bar := (
if flag
then (insert Bar{a := y})
else <Bar>{}
)
}
))
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Baz{b := 1};
insert Baz{b := 2};
insert Baz{b := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(1, 10, false){a := .bar.a, b}',
[
{'a': None, 'b': 1},
],
)
await self.assert_query_result(
'select Bar.a',
[],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select foo(1, 10, true){a := .bar.a, b}',
[
{'a': 10, 'b': 1},
],
)
await self.assert_query_result(
'select Bar.a',
[10],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 10, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2} union ('
' select foo(x, x * 10, false){a := .bar.a, b}'
')',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2} union ('
' select foo(x, x * 10, true){a := .bar.a, b}'
')',
[
{'a': 10, 'b': 1},
{'a': 20, 'b': 2},
],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 10, 'b': 1},
{'a': 20, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if true then foo(1, 10, false).bar.a else 99',
[],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if false then foo(1, 10, false).bar.a else 99',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if true then 99 else foo(1, 10, false).bar.a',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if false then 99 else foo(1, 10, false).bar.a',
[],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if true then foo(1, 10, true).bar.a else 99',
[10],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 10, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if false then foo(1, 10, true).bar.a else 99',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if true then 99 else foo(1, 10, true).bar.a',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select if false then 99 else foo(1, 10, true).bar.a',
[10],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 10, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select foo(1, 10, false).bar.a ?? 99',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo(1, 10, false).bar.a',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select foo(1, 10, true).bar.a ?? 99',
[10],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 10, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo(1, 10, true).bar.a',
[99],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 1},
{'a': None, 'b': 2},
{'a': None, 'b': 3},
],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_link_iterator_03 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_linkprop_01(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required link bar -> Bar {
create property b -> int64;
}
};
create function foo(x: int64, y: int64) -> set of Baz {
set is_inlined := true;
using ((
update Baz filter .bar.a <= x set {
bar := .bar { @b := y }
}
))
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Baz{bar := (insert Bar{a := 1})};
insert Baz{bar := (insert Bar{a := 2})};
insert Baz{bar := (insert Bar{a := 3})};
''')
await reset_data()
await self.assert_query_result(
'select foo(2, 4){a := .bar.a, b := .bar@b}',
[
{'a': 1, 'b': 4},
{'a': 2, 'b': 4},
],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b := .bar@b} order by .a',
[
{'a': 1, 'b': 4},
{'a': 2, 'b': 4},
{'a': 3, 'b': None},
],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_linkprop_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_nested_01(self):
# Simple inner modifying function
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function inner(x: int64) -> set of Bar {
set is_inlined := true;
using ((update Bar set { a := x }));
};
create function foo(x: int64) -> set of Bar {
set is_inlined := true;
using (inner(x));
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(1).a',
[1, 1, 1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 1, 1],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_nested_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_update_nested_02(self):
# Putting the result of an inner modifying function into shape
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create multi link bar -> Bar;
};
create function inner1(y: int64) -> set of Bar {
set is_inlined := true;
using ((update Bar filter .a <= y set { a := .a - 1 }));
};
create function inner2(x: int64, y: int64) -> set of Baz {
set is_inlined := true;
using (
(update Baz filter .b <= x set {
bar := assert_distinct(inner1(y)),
})
);
};
create function foo(x: int64, y: int64) -> set of Baz {
set is_inlined := true;
using (inner2(x, y));
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
insert Baz{b := 4};
insert Baz{b := 5};
insert Baz{b := 6};
''')
await reset_data()
await self.assert_query_result(
'select foo(4, 1){a := .bar.a, b}',
[
{'a': [0], 'b': 4},
],
)
await self.assert_query_result(
'select Bar.a',
[0, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Baz {'
' a := (select .bar order by .a).a,'
' b,'
'} order by .b',
[
{'a': [0], 'b': 4},
{'a': [], 'b': 5},
{'a': [], 'b': 6},
],
)
# Inner update will return an empty set for all subsequent calls.
await reset_data()
await self.assert_query_result(
'select foo(5, 2){a := .bar.a, b}',
[
{'a': [0, 1], 'b': 4},
{'a': [], 'b': 5},
],
)
await self.assert_query_result(
'select Bar.a',
[0, 1, 3],
sort=True,
)
await self.assert_query_result(
'select Baz {'
' a := (select .bar order by .a).a,'
' b,'
'} order by .b',
[
{'a': [0, 1], 'b': 4},
{'a': [], 'b': 5},
{'a': [], 'b': 6},
],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_update_nested_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_basic_01(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64) -> set of Bar {
set is_inlined := true;
using ((delete Bar filter .a <= x));
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(1).a',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2).a',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_basic_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_basic_02(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64) -> set of int64 {
set is_inlined := true;
using ((delete Bar filter .a <= x).a);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(0)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(1)',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select foo(3)',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_basic_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_basic_03(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(named only m: int64) -> set of int64 {
set is_inlined := true;
using ((delete Bar filter .a <= m).a);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(m := 0)',
[],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(m := 1)',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(m := 2)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select foo(m := 3)',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_basic_03 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_basic_04(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: optional int64) -> set of int64 {
set is_inlined := true;
using ((delete Bar filter .a <= x ?? 9).a);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(<int64>{})',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
)
await reset_data()
await self.assert_query_result(
'select foo(0)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(1)',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select foo(3)',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_basic_04 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_basic_05(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(
variadic x: int64,
) -> set of int64 {
set is_inlined := true;
using (
(
delete Bar
filter .a <= sum(array_unpack(x))
).a
);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(0)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 1)',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, 1, 2)',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_basic_05 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_basic_06(self):
# Check dml function in with clause has effect
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64) -> set of Bar {
set is_inlined := true;
using ((delete Bar filter .a <= x));
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
insert Bar{a := 4};
insert Bar{a := 5};
''')
await reset_data()
await self.assert_query_result(
'with temp := foo(2)'
'select temp.a',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (for x in {1, 2, 3} union (select foo(x)))'
'select temp.a',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if true then foo(2) else <Bar>{})'
'select temp.a',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if false then foo(2) else <Bar>{})'
'select temp.a',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if true then <Bar>{} else foo(2))'
'select temp.a',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if false then <Bar>{} else foo(2))'
'select temp.a',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3, 4, 5],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_basic_06 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_basic_07(self):
# Check dml function in with clause has effect but is not used
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64) -> set of Bar {
set is_inlined := true;
using ((delete Bar filter .a <= x));
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
insert Bar{a := 4};
insert Bar{a := 5};
''')
await reset_data()
await self.assert_query_result(
'with temp := foo(2)'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (for x in {1, 2, 3} union (select foo(x)))'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if true then foo(2) else <Bar>{})'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if false then foo(2) else <Bar>{})'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if true then <Bar>{} else foo(2))'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3, 4, 5],
sort=True,
)
await reset_data()
await self.assert_query_result(
'with temp := (if false then <Bar>{} else foo(2))'
'select 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[3, 4, 5],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_basic_07 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_iterator_01(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64) -> set of int64 {
set is_inlined := true;
using ((delete Bar filter .a <= x).a);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(0)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(1)',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select foo(3)',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
)
await reset_data()
await self.assert_query_result(
'for x in {0, 1} union (select foo(x))',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(x))',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
)
await reset_data()
await self.assert_query_result(
'select if true then foo(2) else 99',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select if false then foo(2) else 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then 99 else foo(2)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if false then 99 else foo(2)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select foo(0) ?? 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2) ?? 99',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo(2)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_iterator_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_iterator_02(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(x: int64) -> set of int64 {
set is_inlined := true;
using (
for z in {0, 1} union (
(delete Bar filter .a <= x).a
)
);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(0)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(1)',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select foo(3)',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
)
await reset_data()
await self.assert_query_result(
'for x in {0, 1} union (select foo(x))',
[1],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
)
await reset_data()
await self.assert_query_result(
'for x in {1, 2, 3} union (select foo(x))',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
)
await reset_data()
await self.assert_query_result(
'select if true then foo(2) else 99',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select if false then foo(2) else 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then 99 else foo(2)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if false then 99 else foo(2)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select foo(0) ?? 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2) ?? 99',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo(2)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_iterator_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_iterator_03(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create function foo(
x: int64, y: bool
) -> set of int64 {
set is_inlined := true;
using (
if y
then (delete Bar filter .a <= x).a
else <int64>{}
);
};
''')
async def reset_data():
await self.con.execute('''
delete Bar;
insert Bar{a := 1};
insert Bar{a := 2};
insert Bar{a := 3};
''')
await reset_data()
await self.assert_query_result(
'select foo(2, false)',
[],
)
await self.assert_query_result(
'select foo(3, false)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2, true)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select foo(3, true)',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
)
await reset_data()
await self.assert_query_result(
'for x in {0, 1} union (select foo(x, false))',
[],
)
await self.assert_query_result(
'for x in {2, 3} union (select foo(x, false))',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {0, 1} union (select foo(x, true))',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'for x in {2, 3} union (select foo(x, true))',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
)
await reset_data()
await self.assert_query_result(
'select if true then foo(2, false) else 99',
[],
)
await self.assert_query_result(
'select if false then foo(2, false) else 99',
[99],
)
await self.assert_query_result(
'select if true then 99 else foo(2, false)',
[99],
)
await self.assert_query_result(
'select if false then 99 else foo(2, false)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then foo(2, true) else 99',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await reset_data()
await self.assert_query_result(
'select if false then foo(2, true) else 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if true then 99 else foo(2, true)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select if false then 99 else foo(2, true)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, false) ?? 99',
[99],
)
await self.assert_query_result(
'select foo(2, false) ?? 99',
[99],
)
await self.assert_query_result(
'select 99 ?? foo(2, false)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(0, true) ?? 99',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select foo(2, true) ?? 99',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
sort=True,
)
await reset_data()
await self.assert_query_result(
'select 99 ?? foo(2, true)',
[99],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_iterator_03 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_policy_target_01(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create link bar -> Bar {
on target delete allow;
};
};
create function foo(x: int64) -> set of int64 {
set is_inlined := true;
using (
(delete Bar filter .a <= x).a
);
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Baz{b := 4, bar := (insert Bar{a := 1})};
insert Baz{b := 5, bar := (insert Bar{a := 2})};
insert Baz{b := 6, bar := (insert Bar{a := 3})};
''')
await reset_data()
await self.assert_query_result(
'select foo(0)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 1, 'b': 4},
{'a': 2, 'b': 5},
{'a': 3, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(1)',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 4},
{'a': 2, 'b': 5},
{'a': 3, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(2)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 4},
{'a': None, 'b': 5},
{'a': 3, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(3)',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': None, 'b': 4},
{'a': None, 'b': 5},
{'a': None, 'b': 6},
],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_policy_target_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_policy_target_02(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create link bar -> Bar {
on target delete delete source;
};
};
create function foo(x: int64) -> set of int64 {
set is_inlined := true;
using (
(delete Bar filter .a <= x).a
);
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Baz{b := 4, bar := (insert Bar{a := 1})};
insert Baz{b := 5, bar := (insert Bar{a := 2})};
insert Baz{b := 6, bar := (insert Bar{a := 3})};
''')
await reset_data()
await self.assert_query_result(
'select foo(0)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b}',
[
{'a': 1, 'b': 4},
{'a': 2, 'b': 5},
{'a': 3, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(1)',
[1],
)
await self.assert_query_result(
'select Bar.a',
[2, 3],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b}',
[
{'a': 2, 'b': 5},
{'a': 3, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(2)',
[1, 2],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[3],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b}',
[
{'a': 3, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(3)',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[],
)
await self.assert_query_result(
'select Baz{a := .bar.a, b}',
[],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_policy_target_02 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
async def test_edgeql_functions_inline_delete_policy_source_01(self):
await self.con.execute('''
create type Bar {
create required property a -> int64;
};
create type Baz {
create required property b -> int64;
create link bar -> Bar {
on source delete allow;
};
};
create function foo(x: int64) -> set of int64 {
set is_inlined := true;
using (
(delete Baz filter .b <= x).b
);
};
''')
async def reset_data():
await self.con.execute('''
delete Baz;
delete Bar;
insert Baz{b := 4, bar := (insert Bar{a := 1})};
insert Baz{b := 5, bar := (insert Bar{a := 2})};
insert Baz{b := 6, bar := (insert Bar{a := 3})};
''')
await reset_data()
await self.assert_query_result(
'select foo(0)',
[],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 1, 'b': 4},
{'a': 2, 'b': 5},
{'a': 3, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(4)',
[4],
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 2, 'b': 5},
{'a': 3, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(5)',
[4, 5],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[
{'a': 3, 'b': 6},
],
)
await reset_data()
await self.assert_query_result(
'select foo(6)',
[4, 5, 6],
sort=True,
)
await self.assert_query_result(
'select Bar.a',
[1, 2, 3],
sort=True,
)
await self.assert_query_result(
'select Baz{a := .bar.a, b} order by .b',
[],
) | )
async def reset_data():
await self.con.execute( | test_edgeql_functions_inline_delete_policy_source_01 | python | geldata/gel | tests/test_edgeql_functions_inline.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_functions_inline.py | Apache-2.0 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.