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_insert_update_cross_type_conflict_06(self):
# this isn't really an insert test
await self.con.execute('''
INSERT Person { name := 'Foo' };
INSERT DerivedPerson { name := 'Bar' };
''')
query = r'''
UPDATE Person FILTER true SET { multi_prop := "!" };
'''
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
"multi_prop violates exclusivity constraint"):
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_06 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_07a(self):
await self.con.execute('''
INSERT Person2a { first := 'foo', last := 'bar' };
''')
query = r'''
WITH
F := (INSERT DerivedPerson2a {first := 'foo', last := 'baz'}),
B := (UPDATE Person2a FILTER .first = 'foo' and .last = 'bar'
SET {last := 'baz'}),
SELECT (B, F);
'''
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
"Person2a violates exclusivity constraint"):
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_07a | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_07b(self):
# this should be fine, though
await self.con.execute('''
INSERT Person2a { first := 'foo', last := 'bar' };
INSERT DerivedPerson2a { first := 'spam', last := 'eggs' };
''')
query = r'''
UPDATE Person2a SET { first := "!" };
'''
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_07b | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_08a(self):
await self.con.execute('''
INSERT Person2b { first := 'foo', last := 'bar' };
''')
query = r'''
WITH
F := (INSERT DerivedPerson2b {first := 'foo', last := 'baz'}),
B := (UPDATE Person2b FILTER .first = 'foo' and .last = 'bar'
SET {last := 'baz'}),
SELECT (B, F);
'''
with self.assertRaisesRegex(edgedb.ConstraintViolationError,
"name violates exclusivity constraint"):
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_08a | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_08b(self):
# this should be fine, though
await self.con.execute('''
INSERT Person2b { first := 'foo', last := 'bar' };
INSERT DerivedPerson2b { first := 'spam', last := 'eggs' };
''')
query = r'''
UPDATE Person2b SET { first := "!" };
'''
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_08b | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_09a(self):
# a constraint that is just on the children
await self.con.execute('''
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE TYPE Bar EXTENDING Foo {
ALTER PROPERTY name {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Baz EXTENDING Bar;
INSERT Bar { name := "bar" };
INSERT Baz { name := "baz" };
''')
query = r'''
UPDATE Foo FILTER true SET { name := "!" };
'''
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
"name violates exclusivity constraint"):
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_09a | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_09b(self):
await self.con.execute('''
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE TYPE Bar EXTENDING Foo {
ALTER PROPERTY name {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Baz EXTENDING Bar;
INSERT Bar { name := "bar" };
# INSERT Baz { name := "baz" };
''')
query = r'''
WITH name := '!',
B := (UPDATE Foo FILTER .name = 'bar' SET {name := name}),
F := (INSERT Bar {name := name}),
SELECT (B, F);
'''
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
"name violates exclusivity constraint"):
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_09b | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_09c(self):
await self.con.execute('''
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE TYPE Bar EXTENDING Foo {
ALTER PROPERTY name {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Baz EXTENDING Bar;
INSERT Bar { name := "bar" };
INSERT Baz { name := "baz" };
''')
query = r'''
WITH name := '!',
B := (UPDATE Foo FILTER .name = 'bar' SET {name := name}),
Z := (UPDATE Foo FILTER .name = 'baz' SET {name := name}),
SELECT (B, Z);
'''
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
"name violates exclusivity constraint"):
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_09c | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_10(self):
# a constraint that is just on the children
await self.con.execute('''
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY name -> str;
CREATE MULTI PROPERTY tags -> str;
};
CREATE TYPE Bar EXTENDING Foo {
ALTER PROPERTY tags {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Baz EXTENDING Bar;
INSERT Bar { name := "bar" };
INSERT Baz { name := "baz" };
''')
query = r'''
UPDATE Foo FILTER true SET { tags := "!" };
'''
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
"tags violates exclusivity constraint"):
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_10 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_11(self):
# a constraint that is on an unrelated type
await self.con.execute('''
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY name -> str;
};
CREATE TYPE Bar {
CREATE PROPERTY name -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Baz EXTENDING Foo, Bar;
INSERT Baz { name := "baz" };
''')
query = r'''
WITH name := '!',
F := (INSERT Bar {name := name}),
B := (UPDATE Foo FILTER .name = 'baz' SET {name := name}),
SELECT (B, F);
'''
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
"name violates exclusivity constraint"):
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_11 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_12(self):
# a constraint that is just on the children, using data only
# in the children
await self.con.execute('''
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY name -> str;
CREATE REQUIRED PROPERTY x -> int64;
};
CREATE TYPE Bar EXTENDING Foo {
CREATE REQUIRED PROPERTY y -> int64;
CREATE CONSTRAINT exclusive on
((__subject__.x + __subject__.y));
};
CREATE TYPE Baz EXTENDING Bar;
INSERT Bar { name := "bar", x := 1, y := 1 };
INSERT Baz { name := "baz", x := 2, y := 2 };
''')
query = r'''
UPDATE Foo FILTER true SET { x := - .x };
'''
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"Bar violates exclusivity constraint"):
await self.con.execute(query)
await self.con.execute('''
UPDATE Foo FILTER .name = 'baz' SET { x := 3 };
''')
# now it should be fine
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_12 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_13(self):
# ... make sure we don't try enforcing on non-exclusive constraints
await self.con.execute('''
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY name -> str;
CREATE REQUIRED PROPERTY x -> int64;
CREATE CONSTRAINT expression on ((.x >= 0));
};
INSERT Foo { name := "bar", x := 1 };
INSERT Foo { name := "baz", x := 2 };
''')
query1 = r'''
UPDATE Foo FILTER true SET { name := .name };
'''
query2 = r'''
UPDATE Foo FILTER true SET { x := .x + 1 };
'''
await self.con.execute(query1)
await self.con.execute(query2)
await self.con.execute('''
CREATE TYPE Bar EXTENDING Foo;
''')
await self.con.execute(query1)
await self.con.execute(query2) | )
query1 = r | test_edgeql_insert_update_cross_type_conflict_13 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_14(self):
await self.con.execute('''
create type A {
create property foo -> int64 {
create constraint exclusive;
}
};
create type B extending A;
create type X extending B;
create type Y extending B;
''')
with self.assertRaisesRegex(edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
with x := (insert X { foo := 0 }),
y := (insert Y { foo := 0 }),
select {x, y};
''') | )
with self.assertRaisesRegex(edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute( | test_edgeql_insert_update_cross_type_conflict_14 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_15(self):
await self.con.execute('''
create required global break -> bool { set default := false; };
create type X {
create property foo -> str {
create constraint exclusive;
};
create access policy yes allow all using (true);
create access policy no deny select using (
global break and exists .foo);
};
create type Y extending X;
''')
await self.con.query('''
insert X;
''')
await self.con.query('''
insert Y;
''')
await self.con.execute('''
set global break := true
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.query('''
update X set { foo := "!" };
''') | )
await self.con.query( | test_edgeql_insert_update_cross_type_conflict_15 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_16(self):
await self.con.execute('''
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY name -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Bar EXTENDING Foo;
CREATE TYPE Baz EXTENDING Foo;
INSERT Bar { name := "bar" };
INSERT Baz { name := "baz" };
''')
query = r'''
UPDATE {Bar, Baz} FILTER true SET { name := "!" };
'''
with self.assertRaisesRegex(
edgedb.ConstraintViolationError,
"name violates exclusivity constraint"):
await self.con.execute(query) | )
query = r | test_edgeql_insert_update_cross_type_conflict_16 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_update_cross_type_conflict_17(self):
await self.con.execute('''
create type T;
create type X {
create multi link l -> T {
create property x -> str { create constraint exclusive; }
};
};
create type Y extending X;
insert X;
insert Y;
''')
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
"do not support exclusive constraints on link properties"):
await self.con.execute('''
update X set { l := (insert T { @x := 'x' }) };
''') | )
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
"do not support exclusive constraints on link properties"):
await self.con.execute( | test_edgeql_insert_update_cross_type_conflict_17 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_and_update_01(self):
# INSERTing something that would violate a constraint while
# fixing the violation is still supposed to be an error.
await self.con.execute('''
INSERT Person { name := 'foo' };
''')
with self.assertRaisesRegex(edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
SELECT (
(UPDATE Person FILTER .name = 'foo'
SET { name := 'foo' }),
(INSERT Person { name := 'foo' })
)
''') | )
with self.assertRaisesRegex(edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute( | test_edgeql_insert_and_update_01 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_and_delete_01(self):
# INSERTing something that would violate a constraint while
# fixing the violation is still supposed to be an error.
await self.con.execute('''
INSERT Person { name := 'foo' };
''')
with self.assertRaisesRegex(edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
SELECT (
(DELETE Person FILTER .name = 'foo'),
(INSERT Person { name := 'foo' })
)
''') | )
with self.assertRaisesRegex(edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute( | test_edgeql_insert_and_delete_01 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_and_delete_02(self):
# Assigning the result of a DELETE as a link during an INSERT
# should be an error.
await self.con.execute('''
INSERT Note { name := 'delete me' };
''')
with self.assertRaisesRegex(edgedb.ConstraintViolationError,
r"deletion of default::Note.+ is "
r"prohibited by link target policy"):
await self.con.execute('''
INSERT Person {
name := 'foo',
note := (
DELETE Note FILTER .name = 'delete me' LIMIT 1
)
}
''') | )
with self.assertRaisesRegex(edgedb.ConstraintViolationError,
r"deletion of default::Note.+ is "
r"prohibited by link target policy"):
await self.con.execute( | test_edgeql_insert_and_delete_02 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_multi_exclusive_01(self):
await self.con.execute('''
INSERT Person { name := "asdf", multi_prop := "a" };
''')
await self.con.execute('''
DELETE Person;
''')
await self.con.execute('''
INSERT Person { name := "asdf", multi_prop := "a" };
''') | )
await self.con.execute( | test_edgeql_insert_multi_exclusive_01 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_explicit_id_01(self):
await self.con.execute('''
configure session set allow_user_specified_id := true
''')
await self.con.execute('''
INSERT Person {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff',
name := "test",
}
''')
await self.assert_query_result(
r'''
SELECT Person
''',
[
{'id': 'ffffffff-ffff-ffff-ffff-ffffffffffff'}
]
) | )
await self.con.execute( | test_edgeql_insert_explicit_id_01 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_explicit_id_02(self):
await self.con.execute('''
configure session set allow_user_specified_id := true
''')
await self.con.execute('''
INSERT Person {
id := <uuid>to_json('"ffffffff-ffff-ffff-ffff-ffffffffffff"'),
name := "test",
}
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
INSERT Person {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff',
name := "test2",
}
''') | )
await self.con.execute( | test_edgeql_insert_explicit_id_02 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_explicit_id_03(self):
await self.con.execute('''
configure session set allow_user_specified_id := true
''')
await self.con.execute('''
INSERT Person {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff',
name := "test",
}
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
INSERT DerivedPerson {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff',
name := "test2",
}
''') | )
await self.con.execute( | test_edgeql_insert_explicit_id_03 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_explicit_id_04(self):
await self.con.execute('''
configure session set allow_user_specified_id := true
''')
await self.con.execute('''
create required global break -> bool { set default := false; };
create type X {
create access policy yes allow all using (true);
create access policy no deny select using (global break);
};
create type Y;
''')
await self.con.query('''
insert X {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff'
};
''')
await self.con.execute('''
set global break := true
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.query('''
insert Y {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff'
};
''') | )
await self.con.execute( | test_edgeql_insert_explicit_id_04 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_explicit_id_05(self):
await self.con.execute('''
configure session set allow_user_specified_id := true
''')
await self.con.execute('''
INSERT Person {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff',
name := "test",
}
''')
await self.assert_query_result(
r'''
INSERT Person {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff',
name := "test",
} UNLESS CONFLICT
''',
[]
)
await self.assert_query_result(
r'''
INSERT Person {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff',
name := "test",
} UNLESS CONFLICT ON (.id)
''',
[]
)
await self.assert_query_result(
r'''
INSERT Note {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff',
name := "test",
} UNLESS CONFLICT
''',
[]
)
await self.assert_query_result(
r'''
INSERT Note {
id := <uuid>'ffffffff-ffff-ffff-ffff-ffffffffffff',
name := "test",
} UNLESS CONFLICT ON (.id)
''',
[]
) | )
await self.con.execute( | test_edgeql_insert_explicit_id_05 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_explicit_id_06(self):
await self.con.execute('''
configure session set allow_user_specified_id := true
''')
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
"missing value for required property"
):
await self.con.execute(r'''
INSERT Person {
id := <optional uuid>{},
name := "test",
}
''') | )
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
"missing value for required property"
):
await self.con.execute(r | test_edgeql_insert_explicit_id_06 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_except_constraint_01(self):
# Test basic behavior of a constraint using except
await self.con.execute('''
insert ExceptTest { name := "foo" };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
insert ExceptTest { name := "foo" };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
insert ExceptTest { name := "foo", deleted := false };
''')
await self.con.execute('''
insert ExceptTest { name := "foo", deleted := true };
''')
await self.con.execute('''
insert ExceptTest { name := "bar", deleted := true };
''')
await self.con.execute('''
insert ExceptTest { name := "bar", deleted := true };
''')
await self.con.execute('''
insert ExceptTest { name := "bar" };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
insert ExceptTest { name := "bar" };
''')
await self.con.execute('''
insert ExceptTest { name := "baz" };
''')
await self.con.execute('''
insert ExceptTestSub { name := "bar", deleted := true };
''')
# Now we are going to drop the constraint and then add it back in,
# nothing should error
await self.con.execute('''
alter type ExceptTest {
drop constraint exclusive on (.name) except (.deleted);
};
''')
await self.con.execute('''
alter type ExceptTest {
create constraint exclusive on (.name) except (.deleted);
};
''')
# Now drop it, and add something that *will* break, and recreate it
await self.con.execute('''
alter type ExceptTest {
drop constraint exclusive on (.name) except (.deleted);
};
''')
await self.con.execute('''
insert ExceptTestSub { name := "baz" };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
alter type ExceptTest {
create constraint exclusive on (.name) except (.deleted);
};
''') | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute( | test_edgeql_insert_except_constraint_01 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_except_constraint_02(self):
# Test some self conflict insert cases
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
select {
(insert ExceptTest { name := "foo" }),
(insert ExceptTestSub { name := "foo" }),
};
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
select {
(insert ExceptTest { name := "foo" }),
(insert ExceptTestSub { name := "foo", deleted := false }),
};
''')
await self.con.execute('''
select {
(insert ExceptTest { name := "foo" }),
(insert ExceptTestSub { name := "foo", deleted := true }),
};
''') | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute( | test_edgeql_insert_except_constraint_02 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_except_constraint_03(self):
# Test some self conflict update cases
await self.con.execute('''
insert ExceptTest { name := "a" };
insert ExceptTestSub { name := "b" };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
update ExceptTest set { name := "foo" };
''')
await self.con.execute('''
update ExceptTest set { name := "foo", deleted := true };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
update ExceptTest set { deleted := false };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute('''
update ExceptTest set { deleted := {} };
''') | )
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
"violates exclusivity constraint"):
await self.con.execute( | test_edgeql_insert_except_constraint_03 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_in_free_object_01(self):
await self.assert_query_result(
r"""
select {
obj := (
INSERT InsertTest {
name := 'insert simple 01',
l2 := 0,
}
)
}
""",
[{"obj": {"id": str}}],
)
await self.assert_query_result(
r"""
select {
obj := (
INSERT InsertTest {
name := 'insert simple 02',
l2 := 0,
}
) { name, l2 }
}
""",
[{"obj": {'name': "insert simple 02", 'l2': 0}}],
)
await self.assert_query_result(
r"""
select {
objs := (
for name in {'one', 'two'} union (
INSERT InsertTest {
name := name, l2 := 0,
}
)
)
}
""",
[{"objs": [{"id": str}, {"id": str}]}],
) | ,
[{"obj": {"id": str}}],
)
await self.assert_query_result(
r | test_edgeql_insert_in_free_object_01 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_in_free_object_02(self):
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"mutations are invalid in a shape's computed expression"):
await self.con.query('''
select { foo := 1 } {
obj := (
INSERT InsertTest {
name := 'insert simple 02',
l2 := 0,
}
) { name, l2 }
}
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"mutations are invalid in a shape's computed expression"):
await self.con.query('''
select (for x in {1,2} union FreeObject) {
obj := (
INSERT InsertTest {
name := 'insert simple 01',
l2 := 0,
}
)
};
''')
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"mutations are invalid in a shape's computed expression"):
await self.con.query('''
with X := {
obj := (
INSERT InsertTest {
name := 'insert simple 01',
l2 := 0,
}
)
}, select X;
''') | )
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"mutations are invalid in a shape's computed expression"):
await self.con.query( | test_edgeql_insert_in_free_object_02 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_rebind_with_typenames_01(self):
await self.assert_query_result(
'''
with
update1 := (insert InsertTest {l2:=1}),
select (select update1);
''',
[{'id': str}],
always_typenames=True,
)
await self.assert_query_result(
'''
with
update1 := (insert InsertTest {l2:=1}),
select {update1};
''',
[{'id': str}],
always_typenames=True,
) | with
update1 := (insert InsertTest {l2:=1}),
select (select update1);
''',
[{'id': str}],
always_typenames=True,
)
await self.assert_query_result( | test_edgeql_insert_rebind_with_typenames_01 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_single_linkprop(self):
await self.con.execute('''
insert Subordinate { name := "1" };
insert Subordinate { name := "2" };
''')
for _ in range(10):
await self.con.execute('''
insert InsertTest {
l2 := -1,
sub := (select Subordinate { @note := "!" }
order by random() limit 1)
};
''')
await self.assert_query_result(
'''
select InsertTest { sub: {name, @note} };
''',
[{"sub": {"name": str, "@note": "!"}}] * 10,
)
await self.con.execute('''
update InsertTest set {
sub := (select Subordinate { @note := "!" }
order by random() limit 1)
};
''')
await self.assert_query_result(
'''
select InsertTest { sub: {name, @note} };
''',
[{"sub": {"name": str, "@note": "!"}}] * 10,
) | )
for _ in range(10):
await self.con.execute( | test_edgeql_insert_single_linkprop | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_conditional_01(self):
await self.assert_query_result(
'''
select if <bool>$0 then (
insert InsertTest { l2 := 2 }
) else (
insert DerivedTest { l2 := 200 }
)
''',
[{}],
variables=(True,)
)
await self.assert_query_result(
'''
select InsertTest { l2, tname := .__type__.name }
''',
[
{"l2": 2, "tname": "default::InsertTest"},
],
)
await self.assert_query_result(
'''
select if <bool>$0 then (
insert InsertTest { l2 := 2 }
) else (
insert DerivedTest { l2 := 200 }
)
''',
[{}],
variables=(False,)
)
await self.assert_query_result(
'''
select InsertTest { l2, tname := .__type__.name } order by .l2
''',
[
{"l2": 2, "tname": "default::InsertTest"},
{"l2": 200, "tname": "default::DerivedTest"},
],
)
await self.assert_query_result(
'''
select if array_unpack(<array<bool>>$0) then (
insert InsertTest { l2 := 2 }
) else (
insert DerivedTest { l2 := 200 }
)
''',
[{}, {}],
variables=([True, False],)
)
await self.assert_query_result(
'''
with go := <bool>$0
select if go then (
insert InsertTest { l2 := 100 }
) else {}
''',
[{}],
variables=(True,)
)
await self.assert_query_result(
'''
select InsertTest { l2, tname := .__type__.name } order by .l2
''',
[
{"l2": 2, "tname": "default::InsertTest"},
{"l2": 2, "tname": "default::InsertTest"},
{"l2": 100, "tname": "default::InsertTest"},
{"l2": 200, "tname": "default::DerivedTest"},
{"l2": 200, "tname": "default::DerivedTest"},
],
) | select if <bool>$0 then (
insert InsertTest { l2 := 2 }
) else (
insert DerivedTest { l2 := 200 }
)
''',
[{}],
variables=(True,)
)
await self.assert_query_result( | test_edgeql_insert_conditional_01 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_conditional_03(self):
await self.assert_query_result(
'''
select (for n in array_unpack(<array<int64>>$0) union (
if n % 2 = 0 then
(insert InsertTest { l2 := n }) else {}
)) { l2 } order by .l2;
''',
[{'l2': 2}, {'l2': 4}],
variables=([1, 2, 3, 4, 5],),
)
await self.assert_query_result(
'''
select InsertTest { l2 } order by .l2;
''',
[{'l2': 2}, {'l2': 4}],
) | select (for n in array_unpack(<array<int64>>$0) union (
if n % 2 = 0 then
(insert InsertTest { l2 := n }) else {}
)) { l2 } order by .l2;
''',
[{'l2': 2}, {'l2': 4}],
variables=([1, 2, 3, 4, 5],),
)
await self.assert_query_result( | test_edgeql_insert_conditional_03 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_coalesce_01(self):
await self.assert_query_result(
'''
select (select InsertTest filter .l2 = 2) ??
(insert InsertTest { l2 := 2 });
''',
[{}],
)
await self.assert_query_result(
'''
select (select InsertTest filter .l2 = 2) ??
(insert InsertTest { l2 := 2 });
''',
[{}],
)
await self.assert_query_result(
'''
select count((delete InsertTest))
''',
[1],
) | select (select InsertTest filter .l2 = 2) ??
(insert InsertTest { l2 := 2 });
''',
[{}],
)
await self.assert_query_result( | test_edgeql_insert_coalesce_01 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_coalesce_02(self):
await self.assert_query_result(
'''
select ((select InsertTest filter .l2 = 2), true) ??
((insert InsertTest { l2 := 2 }), false);
''',
[({}, False)],
)
await self.assert_query_result(
'''
select ((select InsertTest filter .l2 = 2), true) ??
((insert InsertTest { l2 := 2 }), false);
''',
[({}, True)],
) | select ((select InsertTest filter .l2 = 2), true) ??
((insert InsertTest { l2 := 2 }), false);
''',
[({}, False)],
)
await self.assert_query_result( | test_edgeql_insert_coalesce_02 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_coalesce_03(self):
await self.assert_query_result(
'''
select (
(update InsertTest filter .l2 = 2 set { name := "!" }) ??
(insert InsertTest { l2 := 2, name := "?" })
) { l2, name }
''',
[{'l2': 2, 'name': "?"}],
)
await self.assert_query_result(
'''
select (
(update InsertTest filter .l2 = 2 set { name := "!" }) ??
(insert InsertTest { l2 := 2, name := "?" })
) { l2, name }
''',
[{'l2': 2, 'name': "!"}],
)
await self.assert_query_result(
'''
select InsertTest { l2, name }
''',
[{'l2': 2, 'name': "!"}],
)
await self.assert_query_result(
'''
select count((delete InsertTest))
''',
[1],
) | select (
(update InsertTest filter .l2 = 2 set { name := "!" }) ??
(insert InsertTest { l2 := 2, name := "?" })
) { l2, name }
''',
[{'l2': 2, 'name': "?"}],
)
await self.assert_query_result( | test_edgeql_insert_coalesce_03 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_coalesce_05(self):
await self.con.execute('''
insert Subordinate { name := "foo" };
''')
Q = '''
for sub in Subordinate union (
(select Note filter .subject = sub) ??
(insert Note { name := "", subject := sub })
);
'''
await self.assert_query_result(
Q,
[{}],
)
await self.assert_query_result(
Q,
[{}],
)
await self.assert_query_result(
'select count(Note)',
[1],
)
await self.con.execute('''
insert Subordinate { name := "bar" };
insert Subordinate { name := "baz" };
''')
await self.assert_query_result(
Q,
[{}] * 3,
)
await self.assert_query_result(
Q,
[{}] * 3,
)
await self.assert_query_result(
'select count(Note)',
[3],
) | )
Q = | test_edgeql_insert_coalesce_05 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_coalesce_nulls_03(self):
await self.con.execute('''
insert Note { name := 'x' }
''')
Q = '''
with name := 'name',
new := (
(select Person filter .name = name) ??
(insert Person { name := name})
),
select (update Note filter .name = 'x' set { subject := new })
{ subject }
'''
await self.assert_query_result(
Q,
[{'subject': {}}],
)
await self.assert_query_result(
Q,
[{'subject': {}}],
) | )
Q = | test_edgeql_insert_coalesce_nulls_03 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_insert_coalesce_nulls_06(self):
await self.con.execute('''
insert Note { name := 'x' }
''')
Q = '''
with name := 'name',
new := (
(select Note filter .name = name) ??
(insert Note { name := name })
),
select (update Note filter .name = 'x' set {
subject := assert_single(new) })
{ subject }
'''
await self.assert_query_result(
Q,
[{'subject': {}}],
)
await self.assert_query_result(
Q,
[{'subject': {}}],
) | )
Q = | test_edgeql_insert_coalesce_nulls_06 | python | geldata/gel | tests/test_edgeql_insert.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_insert.py | Apache-2.0 |
async def test_edgeql_ddl_type_05(self):
await self.con.execute("""
CREATE TYPE A5;
CREATE TYPE Object5 {
CREATE REQUIRED LINK a -> A5;
CREATE REQUIRED PROPERTY b -> str;
};
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
links: {
name,
required,
}
FILTER .name = 'a'
ORDER BY .name,
properties: {
name,
required,
}
FILTER .name = 'b'
ORDER BY .name
}
FILTER .name = 'default::Object5';
""",
[{
'links': [{
'name': 'a',
'required': True,
}],
'properties': [{
'name': 'b',
'required': True,
}],
}],
)
await self.con.execute("""
ALTER TYPE Object5 {
ALTER LINK a SET OPTIONAL;
};
ALTER TYPE Object5 {
ALTER PROPERTY b SET OPTIONAL;
};
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
links: {
name,
required,
}
FILTER .name = 'a'
ORDER BY .name,
properties: {
name,
required,
}
FILTER .name = 'b'
ORDER BY .name
}
FILTER .name = 'default::Object5';
""",
[{
'links': [{
'name': 'a',
'required': False,
}],
'properties': [{
'name': 'b',
'required': False,
}],
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_type_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_type_06(self):
await self.con.execute("""
CREATE TYPE A6 {
CREATE PROPERTY name -> str;
};
CREATE TYPE Object6 {
CREATE SINGLE LINK a -> A6;
CREATE SINGLE PROPERTY b -> str;
};
INSERT A6 { name := 'a6' };
INSERT Object6 {
a := (SELECT A6 LIMIT 1),
b := 'foo'
};
INSERT Object6;
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
links: {
name,
cardinality,
}
FILTER .name = 'a'
ORDER BY .name,
properties: {
name,
cardinality,
}
FILTER .name = 'b'
ORDER BY .name
}
FILTER .name = 'default::Object6';
""",
[{
'links': [{
'name': 'a',
'cardinality': 'One',
}],
'properties': [{
'name': 'b',
'cardinality': 'One',
}],
}],
)
await self.assert_query_result(
r"""
SELECT Object6 {
a: {name},
b,
} FILTER EXISTS .a
""",
[{
'a': {'name': 'a6'},
'b': 'foo',
}]
)
await self.con.execute("""
ALTER TYPE Object6 {
ALTER LINK a SET MULTI;
};
ALTER TYPE Object6 {
ALTER PROPERTY b SET MULTI;
};
""")
await self.assert_query_result(
"""
SELECT schema::ObjectType {
links: {
name,
cardinality,
}
FILTER .name = 'a'
ORDER BY .name,
properties: {
name,
cardinality,
}
FILTER .name = 'b'
ORDER BY .name
}
FILTER .name = 'default::Object6';
""",
[{
'links': [{
'name': 'a',
'cardinality': 'Many',
}],
'properties': [{
'name': 'b',
'cardinality': 'Many',
}],
}],
)
# Check that the data has been migrated correctly.
await self.assert_query_result(
r"""
SELECT Object6 {
a: {name},
b,
} FILTER EXISTS .a
""",
[{
'a': [{'name': 'a6'}],
'b': ['foo'],
}]
)
# Change it back.
await self.con.execute("""
ALTER TYPE Object6 {
ALTER LINK a SET SINGLE USING (SELECT .a LIMIT 1);
};
ALTER TYPE Object6 {
ALTER PROPERTY b SET SINGLE USING (SELECT .b LIMIT 1);
};
""")
await self.assert_query_result(
"""
SELECT schema::ObjectType {
links: {
name,
cardinality,
}
FILTER .name = 'a'
ORDER BY .name,
properties: {
name,
cardinality,
}
FILTER .name = 'b'
ORDER BY .name
}
FILTER .name = 'default::Object6';
""",
[{
'links': [{
'name': 'a',
'cardinality': 'One',
}],
'properties': [{
'name': 'b',
'cardinality': 'One',
}],
}],
)
# Check that the data has been migrated correctly.
await self.assert_query_result(
r"""
SELECT Object6 {
a: {name},
b,
} FILTER EXISTS .a
""",
[{
'a': {'name': 'a6'},
'b': 'foo',
}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_type_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_type_and_add_01(self):
await self.con.execute("""
CREATE TYPE Foo {
CREATE PROPERTY x -> str;
};
""")
await self.con.execute("""
ALTER TYPE Foo {
DROP PROPERTY x;
RENAME TO Bar;
CREATE PROPERTY a -> str;
CREATE LINK b -> Object;
CREATE CONSTRAINT expression ON (true);
CREATE ANNOTATION description := 'hello';
};
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
links: {name} ORDER BY .name,
properties: {name} ORDER BY .name,
constraints: {name},
annotations: {name}
}
FILTER .name = 'default::Bar';
""",
[
{
"annotations": [{"name": "std::description"}],
"constraints": [{"name": "std::expression"}],
"links": [{"name": "__type__"}, {"name": "b"}],
"properties": [{"name": "a"}, {"name": "id"}],
}
],
)
await self.con.execute("""
ALTER TYPE Bar {
DROP PROPERTY a;
DROP link b;
DROP CONSTRAINT expression ON (true);
DROP ANNOTATION description;
};
""") | )
await self.con.execute( | test_edgeql_ddl_rename_type_and_add_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_type_and_add_02(self):
await self.con.execute("""
CREATE TYPE Foo;
""")
await self.con.execute("""
ALTER TYPE Foo {
CREATE PROPERTY a -> str;
CREATE LINK b -> Object;
CREATE CONSTRAINT expression ON (true);
CREATE ANNOTATION description := 'hello';
RENAME TO Bar;
};
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
links: {name} ORDER BY .name,
properties: {name} ORDER BY .name,
constraints: {name},
annotations: {name}
}
FILTER .name = 'default::Bar';
""",
[
{
"annotations": [{"name": "std::description"}],
"constraints": [{"name": "std::expression"}],
"links": [{"name": "__type__"}, {"name": "b"}],
"properties": [{"name": "a"}, {"name": "id"}],
}
],
)
await self.con.execute("""
ALTER TYPE Bar {
DROP PROPERTY a;
DROP link b;
DROP CONSTRAINT expression ON (true);
DROP ANNOTATION description;
};
""") | )
await self.con.execute( | test_edgeql_ddl_rename_type_and_add_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_type_and_drop_01(self):
await self.con.execute("""
CREATE TYPE Foo {
CREATE PROPERTY a -> str;
CREATE LINK b -> Object;
CREATE CONSTRAINT expression ON (true);
CREATE ANNOTATION description := 'hello';
};
""")
await self.con.execute("""
ALTER TYPE Foo {
RENAME TO Bar;
DROP PROPERTY a;
DROP link b;
DROP CONSTRAINT expression ON (true);
DROP ANNOTATION description;
};
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
links: {name} ORDER BY .name,
properties: {name} ORDER BY .name,
constraints: {name},
annotations: {name}
}
FILTER .name = 'default::Bar';
""",
[
{
"annotations": [],
"constraints": [],
"links": [{"name": "__type__"}],
"properties": [{"name": "id"}],
}
],
)
await self.con.execute("""
DROP TYPE Bar;
""") | )
await self.con.execute( | test_edgeql_ddl_rename_type_and_drop_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_type_and_drop_02(self):
await self.con.execute("""
CREATE TYPE Foo {
CREATE PROPERTY a -> str;
CREATE LINK b -> Object;
CREATE CONSTRAINT expression ON (true);
CREATE ANNOTATION description := 'hello';
};
""")
await self.con.execute("""
ALTER TYPE Foo {
DROP PROPERTY a;
DROP link b;
DROP CONSTRAINT expression ON (true);
DROP ANNOTATION description;
RENAME TO Bar;
};
""")
await self.assert_query_result(
r"""
SELECT schema::ObjectType {
links: {name} ORDER BY .name,
properties: {name} ORDER BY .name,
constraints: {name},
annotations: {name}
}
FILTER .name = 'default::Bar';
""",
[
{
"annotations": [],
"constraints": [],
"links": [{"name": "__type__"}],
"properties": [{"name": "id"}],
}
],
)
await self.con.execute("""
DROP TYPE Bar;
""") | )
await self.con.execute( | test_edgeql_ddl_rename_type_and_drop_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_rename_type_and_prop_01(self):
await self.con.execute(r"""
CREATE TYPE Note {
CREATE PROPERTY note -> str;
CREATE LINK friend -> Object;
};
""")
await self.con.execute(r"""
ALTER TYPE Note {
RENAME TO Remark;
ALTER PROPERTY note RENAME TO remark;
ALTER LINK friend RENAME TO enemy;
};
""")
await self.con.execute(r"""
ALTER TYPE Remark {
DROP PROPERTY remark;
DROP LINK enemy;
};
""") | )
await self.con.execute(r | test_edgeql_ddl_rename_type_and_prop_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_14(self):
await self.con.execute("""
CREATE TYPE TestSelfLink1 {
CREATE PROPERTY foo1 -> std::str;
CREATE PROPERTY bar1 -> std::str {
SET default := __source__.foo1;
};
};
""")
await self.con.execute(
"""
INSERT TestSelfLink1 { foo1 := 'hello' };
"""
) | )
await self.con.execute( | test_edgeql_ddl_14 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_15(self):
await self.con.execute(r"""
CREATE TYPE TestSelfLink2 {
CREATE PROPERTY foo2 -> std::str;
CREATE MULTI PROPERTY bar2 -> std::str {
# NOTE: this is a set of all TestSelfLink2.foo2
SET default := TestSelfLink2.foo2;
};
};
INSERT TestSelfLink2 {
foo2 := 'Alice'
};
INSERT TestSelfLink2 {
foo2 := 'Bob'
};
INSERT TestSelfLink2 {
foo2 := 'Carol'
};
""")
await self.assert_query_result(
r"""
SELECT TestSelfLink2 {
foo2,
bar2,
} ORDER BY TestSelfLink2.foo2;
""",
[
{'bar2': [], 'foo2': 'Alice'},
{'bar2': {'Alice'}, 'foo2': 'Bob'},
{'bar2': {'Alice', 'Bob'}, 'foo2': 'Carol'}
],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_15 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_18(self):
await self.con.execute("""
CREATE MODULE foo;
CREATE MODULE bar;
SET MODULE foo;
SET ALIAS b AS MODULE bar;
CREATE SCALAR TYPE foo_t EXTENDING int64 {
CREATE CONSTRAINT expression ON (__subject__ > 0);
};
CREATE SCALAR TYPE b::bar_t EXTENDING int64;
CREATE TYPE Obj {
CREATE PROPERTY foo -> foo_t {
SET default := <foo::foo_t>20;
};
CREATE PROPERTY bar -> b::bar_t;
};
CREATE TYPE b::Obj2 {
CREATE LINK obj -> Obj;
};
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ScalarType {
name,
constraints: {
name,
subjectexpr,
}
}
FILTER .name LIKE '%bar%' OR .name LIKE '%foo%'
ORDER BY .name;
""",
[
{'name': 'bar::bar_t', 'constraints': []},
{'name': 'foo::foo_t', 'constraints': [
{
'name': 'std::expression',
'subjectexpr': '(__subject__ > 0)',
},
]},
]
)
await self.con.execute("""
ALTER SCALAR TYPE foo::foo_t RENAME TO foo::baz_t;
""")
await self.con.execute("""
ALTER SCALAR TYPE foo::baz_t RENAME TO bar::quux_t;
""")
await self.con.execute("""
DROP TYPE bar::Obj2;
DROP TYPE foo::Obj;
DROP SCALAR TYPE bar::quux_t;
""") | )
await self.assert_query_result(
r | test_edgeql_ddl_18 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_19(self):
await self.con.execute("""
CREATE TYPE ActualType {
CREATE REQUIRED PROPERTY foo -> str;
};
CREATE ALIAS Alias1 := ActualType {
bar := 9
};
CREATE ALIAS Alias2 := ActualType {
connected := (SELECT Alias1 ORDER BY Alias1.foo)
};
INSERT ActualType {
foo := 'obj1'
};
INSERT ActualType {
foo := 'obj2'
};
""")
await self.assert_query_result(
r"""
SELECT Alias2 {
foo,
connected: {
foo,
bar
}
}
ORDER BY Alias2.foo;
""",
[
{
'foo': 'obj1',
'connected': [{
'foo': 'obj1',
'bar': 9,
}, {
'foo': 'obj2',
'bar': 9,
}],
},
{
'foo': 'obj2',
'connected': [{
'foo': 'obj1',
'bar': 9,
}, {
'foo': 'obj2',
'bar': 9,
}],
}
]
)
# Make sure @source/@target are correct in created alias
await self.assert_query_result(
r"""
SELECT schema::Link {
pnames := .properties.name
} FILTER .name IN {"connected", '__type__'}
AND .source.name = 'default::Alias2'
""",
[
{"pnames": {'source', 'target'}},
{"pnames": {'source', 'target'}},
]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_19 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_20(self):
await self.con.execute("""
CREATE TYPE A20 {
CREATE REQUIRED PROPERTY foo -> str;
};
CREATE TYPE B20 {
CREATE LINK l -> A20;
};
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
links: {
name,
bases: {
name
}
} FILTER .name = 'l'
}
FILTER .name = 'default::B20'
""",
[
{
'links': [{
'name': 'l',
'bases': [{
'name': 'std::link',
}],
}],
},
]
)
await self.con.execute("""
CREATE ABSTRACT LINK l20;
ALTER TYPE B20 {
ALTER LINK l EXTENDING l20;
};
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
links: {
name,
bases: {
name
}
} FILTER .name = 'l'
}
FILTER .name = 'default::B20'
""",
[
{
'links': [{
'name': 'l',
'bases': [{
'name': 'default::l20',
}],
}],
},
]
)
await self.con.execute("""
ALTER TYPE B20 {
ALTER LINK l DROP EXTENDING l20;
};
""")
await self.assert_query_result(
r"""
WITH MODULE schema
SELECT ObjectType {
links: {
name,
bases: {
name
}
} FILTER .name = 'l'
}
FILTER .name = 'default::B20'
""",
[
{
'links': [{
'name': 'l',
'bases': [{
'name': 'std::link',
}],
}],
},
]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_20 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_23(self):
# Test that an unqualifed reverse link expression
# as an alias pointer target is handled correctly and
# manifests as std::BaseObject.
await self.con.execute("""
CREATE TYPE User;
CREATE TYPE Award {
CREATE LINK user -> User;
};
CREATE ALIAS Alias1 := (SELECT User {
awards := .<user
});
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::Alias1')
SELECT
C.pointers { target: { name } }
FILTER
C.pointers.name = 'awards'
""",
[
{
'target': {
'name': 'std::BaseObject'
}
},
],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_23 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_24(self):
# Test transition of property from inherited to owned.
await self.con.execute("""
CREATE TYPE Desc;
CREATE TYPE Named {
CREATE PROPERTY name -> str;
CREATE LINK desc -> Desc;
};
CREATE TYPE User EXTENDING Named;
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::User')
SELECT
C {
pointers: { @owned }
FILTER .name IN {'name', 'desc'}
};
""",
[
{
'pointers': [{
'@owned': False,
}, {
'@owned': False,
}],
},
],
)
await self.con.execute("""
ALTER TYPE User {
ALTER PROPERTY name SET OWNED;
ALTER LINK desc SET OWNED;
};
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::User')
SELECT
C {
pointers: { @owned }
FILTER .name IN {'name', 'desc'}
};
""",
[
{
'pointers': [{
'@owned': True,
}, {
'@owned': True,
}],
},
],
)
await self.con.execute("""
ALTER TYPE User {
ALTER PROPERTY name {
SET REQUIRED;
CREATE CONSTRAINT exclusive;
};
ALTER LINK desc {
SET REQUIRED;
CREATE CONSTRAINT exclusive;
};
};
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::User')
SELECT
C {
pointers: {
@owned,
required,
constraints: {
name,
}
}
FILTER .name IN {'name', 'desc'}
};
""",
[
{
'pointers': [{
'@owned': True,
'required': True,
'constraints': [{
'name': 'std::exclusive',
}],
}, {
'@owned': True,
'required': True,
'constraints': [{
'name': 'std::exclusive',
}],
}],
},
],
)
# and drop it again
await self.con.execute("""
ALTER TYPE User {
ALTER PROPERTY name DROP OWNED;
ALTER LINK desc DROP OWNED;
};
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::User')
SELECT
C {
pointers: {
@owned,
required,
constraints: {
name,
}
}
FILTER .name IN {'name', 'desc'}
};
""",
[
{
'pointers': [{
'@owned': False,
'required': False,
'constraints': [],
}, {
'@owned': False,
'required': False,
'constraints': [],
}],
},
],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_24 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_26(self):
await self.con.execute("""
CREATE TYPE Target;
CREATE TYPE Source {
CREATE LINK target -> Source;
};
CREATE TYPE Child EXTENDING Source {
ALTER LINK target {
SET REQUIRED;
CREATE PROPERTY foo -> str;
}
};
CREATE TYPE Grandchild EXTENDING Child {
ALTER LINK target {
ALTER PROPERTY foo {
CREATE CONSTRAINT exclusive;
}
}
};
""")
await self.con.execute("""
ALTER TYPE Child ALTER LINK target DROP OWNED;
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::Child')
SELECT
C {
links: {
@owned,
required,
properties: {
name,
} ORDER BY .name
}
FILTER .name = 'target'
};
""",
[
{
'links': [{
'@owned': False,
'required': False,
'properties': [{"name": "source"}, {"name": "target"}],
}],
},
],
)
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::Grandchild')
SELECT
C {
links: {
@owned,
required,
properties: {
name,
@owned,
constraints: {
name,
}
} FILTER .name = 'foo'
}
FILTER .name = 'target'
};
""",
[
{
'links': [{
'@owned': True,
'required': True,
'properties': [{
'name': 'foo',
'@owned': True,
'constraints': [{
'name': 'std::exclusive',
}]
}],
}],
},
],
) | )
await self.con.execute( | test_edgeql_ddl_26 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_27(self):
await self.con.execute("""
CREATE TYPE Base {
CREATE PROPERTY foo -> str;
};
CREATE TYPE Derived EXTENDING Base {
ALTER PROPERTY foo SET REQUIRED;
};
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::Derived')
SELECT
C {
properties: {
@owned,
required,
inherited_fields,
}
FILTER .name = 'foo'
};
""",
[
{
'properties': [{
'@owned': True,
'required': True,
'inherited_fields': {
'cardinality',
'readonly',
'target',
},
}],
},
],
)
await self.con.execute("""
ALTER TYPE Base DROP PROPERTY foo;
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::Derived')
SELECT
C {
properties: {
@owned,
required,
inherited_fields,
}
FILTER .name = 'foo'
};
""",
[
{
'properties': [{
'@owned': True,
'required': True,
'inherited_fields': [],
}],
},
],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_27 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_sequence_01(self):
await self.con.execute("""
CREATE TYPE Foo {
CREATE REQUIRED PROPERTY index -> std::int64;
};
""")
await self.con.execute("""
CREATE SCALAR TYPE ctr EXTENDING std::sequence;
ALTER TYPE Foo {
ALTER PROPERTY index {
SET TYPE ctr;
};
};
""")
await self.con.execute("""
INSERT Foo;
""") | )
await self.con.execute( | test_edgeql_ddl_sequence_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_abstract_link_04(self):
await self.con.execute("""
CREATE ABSTRACT LINK test_object_link {
CREATE PROPERTY test_link_prop -> int64;
CREATE PROPERTY computed_prop := @test_link_prop * 2;
};
CREATE TYPE Target;
CREATE TYPE TestObjectType {
CREATE LINK test_object_link EXTENDING test_object_link
-> Target;
};
INSERT TestObjectType {
test_object_link := (INSERT Target { @test_link_prop := 42 })
};
""")
await self.assert_query_result(
r"""
SELECT TestObjectType {
test_object_link: { @test_link_prop, @computed_prop },
};
""",
[{"test_object_link":
{"@computed_prop": 84, "@test_link_prop": 42}}]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_abstract_link_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_extending_01(self):
await self.con.execute("""
CREATE TYPE Parent {
CREATE PROPERTY name -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Child EXTENDING Parent;
""")
await self.con.execute("""
ALTER TYPE Child DROP EXTENDING Parent;
""")
async with self.assertRaisesRegexTx(
edgedb.QueryError,
"object type 'default::Child' has no link or property 'name'",
):
await self.con.execute("""
SELECT Child.name
""")
# Should be able to drop parent
await self.con.execute("""
DROP TYPE Parent;
""") | )
await self.con.execute( | test_edgeql_ddl_drop_extending_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_extending_02(self):
await self.con.execute("""
CREATE TYPE Parent {
CREATE PROPERTY name -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Child EXTENDING Parent {
ALTER PROPERTY name {
SET OWNED;
ALTER CONSTRAINT exclusive SET OWNED;
};
};
""")
await self.con.execute("""
ALTER TYPE Child DROP EXTENDING Parent;
""")
# The constraint shouldn't be linked anymore
await self.con.execute("""
INSERT Child { name := "foo" };
INSERT Parent { name := "foo" };
""")
await self.con.execute("""
INSERT Parent { name := "bar" };
INSERT Child { name := "bar" };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'name violates exclusivity constraint',
):
await self.con.execute("""
INSERT Parent { name := "bar" };
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'name violates exclusivity constraint',
):
await self.con.execute("""
INSERT Child { name := "bar" };
""")
# Should be able to drop parent
await self.con.execute("""
DROP TYPE Parent;
""") | )
await self.con.execute( | test_edgeql_ddl_drop_extending_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_extending_03(self):
await self.con.execute("""
CREATE TYPE Parent {
CREATE PROPERTY name -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Child EXTENDING Parent {
ALTER PROPERTY name {
SET OWNED;
ALTER CONSTRAINT exclusive SET OWNED;
};
};
CREATE TYPE Grandchild EXTENDING Child;
""")
await self.con.execute("""
ALTER TYPE Child DROP EXTENDING Parent;
""")
# Should be able to drop parent
await self.con.execute("""
DROP TYPE Parent;
""") | )
await self.con.execute( | test_edgeql_ddl_drop_extending_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_extending_04(self):
await self.con.execute("""
CREATE TYPE Parent {
CREATE PROPERTY name -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Child EXTENDING Parent {
ALTER PROPERTY name {
SET OWNED;
ALTER CONSTRAINT exclusive SET OWNED;
};
};
CREATE TYPE Grandchild EXTENDING Child {
ALTER PROPERTY name {
SET OWNED;
ALTER CONSTRAINT exclusive SET OWNED;
};
};
""")
await self.con.execute("""
ALTER TYPE Grandchild DROP EXTENDING Child;
""")
# Should be able to drop parent
await self.con.execute("""
DROP TYPE Child;
DROP TYPE Parent;
""")
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'name violates exclusivity constraint',
):
await self.con.execute("""
INSERT Grandchild { name := "bar" };
INSERT Grandchild { name := "bar" };
""") | )
await self.con.execute( | test_edgeql_ddl_drop_extending_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_extending_05(self):
await self.con.execute("""
CREATE TYPE Parent {
CREATE PROPERTY name -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE Child EXTENDING Parent {
ALTER PROPERTY name {
SET OWNED;
};
};
""")
await self.con.execute("""
ALTER TYPE Child DROP EXTENDING Parent;
""")
# The constraint on Child should be dropped
await self.con.execute("""
INSERT Child { name := "foo" };
INSERT Child { name := "foo" };
""") | )
await self.con.execute( | test_edgeql_ddl_drop_extending_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_extending_06(self):
await self.con.execute("""
CREATE ABSTRACT TYPE Named {
CREATE OPTIONAL SINGLE PROPERTY name -> str;
};
CREATE TYPE Foo EXTENDING Named;
""")
await self.con.execute("""
INSERT Foo { name := "Phil Emarg" };
""")
await self.con.execute("""
ALTER TYPE Foo {
ALTER PROPERTY name {
SET OWNED;
};
DROP EXTENDING Named;
};
DROP TYPE Named;
""")
await self.assert_query_result(
r"""
SELECT Foo.name;
""",
["Phil Emarg"],
) | )
await self.con.execute( | test_edgeql_ddl_drop_extending_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_extending_07(self):
await self.con.execute("""
CREATE ABSTRACT TYPE Named {
CREATE PROPERTY name -> str;
};
CREATE ABSTRACT TYPE Noted {
CREATE PROPERTY note -> str;
};
CREATE TYPE Foo EXTENDING Named {
CREATE PROPERTY note -> str;
};
""")
await self.con.execute("""
INSERT Foo { name := "Phil Emarg", note := "foo" };
""")
# swap parent from Named to Noted, and drop ownership of note
await self.con.execute("""
ALTER TYPE Foo {
ALTER PROPERTY name {
SET OWNED;
};
DROP EXTENDING Named;
EXTENDING Noted LAST;
ALTER PROPERTY note {
DROP OWNED;
};
};
DROP TYPE Named;
""")
await self.assert_query_result(
r"""
SELECT Foo { note, name };
""",
[{"name": "Phil Emarg", "note": "foo"}],
)
await self.con.execute("""
ALTER TYPE Foo {
DROP EXTENDING Noted;
};
""")
with self.assertRaisesRegex(
edgedb.QueryError,
"has no link or property 'note'"):
await self.con.execute(r"""
SELECT Foo.note;
""") | )
await self.con.execute( | test_edgeql_ddl_drop_extending_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_drop_extending_08(self):
await self.con.execute("""
CREATE ABSTRACT TYPE Named {
CREATE OPTIONAL SINGLE PROPERTY name -> str;
};
CREATE ABSTRACT TYPE Named2 {
CREATE OPTIONAL SINGLE PROPERTY name -> str;
};
CREATE TYPE Foo EXTENDING Named;
""")
await self.con.execute("""
INSERT Foo { name := "Phil Emarg" };
""")
# swap parent from Named to Named2; this should preserve the name prop
await self.con.execute("""
ALTER TYPE Foo {
DROP EXTENDING Named;
EXTENDING Named2 LAST;
};
DROP TYPE Named;
""")
await self.assert_query_result(
r"""
SELECT Foo.name;
""",
["Phil Emarg"],
) | )
await self.con.execute( | test_edgeql_ddl_drop_extending_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_add_extending_01(self):
await self.con.execute("""
CREATE TYPE Thing;
CREATE TYPE Foo {
CREATE LINK item -> Object {
CREATE PROPERTY foo -> str;
};
};
INSERT Foo { item := (INSERT Thing { @foo := "test" }) };
""")
await self.con.execute("""
CREATE TYPE Base {
CREATE OPTIONAL SINGLE LINK item -> Object {
CREATE OPTIONAL SINGLE PROPERTY foo -> str;
};
};
""")
await self.con.execute("""
ALTER TYPE Foo {
EXTENDING Base LAST;
ALTER LINK item {
ALTER PROPERTY foo {
DROP OWNED;
};
DROP OWNED;
};
};
""")
await self.assert_query_result(
r"""
SELECT Foo { item: {@foo} };
""",
[{"item": {"@foo": "test"}}],
) | )
await self.con.execute( | test_edgeql_ddl_add_extending_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_03(self):
# Test INSERT as default link expression
await self.con.execute(r"""
CREATE TYPE TestDefaultInsert03;
CREATE TYPE TestDefault03 {
CREATE LINK def03 -> TestDefaultInsert03 {
SET default := (INSERT TestDefaultInsert03);
};
};
""")
await self.assert_query_result(
r"""
SELECT (
count(TestDefault03),
count(TestDefaultInsert03)
);
""",
[[0, 0]],
)
await self.assert_query_result(
r"""
SELECT TestDefault03 {
def03
};
""",
[],
)
# `assert_query_result` is used instead of `execute` to
# highlight the issue #1721
await self.assert_query_result(
r"""INSERT TestDefault03;""",
[{'id': uuid.UUID}]
)
await self.assert_query_result(
r"""
SELECT (
count(TestDefault03),
count(TestDefaultInsert03)
);
""",
[[1, 1]],
)
await self.assert_query_result(
r"""
SELECT TestDefault03 {
def03
};
""",
[{
'def03': {
'id': uuid.UUID
}
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_default_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_04(self):
# Test UPDATE as default link expression
await self.con.execute(r"""
CREATE TYPE TestDefaultUpdate04 {
CREATE PROPERTY val -> str {
CREATE CONSTRAINT exclusive;
};
};
CREATE TYPE TestDefault04 {
CREATE LINK def04 -> TestDefaultUpdate04 {
SET default := (
UPDATE TestDefaultUpdate04
FILTER .val = 'def04'
SET {
val := .val ++ '!'
}
);
};
};
INSERT TestDefaultUpdate04 {
val := 'notdef04'
};
INSERT TestDefaultUpdate04 {
val := 'def04'
};
""")
await self.assert_query_result(
r"""
SELECT TestDefaultUpdate04.val;
""",
{'def04', 'notdef04'},
)
await self.assert_query_result(r"""
SELECT {
(INSERT TestDefault04),
(INSERT TestDefault04)
};
""", [{'id': uuid.UUID}, {'id': uuid.UUID}])
await self.assert_query_result(
r"""
SELECT TestDefaultUpdate04.val;
""",
{'def04!', 'notdef04'},
)
await self.assert_query_result(
r"""
SELECT TestDefault04 {
def04: {
val
}
} ORDER BY .def04.val EMPTY FIRST;
""",
[{
'def04': None
}, {
'def04': {
'val': 'def04!'
}
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_default_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_05(self):
# Test DELETE as default property expression
await self.con.execute(r"""
CREATE TYPE TestDefaultDelete05 {
CREATE PROPERTY val -> str;
};
CREATE TYPE TestDefault05 {
CREATE PROPERTY def05 -> str {
SET default := (SELECT (
DELETE TestDefaultDelete05
FILTER .val = 'def05'
LIMIT 1
).val);
};
};
INSERT TestDefaultDelete05 {
val := 'notdef05'
};
INSERT TestDefaultDelete05 {
val := 'def05'
};
""")
await self.assert_query_result(
r"""
SELECT TestDefaultDelete05.val;
""",
{'def05', 'notdef05'},
)
await self.con.execute(r"""
INSERT TestDefault05;
INSERT TestDefault05;
""")
await self.assert_query_result(
r"""
SELECT TestDefaultDelete05.val;
""",
{'notdef05'},
)
await self.assert_query_result(
r"""
SELECT TestDefault05 {
def05
} ORDER BY .def05 EMPTY FIRST;
""",
[{
'def05': None
}, {
'def05': 'def05'
}],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_default_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_06(self):
# Test DELETE as default link expression
await self.con.execute(r"""
CREATE TYPE TestDefaultDelete06 {
CREATE PROPERTY val -> str;
};
CREATE TYPE TestDefault06 {
CREATE REQUIRED LINK def06 -> TestDefaultDelete06 {
SET default := (
DELETE TestDefaultDelete06
FILTER .val = 'def06'
LIMIT 1
);
};
};
INSERT TestDefaultDelete06 {
val := 'notdef06'
};
""")
await self.assert_query_result(
r"""
SELECT TestDefaultDelete06.val;
""",
{'notdef06'},
)
with self.assertRaisesRegex(
edgedb.MissingRequiredError,
r"missing value for required link 'def06'"):
await self.con.execute(r"""
INSERT TestDefault06;
""") | )
await self.assert_query_result(
r | test_edgeql_ddl_default_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_07(self):
await self.con.execute(r"""
CREATE TYPE Foo;
INSERT Foo;
alter type Foo {
create required property name -> str {
set default := 'something'
}
};
""")
await self.assert_query_result(
r"""
SELECT Foo.name;
""",
{'something'},
) | )
await self.assert_query_result(
r | test_edgeql_ddl_default_07 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_08(self):
await self.con.execute(r"""
CREATE TYPE Foo;
INSERT Foo;
alter type Foo {
create required multi property name -> str {
set default := 'something'
}
};
""")
await self.assert_query_result(
r"""
SELECT Foo.name;
""",
{'something'},
) | )
await self.assert_query_result(
r | test_edgeql_ddl_default_08 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_09(self):
await self.con.execute(r"""
CREATE TYPE Foo;
""")
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
"default value for property 'x' of link 'asdf' of object type "
"'default::Bar' is too complicated; "
"link property defaults must not depend on database contents"
):
await self.con.execute('''
create type Bar {
create link asdf -> Foo {
create property x -> int64 {
set default := count(Object)
}
}
};
''') | )
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
"default value for property 'x' of link 'asdf' of object type "
"'default::Bar' is too complicated; "
"link property defaults must not depend on database contents"
):
await self.con.execute( | test_edgeql_ddl_default_09 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_14(self):
await self.con.execute(r"""
create type X;
insert X;
""")
with self.assertRaisesRegex(
edgedb.MissingRequiredError,
'missing value for required property',
):
await self.con.execute(r"""
alter type X {
create required property foo -> str {
set default := (select "!" filter false);
}
};
""") | )
with self.assertRaisesRegex(
edgedb.MissingRequiredError,
'missing value for required property',
):
await self.con.execute(r | test_edgeql_ddl_default_14 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_16(self):
await self.con.execute(r"""
create type T;
insert T;
alter type T {
create required property y: str {
set default := (with x := { y := "lol" }, select x.y)
}
};
insert T;
""")
await self.assert_query_result(
r"""
select T { y }
""",
[
{'y': "lol"},
{'y': "lol"},
],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_default_16 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_default_id(self):
# Overriding id's default with another uuid generate function is legit
await self.con.execute(r"""
create type A {
alter property id {
set default := std::uuid_generate_v4()
}
};
""")
await self.con.execute(r"""
create type B {
alter property id {
set default := (select std::uuid_generate_v4())
}
};
""")
# But overriding it with other things is not
with self.assertRaisesRegex(
edgedb.SchemaDefinitionError,
"invalid default value for 'id' property",
):
await self.con.execute(r"""
create type C {
alter property id {
set default :=
<uuid>"00000000-0000-0000-0000-000000000000"
}
};
""") | )
await self.con.execute(r | test_edgeql_ddl_default_id | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_property_alter_01(self):
await self.con.execute(r"""
CREATE TYPE Foo {
CREATE PROPERTY bar -> float32;
};
""")
await self.con.execute(r"""
CREATE TYPE TestDefaultCircular {
CREATE PROPERTY def01 -> int64 {
SET default := (SELECT count(TestDefaultCircular));
};
};
""") | )
await self.con.execute(r | test_edgeql_ddl_property_alter_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_target_bad_01(self):
await self.con.execute('''
CREATE TYPE A;
CREATE TYPE B;
CREATE TYPE Base0 {
CREATE LINK foo -> A;
};
CREATE TYPE Base1 {
CREATE LINK foo -> B;
};
''')
with self.assertRaisesRegex(
edgedb.SchemaError,
"inherited link 'foo' of object type 'default::Derived' has a "
"type conflict"
):
await self.con.execute('''
CREATE TYPE Derived EXTENDING Base0, Base1;
''') | )
with self.assertRaisesRegex(
edgedb.SchemaError,
"inherited link 'foo' of object type 'default::Derived' has a "
"type conflict"
):
await self.con.execute( | test_edgeql_ddl_link_target_bad_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_target_bad_02(self):
await self.con.execute('''
CREATE TYPE A;
CREATE TYPE B;
CREATE TYPE C;
CREATE TYPE Base0 {
CREATE LINK foo -> A | B;
};
CREATE TYPE Base1 {
CREATE LINK foo -> C;
};
''')
with self.assertRaisesRegex(
edgedb.SchemaError,
"inherited link 'foo' of object type 'default::Derived' "
"has a type conflict"
):
await self.con.execute('''
CREATE TYPE Derived EXTENDING Base0, Base1;
''') | )
with self.assertRaisesRegex(
edgedb.SchemaError,
"inherited link 'foo' of object type 'default::Derived' "
"has a type conflict"
):
await self.con.execute( | test_edgeql_ddl_link_target_bad_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_target_bad_03(self):
await self.con.execute('''
CREATE TYPE A;
CREATE TYPE Foo {
CREATE LINK a -> A;
CREATE PROPERTY b -> str;
};
''')
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
"cannot RESET TYPE of link 'a' of object type 'default::Foo' "
"because it is not inherited"):
await self.con.execute('''
ALTER TYPE Foo ALTER LINK a RESET TYPE;
''')
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
"cannot RESET TYPE of property 'b' of object type "
"'default::Foo' because it is not inherited"):
await self.con.execute('''
ALTER TYPE Foo ALTER PROPERTY b RESET TYPE;
''') | )
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
"cannot RESET TYPE of link 'a' of object type 'default::Foo' "
"because it is not inherited"):
await self.con.execute( | test_edgeql_ddl_link_target_bad_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_target_bad_04(self):
await self.con.execute('''
CREATE TYPE Foo;
CREATE TYPE Bar;
''')
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
"unsupported type intersection in schema"
):
await self.con.execute('''
CREATE TYPE Spam {
CREATE MULTI LINK foobar := Foo[IS Bar]
};
''') | )
with self.assertRaisesRegex(
edgedb.UnsupportedFeatureError,
"unsupported type intersection in schema"
):
await self.con.execute( | test_edgeql_ddl_link_target_bad_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_target_alter_01(self):
await self.con.execute(r"""
CREATE TYPE GrandParent01 {
CREATE PROPERTY foo -> int64;
};
CREATE TYPE Parent01 EXTENDING GrandParent01;
CREATE TYPE Parent02 EXTENDING GrandParent01;
CREATE TYPE Child EXTENDING Parent01, Parent02;
ALTER TYPE GrandParent01 {
ALTER PROPERTY foo SET TYPE int16;
};
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name IN
{'default::Child', 'default::Parent01'})
SELECT
C.pointers { target: { name } }
FILTER
C.pointers.name = 'foo'
""",
[
{
'target': {
'name': 'std::int16'
}
},
{
'target': {
'name': 'std::int16'
}
},
],
) | )
await self.assert_query_result(
r | test_edgeql_ddl_link_target_alter_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_link_target_alter_06(self):
await self.con.execute(r"""
CREATE TYPE Foo {
CREATE PROPERTY foo -> int64;
CREATE PROPERTY bar := .foo + .foo;
};
""")
await self.con.execute(r"""
ALTER TYPE Foo {
ALTER PROPERTY foo SET TYPE int16;
};
""")
await self.assert_query_result(
r"""
WITH
C := (SELECT schema::ObjectType
FILTER .name = 'default::Foo')
SELECT
C.pointers { target: { name } }
FILTER
C.pointers.name = 'bar'
""",
[
{
'target': {
'name': 'std::int16'
}
},
],
) | )
await self.con.execute(r | test_edgeql_ddl_link_target_alter_06 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_prop_target_subtype_01(self):
await self.con.execute(r"""
CREATE SCALAR TYPE mystr EXTENDING std::str {
CREATE CONSTRAINT std::max_len_value(5)
};
CREATE TYPE Foo {
CREATE PROPERTY a -> std::str;
};
CREATE TYPE Bar EXTENDING Foo {
ALTER PROPERTY a SET TYPE mystr;
};
""")
await self.con.execute('INSERT Foo { a := "123456" }')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'must be no longer than 5 characters'
):
await self.con.execute('INSERT Bar { a := "123456" }')
await self.con.execute("""
ALTER TYPE Bar ALTER PROPERTY a RESET TYPE;
""")
await self.con.execute('INSERT Bar { a := "123456" }') | )
await self.con.execute('INSERT Foo { a := "123456" }')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError,
'must be no longer than 5 characters'
):
await self.con.execute('INSERT Bar { a := "123456" }')
await self.con.execute( | test_edgeql_ddl_prop_target_subtype_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_set_type_using_01(self):
await self.con.execute(r"""
CREATE SCALAR TYPE mystr EXTENDING str;
CREATE TYPE Bar {
CREATE PROPERTY name -> str;
};
CREATE TYPE SubBar EXTENDING Bar;
CREATE TYPE Foo {
CREATE PROPERTY p -> str {
CREATE CONSTRAINT exclusive;
};
CREATE CONSTRAINT exclusive ON (.p);
CREATE REQUIRED PROPERTY r_p -> str;
CREATE MULTI PROPERTY m_p -> str;
CREATE REQUIRED MULTI PROPERTY rm_p -> str;
CREATE LINK l -> Bar {
CREATE PROPERTY lp -> str;
};
CREATE REQUIRED LINK r_l -> Bar {
CREATE PROPERTY lp -> str;
};
CREATE MULTI LINK m_l -> Bar {
CREATE PROPERTY lp -> str;
};
CREATE REQUIRED MULTI LINK rm_l -> Bar {
CREATE PROPERTY lp -> str;
};
};
INSERT Bar {name := 'bar1'};
INSERT SubBar {name := 'bar2'};
WITH
bar := (SELECT Bar FILTER .name = 'bar1' LIMIT 1),
bars := (SELECT Bar),
INSERT Foo {
p := '1',
r_p := '10',
m_p := {'1', '2'},
rm_p := {'10', '20'},
l := bar { @lp := '1' },
r_l := bar { @lp := '10' },
m_l := (
FOR bar IN {enumerate(bars)}
UNION (SELECT bar.1 { @lp := <str>(bar.0 + 1) })
),
rm_l := (
FOR bar IN {enumerate(bars)}
UNION (SELECT bar.1 { @lp := <str>((bar.0 + 1) * 10) })
)
};
WITH
bar := (SELECT Bar FILTER .name = 'bar2' LIMIT 1),
bars := (SELECT Bar),
INSERT Foo {
p := '3',
r_p := '30',
m_p := {'3', '4'},
rm_p := {'30', '40'},
l := bar { @lp := '3' },
r_l := bar { @lp := '30' },
m_l := (
FOR bar IN {enumerate(bars)}
UNION (SELECT bar.1 { @lp := <str>(bar.0 + 3) })
),
rm_l := (
FOR bar IN {enumerate(bars)}
UNION (SELECT bar.1 { @lp := <str>((bar.0 + 3) * 10) })
)
};
""")
# A normal cast of a property.
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p {
SET TYPE int64 USING (<int64>.p)
}
""")
await self.assert_query_result(
'SELECT Foo { p } ORDER BY .p',
[
{'p': 1},
{'p': 3},
],
)
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY m_p {
SET TYPE int64 USING (<int64>.m_p)
}
""")
await self.assert_query_result(
'SELECT Foo { m_p } ORDER BY .p',
[
{'m_p': {1, 2}},
{'m_p': {3, 4}},
],
)
# Cast to an already-compatible type, but with an explicit expression.
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p {
SET TYPE mystr USING (.p ++ '!')
}
""")
await self.assert_query_result(
'SELECT Foo { p } ORDER BY .p',
[
{'p': '1!'},
{'p': '3!'},
],
)
# Cast to the _same_ type, but with an explicit expression.
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p {
SET TYPE str USING (.p ++ '!')
}
""")
await self.assert_query_result(
'SELECT Foo { p } ORDER BY .p',
[
{'p': '1!'},
{'p': '3!'},
],
)
# A reference to another property of the same host type.
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p {
SET TYPE int64 USING (<int64>.r_p)
}
""")
await self.assert_query_result(
'SELECT Foo { p } ORDER BY .p',
[
{'p': 10},
{'p': 30},
],
)
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY m_p {
SET TYPE int64 USING (<int64>.m_p + <int64>.r_p)
}
""")
await self.assert_query_result(
'SELECT Foo { m_p } ORDER BY .p',
[
{'m_p': {11, 12}},
{'m_p': {33, 34}},
],
)
async with self._run_and_rollback():
# This had trouble if there was a SELECT, at one point.
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY m_p {
SET TYPE int64 USING (SELECT <int64>.m_p + <int64>.r_p)
}
""")
# Conversion expression that reduces cardinality...
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p {
SET TYPE int64 USING (<int64>{})
}
""")
await self.assert_query_result(
'SELECT Foo { p } ORDER BY .p',
[
{'p': None},
{'p': None},
],
)
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY m_p {
SET TYPE int64 USING (
<int64>{} IF <int64>.m_p % 2 = 0 ELSE <int64>.m_p
)
}
""")
await self.assert_query_result(
'SELECT Foo { m_p } ORDER BY .p',
[
{'m_p': {1}},
{'m_p': {3}},
],
)
# ... should fail if empty set is produced and the property is required
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
r"missing value for required property 'r_p'"
r" of object type 'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY r_p {
SET TYPE int64 USING (<int64>{})
}
""")
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
r"missing value for required property 'rm_p'"
r" of object type 'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY rm_p {
SET TYPE int64 USING (
<int64>{} IF True ELSE <int64>.rm_p
)
}
""")
# Straightforward link cast.
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l {
SET TYPE SubBar USING (.l[IS SubBar])
}
""")
await self.assert_query_result(
'SELECT Foo { l: {name} } ORDER BY .p',
[
{'l': None},
{'l': {'name': 'bar2'}},
],
)
await self.con.execute("""
ALTER TYPE Foo ALTER LINK m_l {
SET TYPE SubBar USING (.m_l[IS SubBar])
}
""")
await self.assert_query_result(
'SELECT Foo { m_l: {name} } ORDER BY .p',
[
{'m_l': [{'name': 'bar2'}]},
{'m_l': [{'name': 'bar2'}]},
],
)
# Use a more elaborate expression for the tranform.
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l {
SET TYPE SubBar USING (SELECT .m_l[IS SubBar] LIMIT 1)
}
""")
await self.assert_query_result(
'SELECT Foo { l: {name, @lp} } ORDER BY .p',
[
{'l': {'name': 'bar2', '@lp': '1'}},
{'l': {'name': 'bar2', '@lp': '3'}},
],
)
# Check that minimum cardinality constraint is enforced on links too...
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
r"missing value for required link 'r_l'"
r" of object type 'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK r_l {
SET TYPE SubBar USING (.r_l[IS SubBar])
}
""")
async with self.assertRaisesRegexTx(
edgedb.MissingRequiredError,
r"missing value for required link 'rm_l'"
r" of object type 'default::Foo'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK rm_l {
SET TYPE SubBar USING (SELECT SubBar FILTER False LIMIT 1)
}
""")
# Test link property transforms now.
async with self._run_and_rollback():
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l ALTER PROPERTY lp {
SET TYPE int64 USING (<int64>@lp)
}
""")
await self.assert_query_result(
'SELECT Foo { l: { @lp } } ORDER BY .p',
[
{'l': {'@lp': 1}},
{'l': {'@lp': 3}},
],
)
async with self._run_and_rollback():
# Also once had SELECT trouble
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l ALTER PROPERTY lp {
SET TYPE int64 USING (SELECT <int64>@lp)
}
""") | )
# A normal cast of a property.
async with self._run_and_rollback():
await self.con.execute( | test_edgeql_ddl_ptr_set_type_using_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_set_type_using_02(self):
await self.con.execute(r"""
CREATE ABSTRACT TYPE Parent {
CREATE PROPERTY name -> str;
};
CREATE TYPE Child EXTENDING Parent;
INSERT Child { name := "10" };
""")
await self.con.execute(r"""
ALTER TYPE Parent {
ALTER PROPERTY name {
SET TYPE int64 USING (<int64>.name)
}
}
""")
await self.assert_query_result(
'SELECT Child { name }',
[
{'name': 10},
]
) | )
await self.con.execute(r | test_edgeql_ddl_ptr_set_type_using_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_set_type_using_03(self):
# check that defaults don't break things
await self.con.execute(r"""
create type Foo {
create property x -> str {
set default := '';
};
create multi property y -> str {
set default := '';
};
};
# And that aliases don't either
create alias Alias := Foo;
""")
await self.con.execute(r"""
alter type Foo {
alter property x {
set default := 0;
set type int64 using (<int64>.x);
};
alter property y {
set default := 0;
set type int64 using (<int64>.y);
};
};
""")
await self.con.execute(r"""
create type Bar {
create link l -> Foo {
create property x -> str {
set default := '';
}
}
};
""")
await self.con.execute(r"""
alter type Bar {
alter link l {
alter property x {
set default := 0;
set type int64 using (<int64>@x);
}
}
};
""") | )
await self.con.execute(r | test_edgeql_ddl_ptr_set_type_using_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_set_type_using_04(self):
# check that defaults don't break things
await self.con.execute(r"""
create scalar type X extending sequence;
create type Foo {
create property x -> X;
};
""")
await self.con.execute(r"""
alter type Foo {
alter property x {
set type array<str> using ([<str>.x]);
}
};
""")
await self.con.execute(r"""
create type Bar {
create property x -> int64;
};
""")
await self.con.execute(r"""
alter type Bar {
alter property x {
set type X using (<X>.x);
}
};
""")
await self.con.execute(r"""
create type Baz {
create multi property x -> int64;
};
""")
await self.con.execute(r"""
alter type Baz {
alter property x {
set type X using (<X>.x);
}
};
""") | )
await self.con.execute(r | test_edgeql_ddl_ptr_set_type_using_04 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_set_type_validation(self):
await self.con.execute(r"""
CREATE TYPE Bar;
CREATE TYPE Spam;
CREATE TYPE Egg;
CREATE TYPE Foo {
CREATE PROPERTY p -> str;
CREATE LINK l -> Bar {
CREATE PROPERTY lp -> str;
};
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"property 'p' of object type 'default::Foo' cannot be cast"
r" automatically from scalar type 'std::str' to scalar"
r" type 'std::int64'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p SET TYPE int64;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"result of USING clause for the alteration of"
r" property 'p' of object type 'default::Foo' cannot be cast"
r" automatically from scalar type 'std::float64' to scalar"
r" type 'std::int64'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p
SET TYPE int64 USING (<float64>.p)
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"possibly more than one element returned by the USING clause for"
r" the alteration of property 'p' of object type 'default::Foo',"
r" while a singleton is expected"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p SET TYPE int64 USING ({1, 2})
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"link 'l' of object type 'default::Foo' cannot be cast"
r" automatically from object type 'default::Bar' to object"
r" type 'default::Spam'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l SET TYPE Spam;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"result of USING clause for the alteration of"
r" link 'l' of object type 'default::Foo' cannot be cast"
r" automatically from object type '\(default::Bar & default::Egg\)'"
r" to object type 'default::Spam'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l SET TYPE Spam USING (.l[IS Egg])
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"possibly more than one element returned by the USING clause for"
r" the alteration of link 'l' of object type 'default::Foo', while"
r" a singleton is expected"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l SET TYPE Spam USING (SELECT Spam)
""") | )
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"property 'p' of object type 'default::Foo' cannot be cast"
r" automatically from scalar type 'std::str' to scalar"
r" type 'std::int64'"
):
await self.con.execute( | test_edgeql_ddl_ptr_set_type_validation | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_using_dml_01(self):
await self.con.execute(
r"""
CREATE TYPE Hello;
CREATE TYPE World {
CREATE LINK hell -> Hello;
CREATE MULTI LINK heaven -> Hello;
};
INSERT World {
heaven := {
(INSERT Hello),
(INSERT Hello),
(INSERT Hello),
}
};
INSERT World {
hell := (INSERT Hello),
heaven := {
(INSERT Hello),
(INSERT Hello),
}
};
"""
)
self.assertEqual(len(await self.con.query("SELECT Hello")), 6)
await self.con.execute(
r"""
ALTER TYPE World {
ALTER LINK hell SET REQUIRED USING (INSERT Hello);
ALTER LINK heaven SET SINGLE USING (INSERT Hello);
}
"""
)
self.assertEqual(len(await self.con.query("SELECT Hello")), 9)
res = await self.con.query(
"SELECT World { hell: { id }, heaven: { id } }"
)
self.assertEqual(len(res), 2)
set_of_hellos = {
world.hell.id for world in res
}.union({
world.heaven.id for world in res
})
self.assertEqual(len(set_of_hellos), 4) | )
self.assertEqual(len(await self.con.query("SELECT Hello")), 6)
await self.con.execute(
r | test_edgeql_ddl_ptr_using_dml_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_using_dml_02(self):
await self.con.execute(
r"""
CREATE TYPE Hello;
CREATE TYPE World {
CREATE LINK hell -> Hello;
CREATE MULTI LINK heaven -> Hello;
};
"""
)
await self.con.execute(
r"""
ALTER TYPE World {
ALTER LINK hell SET REQUIRED USING (INSERT Hello);
ALTER LINK heaven SET SINGLE USING (INSERT Hello);
}
"""
) | )
await self.con.execute(
r | test_edgeql_ddl_ptr_using_dml_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_using_dml_05(self):
await self.con.execute(
r"""
CREATE TYPE Hello {
CREATE PROPERTY bar -> str;
};
CREATE TYPE World {
CREATE PROPERTY foo -> str;
CREATE LINK hell -> Hello;
};
INSERT World { foo := 'hello' };
"""
)
await self.con.execute(
r"""
ALTER TYPE World {
ALTER LINK hell SET REQUIRED
USING (INSERT Hello { bar := World.foo });
}
"""
) | )
await self.con.execute(
r | test_edgeql_ddl_ptr_using_dml_05 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_set_cardinality_01(self):
await self.con.execute(r'''
CREATE TYPE Foo {
CREATE MULTI PROPERTY bar -> str;
};
INSERT Foo { bar := "foo" };
ALTER TYPE Foo { ALTER PROPERTY bar {
SET SINGLE USING (assert_single(.bar))
} };
''')
await self.assert_query_result(
r"""
SELECT Foo { bar }
""",
[
{'bar': "foo"}
]
)
# Make sure the delete triggers get cleaned up
await self.assert_query_result(
r"""
DELETE Foo
""",
[
{}
]
) | )
await self.assert_query_result(
r | test_edgeql_ddl_ptr_set_cardinality_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_set_cardinality_02(self):
await self.con.execute(r"""
create type B {
create multi property x -> str {
create constraint exclusive;
};
};
create type C extending B;
""")
await self.con.execute(r"""
alter type B alter property x set single using (select .x limit 1);
""")
await self.con.execute('''
insert B { x := 'a' };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, ''
):
await self.con.execute('''
insert B { x := 'a' };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, ''
):
await self.con.execute('''
insert C { x := 'a' };
''')
await self.con.execute(r"""
drop type C;
drop type B;
""") | )
await self.con.execute(r | test_edgeql_ddl_ptr_set_cardinality_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_set_cardinality_03(self):
await self.con.execute(r"""
create type B {
create property x -> str {
create constraint exclusive;
}
};
create type C extending B;
""")
await self.con.execute(r"""
alter type B alter property x set multi;
""")
await self.con.execute('''
insert B { x := 'a' };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, ''
):
await self.con.execute('''
insert B { x := 'a' };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, ''
):
await self.con.execute('''
insert C { x := 'a' };
''')
await self.con.execute(r"""
drop type C;
drop type B;
""") | )
await self.con.execute(r | test_edgeql_ddl_ptr_set_cardinality_03 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_set_cardinality_validation(self):
await self.con.execute(r"""
CREATE TYPE Bar;
CREATE TYPE Egg;
CREATE TYPE Foo {
CREATE MULTI PROPERTY p -> str;
CREATE MULTI LINK l -> Bar {
CREATE PROPERTY lp -> str;
};
};
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"cannot automatically convert property 'p' of object type"
r" 'default::Foo' to 'single' cardinality"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p SET SINGLE;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"result of USING clause for the alteration of"
r" property 'p' of object type 'default::Foo' cannot be cast"
r" automatically from scalar type 'std::float64' to scalar"
r" type 'std::int64'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p
SET TYPE int64 USING (<float64>.p)
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"possibly more than one element returned by the USING clause for"
r" the alteration of property 'p' of object type 'default::Foo',"
r" while a singleton is expected"
):
await self.con.execute("""
ALTER TYPE Foo ALTER PROPERTY p SET SINGLE USING ({1, 2})
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"cannot automatically convert link 'l' of object type"
r" 'default::Foo' to 'single' cardinality"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l SET SINGLE;
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"result of USING clause for the alteration of"
r" link 'l' of object type 'default::Foo' cannot be cast"
r" automatically from object type 'default::Egg'"
r" to object type 'default::Bar'"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l
SET SINGLE USING (SELECT Egg LIMIT 1);
""")
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"possibly more than one element returned by the USING clause for"
r" the alteration of link 'l' of object type 'default::Foo', while"
r" a singleton is expected"
):
await self.con.execute("""
ALTER TYPE Foo ALTER LINK l SET SINGLE USING (SELECT Bar)
""") | )
async with self.assertRaisesRegexTx(
edgedb.SchemaError,
r"cannot automatically convert property 'p' of object type"
r" 'default::Foo' to 'single' cardinality"
):
await self.con.execute( | test_edgeql_ddl_ptr_set_cardinality_validation | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_using_01(self):
await self.con.execute(r"""
create type B {
create property y -> str;
create property x -> str {
create constraint exclusive;
};
create constraint exclusive on (.x);
};
create type C extending B;
""")
await self.con.execute(r"""
alter type B alter property x using (.y);
""")
await self.con.execute('''
insert B { y := 'a' };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, ''
):
await self.con.execute('''
insert B { y := 'a' };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, ''
):
await self.con.execute('''
insert C { y := 'a' };
''')
await self.con.execute(r"""
drop type C;
drop type B;
""") | )
await self.con.execute(r | test_edgeql_ddl_ptr_using_01 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.py | Apache-2.0 |
async def test_edgeql_ddl_ptr_using_02(self):
await self.con.execute(r"""
create type B {
create multi property y -> str;
create multi property x -> str {
create constraint exclusive;
};
};
create type C extending B;
""")
await self.con.execute(r"""
alter type B alter property x using (.y);
""")
await self.con.execute('''
insert B { y := 'a' };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, ''
):
await self.con.execute('''
insert B { y := 'a' };
''')
async with self.assertRaisesRegexTx(
edgedb.ConstraintViolationError, ''
):
await self.con.execute('''
insert C { y := 'a' };
''')
await self.con.execute(r"""
drop type C;
drop type B;
""") | )
await self.con.execute(r | test_edgeql_ddl_ptr_using_02 | python | geldata/gel | tests/test_edgeql_ddl.py | https://github.com/geldata/gel/blob/master/tests/test_edgeql_ddl.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.