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
182
| url
stringlengths 46
251
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
async def test_sql_dml_insert_14(self):
with self.assertRaisesRegex(
asyncpg.InvalidTextRepresentationError,
'invalid input syntax for type uuid',
):
await self.scon.execute(
'''
INSERT INTO "Document" (title, owner_id)
VALUES
('Briefing', 'bad uuid')
'''
) | INSERT INTO "Document" (title, owner_id)
VALUES
('Briefing', 'bad uuid') | test_sql_dml_insert_14 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_15(self):
with self.assertRaisesRegex(
asyncpg.exceptions.CardinalityViolationError,
"object type default::User with id '[0-9a-f-]+' does not exist",
):
await self.scon.execute(
'''
INSERT INTO "Document" (title, owner_id)
VALUES
('Report', '343a6c20-2e3b-11ef-8798-ebce402e7d3f')
'''
) | INSERT INTO "Document" (title, owner_id)
VALUES
('Report', '343a6c20-2e3b-11ef-8798-ebce402e7d3f') | test_sql_dml_insert_15 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_16(self):
with self.assertRaisesRegex(
asyncpg.exceptions.CannotCoerceError,
'cannot cast type boolean to uuid',
):
await self.scon.execute(
'''
INSERT INTO "Document" (title, owner_id)
VALUES ('Briefing', FALSE)
'''
) | INSERT INTO "Document" (title, owner_id)
VALUES ('Briefing', FALSE) | test_sql_dml_insert_16 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_17a(self):
# default values
await self.scon.execute(
'''
INSERT INTO "Document" DEFAULT VALUES;
'''
)
await self.scon.execute(
'''
INSERT INTO "Document" (id, title) VALUES (DEFAULT, 'Report');
'''
)
res = await self.squery_values('SELECT title FROM "Document"')
self.assert_data_shape(res, tb.bag([[None], ['Report (new)']]))
await self.scon.execute(
'''
INSERT INTO "Document" (title) VALUES ('Report2'), (DEFAULT);
'''
)
res = await self.squery_values('SELECT title FROM "Document"')
self.assert_data_shape(
res,
tb.bag([
[None],
[None],
['Report (new)'],
['Report2 (new)'],
]),
)
await self.scon.execute(
'''
INSERT INTO "Post" (title) VALUES ('post'), (DEFAULT);
'''
)
res = await self.squery_values('SELECT title FROM "Post"')
self.assert_data_shape(
res,
tb.bag([
['post'],
['untitled'],
]),
) | INSERT INTO "Document" DEFAULT VALUES; | test_sql_dml_insert_17a | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_17b(self):
# more default values
await self.scon.execute(
'''
INSERT INTO "Post" (id, title, content) VALUES
(DEFAULT, 'foo', 'bar'),
(DEFAULT, 'post', DEFAULT),
(DEFAULT, DEFAULT, 'content'),
(DEFAULT, DEFAULT, DEFAULT);
'''
)
res = await self.squery_values('SELECT title, content FROM "Post"')
self.assert_data_shape(
res,
tb.bag([
['foo', 'bar'],
['post', 'This page intentionally left blank'],
['untitled', 'content'],
['untitled', 'This page intentionally left blank'],
]),
) | INSERT INTO "Post" (id, title, content) VALUES
(DEFAULT, 'foo', 'bar'),
(DEFAULT, 'post', DEFAULT),
(DEFAULT, DEFAULT, 'content'),
(DEFAULT, DEFAULT, DEFAULT); | test_sql_dml_insert_17b | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_18(self):
res = await self.scon.fetch(
'''
WITH
a as (INSERT INTO "Child" (prop) VALUES ('a')),
b as (INSERT INTO "Child" (prop) VALUES ('b_0'), ('b_1'))
SELECT line FROM "Log" ORDER BY line;
'''
)
# changes to the database are not visible in the same query
self.assert_shape(res, 0, 0)
# so we need to re-select
res = await self.squery_values('SELECT line FROM "Log" ORDER BY line;')
self.assertEqual(
res,
[
["inserted all"],
["inserted each a"],
["inserted each b_0"],
["inserted each b_1"],
],
) | WITH
a as (INSERT INTO "Child" (prop) VALUES ('a')),
b as (INSERT INTO "Child" (prop) VALUES ('b_0'), ('b_1'))
SELECT line FROM "Log" ORDER BY line; | test_sql_dml_insert_18 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_19(self):
# exclusive on base, then insert into base and child
with self.assertRaisesRegex(
asyncpg.ExclusionViolationError,
'duplicate key value violates unique constraint '
'"[0-9a-f-]+;schemaconstr"',
):
await self.scon.execute(
'''
WITH
a as (INSERT INTO "Base" (prop) VALUES ('a')),
b as (INSERT INTO "Child" (prop) VALUES ('a'))
SELECT 1
'''
) | WITH
a as (INSERT INTO "Base" (prop) VALUES ('a')),
b as (INSERT INTO "Child" (prop) VALUES ('a'))
SELECT 1 | test_sql_dml_insert_19 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_20(self):
# CommandComplete tag (inserted rows) with no RETURNING
query = '''
INSERT INTO "Document" (title) VALUES ('Report'), ('Briefing');
'''
# extended (binary) protocol, because fetch
res = await self.scon.fetch(query)
# actually, no DataRows are returned, but asyncpg returns [] anyway
self.assert_shape(res, 0, 0)
# simple (text) protocol
res = await self.scon.execute(query)
self.assertEqual(res, 'INSERT 0 2')
# extended (binary) protocol because we used args
query = '''
INSERT INTO "Document" (title) VALUES ($1), ($2);
'''
res = await self.scon.execute(query, 'Report', 'Briefing')
self.assertEqual(res, 'INSERT 0 2') | # extended (binary) protocol, because fetch
res = await self.scon.fetch(query)
# actually, no DataRows are returned, but asyncpg returns [] anyway
self.assert_shape(res, 0, 0)
# simple (text) protocol
res = await self.scon.execute(query)
self.assertEqual(res, 'INSERT 0 2')
# extended (binary) protocol because we used args
query = | test_sql_dml_insert_20 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_21(self):
# CommandComplete tag (inserted rows) with RETURNING
query = '''
INSERT INTO "Document" (title) VALUES ('Report'), ('Briefing')
RETURNING id as my_id;
'''
res = await self.scon.fetch(query)
self.assert_shape(res, rows=2, columns=["my_id"])
# simple (text) protocol
res = await self.scon.execute(query)
self.assertEqual(res, 'INSERT 0 2')
# extended (binary) protocol because we used args
query = '''
INSERT INTO "Document" (title) VALUES ($1), ($2)
RETURNING id as my_id;
'''
res = await self.scon.execute(query, 'Report', 'Briefing')
self.assertEqual(res, 'INSERT 0 2') | res = await self.scon.fetch(query)
self.assert_shape(res, rows=2, columns=["my_id"])
# simple (text) protocol
res = await self.scon.execute(query)
self.assertEqual(res, 'INSERT 0 2')
# extended (binary) protocol because we used args
query = | test_sql_dml_insert_21 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_22(self):
# insert into link table
query = '''
INSERT INTO "Document" (title) VALUES ('Report'), ('Briefing')
RETURNING id;
'''
documents = await self.squery_values(query)
query = '''
WITH
u1 AS (INSERT INTO "User" DEFAULT VALUES RETURNING id),
u2 AS (INSERT INTO "User" DEFAULT VALUES RETURNING id)
SELECT id from u1 UNION ALL SELECT id from u2
'''
users = await self.squery_values(query)
res = await self.scon.execute(
'''
INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2)
''',
documents[0][0],
users[0][0],
)
self.assertEqual(res, 'INSERT 0 1')
res = await self.scon.execute(
'''
INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2), ($1, $3)
''',
documents[1][0],
users[0][0],
users[1][0],
)
self.assertEqual(res, 'INSERT 0 2') | documents = await self.squery_values(query)
query = | test_sql_dml_insert_22 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_24(self):
# insert into link table, link properties
documents = await self.squery_values(
'''
INSERT INTO "Document" (title) VALUES ('Report') RETURNING id
'''
)
users = await self.squery_values(
'''
INSERT INTO "User" DEFAULT VALUES RETURNING id
'''
)
res = await self.scon.execute(
'''
WITH t(doc, usr) as (VALUES ($1::uuid, $2::uuid))
INSERT INTO "Document.shared_with" (source, target, can_edit)
SELECT doc, usr, TRUE FROM t
''',
documents[0][0],
users[0][0],
)
self.assertEqual(res, 'INSERT 0 1')
res = await self.squery_values(
'SELECT can_edit FROM "Document.shared_with"'
)
self.assertEqual(res, [[True]]) | INSERT INTO "Document" (title) VALUES ('Report') RETURNING id | test_sql_dml_insert_24 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_27(self):
with self.assertRaisesRegex(
asyncpg.PostgresError,
'column source is required when inserting into link tables',
):
await self.squery_values(
'''
INSERT INTO "Document.shared_with" (target, can_edit)
VALUES ('uuid 1'::uuid, FALSE)
''',
)
with self.assertRaisesRegex(
asyncpg.PostgresError,
'column target is required when inserting into link tables',
):
await self.squery_values(
'''
INSERT INTO "Document.shared_with" (source, can_edit)
VALUES ('uuid 1'::uuid, FALSE)
''',
) | INSERT INTO "Document.shared_with" (target, can_edit)
VALUES ('uuid 1'::uuid, FALSE)
''',
)
with self.assertRaisesRegex(
asyncpg.PostgresError,
'column target is required when inserting into link tables',
):
await self.squery_values( | test_sql_dml_insert_27 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_29(self):
res = await self.scon.execute(
'''
INSERT INTO "User" (id) VALUES (DEFAULT), (DEFAULT)
'''
)
self.assertEqual(res, 'INSERT 0 2') | INSERT INTO "User" (id) VALUES (DEFAULT), (DEFAULT) | test_sql_dml_insert_29 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_31(self):
res = await self.squery_values(
'''
WITH u as (
INSERT INTO "User" (id) VALUES (DEFAULT), (DEFAULT) RETURNING id
)
INSERT INTO "Document" (title, owner_id)
SELECT 'Report', u.id FROM u
RETURNING title, owner_id
'''
)
self.assertEqual(
res, [['Report (new)', res[0][1]], ['Report (new)', res[1][1]]]
) | WITH u as (
INSERT INTO "User" (id) VALUES (DEFAULT), (DEFAULT) RETURNING id
)
INSERT INTO "Document" (title, owner_id)
SELECT 'Report', u.id FROM u
RETURNING title, owner_id | test_sql_dml_insert_31 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_32(self):
with self.assertRaisesRegex(
asyncpg.PostgresError,
'cannot write into table "columns"',
):
await self.squery_values(
'''
INSERT INTO information_schema.columns DEFAULT VALUES
'''
) | INSERT INTO information_schema.columns DEFAULT VALUES | test_sql_dml_insert_32 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_33(self):
# TODO: error message should say `owner_id` not `owner`
with self.assertRaisesRegex(
asyncpg.PostgresError,
'Expected 2 columns \\(title, owner\\), but got 1',
):
await self.squery_values(
'''
INSERT INTO "Document" (title, owner_id)
VALUES ('Report'), ('Report'), ('Briefing')
'''
) | INSERT INTO "Document" (title, owner_id)
VALUES ('Report'), ('Report'), ('Briefing') | test_sql_dml_insert_33 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_34(self):
id1 = uuid.uuid4()
id2 = uuid.uuid4()
id3 = uuid.uuid4()
id4 = uuid.uuid4()
id5 = uuid.uuid4()
await self.scon.execute("SET LOCAL allow_user_specified_id TO TRUE")
res = await self.squery_values(
f'''
INSERT INTO "Document" (id)
VALUES ($1), ('{id2}')
RETURNING id
''',
id1,
)
self.assertEqual(res, [[id1], [id2]])
res = await self.squery_values(
f'''
INSERT INTO "Document" (id)
SELECT id FROM (VALUES ($1::uuid), ('{id4}')) t(id)
RETURNING id
''',
id3,
)
self.assertEqual(res, [[id3], [id4]])
res = await self.squery_values(
f'''
INSERT INTO "Document" (id)
VALUES ($1)
RETURNING id
''',
id5,
)
self.assertEqual(res, [[id5]]) | ,
id1,
)
self.assertEqual(res, [[id1], [id2]])
res = await self.squery_values(
f | test_sql_dml_insert_34 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_35(self):
with self.assertRaisesRegex(
asyncpg.exceptions.DataError,
"cannot assign to property 'id'",
):
res = await self.squery_values(
f'''
INSERT INTO "Document" (id) VALUES ($1) RETURNING id
''',
uuid.uuid4(),
)
await self.scon.execute('SET LOCAL allow_user_specified_id TO TRUE')
id = uuid.uuid4()
res = await self.squery_values(
f'''
INSERT INTO "Document" (id) VALUES ($1) RETURNING id
''',
id,
)
self.assertEqual(res, [[id]]) | ,
uuid.uuid4(),
)
await self.scon.execute('SET LOCAL allow_user_specified_id TO TRUE')
id = uuid.uuid4()
res = await self.squery_values(
f | test_sql_dml_insert_35 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_38(self):
res = await self.scon.execute(
'''
WITH
d AS (
INSERT INTO "Document" (title) VALUES ('Report') RETURNING id
),
u AS (
INSERT INTO "User" DEFAULT VALUES RETURNING id
)
INSERT INTO "Document.shared_with" (source, target, can_edit)
SELECT d.id, u.id, TRUE FROM d, u
'''
)
self.assertEqual(res, 'INSERT 0 1')
res = await self.squery_values(
'SELECT can_edit FROM "Document.shared_with"'
)
self.assertEqual(res, [[True]]) | WITH
d AS (
INSERT INTO "Document" (title) VALUES ('Report') RETURNING id
),
u AS (
INSERT INTO "User" DEFAULT VALUES RETURNING id
)
INSERT INTO "Document.shared_with" (source, target, can_edit)
SELECT d.id, u.id, TRUE FROM d, u | test_sql_dml_insert_38 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_40(self):
await self.squery_values(
f'''
INSERT INTO "User" DEFAULT VALUES
'''
)
res = await self.scon.execute(
f'''
INSERT INTO "Document2" (title, owner_id)
VALUES ('Raven', (select id FROM "User" LIMIT 1))
'''
)
self.assertEqual(res, 'INSERT 0 1')
res = await self.squery_values(
'''
SELECT title FROM "Document2"
'''
)
self.assertEqual(res, [['Raven']]) | )
res = await self.scon.execute(
f | test_sql_dml_insert_40 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_42(self):
await self.scon.execute("SET LOCAL allow_user_specified_id TO TRUE")
uuid1 = uuid.uuid4()
uuid2 = uuid.uuid4()
res = await self.scon.execute(
f'''
WITH
u1 as (
INSERT INTO "User" DEFAULT VALUES RETURNING id, 'hello' as x
),
u2 as (
INSERT INTO "User" (id) VALUES ($1), ($2)
RETURNING id, 'world' as y
)
INSERT INTO "Document" (owner_id, title)
VALUES
((SELECT id FROM u1), (SELECT x FROM u1)),
((SELECT id FROM u2 LIMIT 1), (SELECT y FROM u2 LIMIT 1)),
(
(SELECT id FROM u2 OFFSET 1 LIMIT 1),
(SELECT y FROM u2 OFFSET 1 LIMIT 1)
)
''',
uuid1,
uuid2,
)
self.assertEqual(res, 'INSERT 0 3')
res = await self.squery_values(
'''
SELECT title, owner_id FROM "Document"
'''
)
res[0][1] = None # first uuid is generated and unknown at this stage
self.assertEqual(
res,
[
['hello (new)', None],
['world (new)', uuid1],
['world (new)', uuid2],
],
) | ,
uuid1,
uuid2,
)
self.assertEqual(res, 'INSERT 0 3')
res = await self.squery_values( | test_sql_dml_insert_42 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_43(self):
await self.scon.execute("SET LOCAL allow_user_specified_id TO TRUE")
doc_id = uuid.uuid4()
user_id = uuid.uuid4()
res = await self.scon.execute(
'''
WITH
d AS (INSERT INTO "Document" (id) VALUES ($1)),
u AS (INSERT INTO "User" (id) VALUES ($2)),
dsw AS (
INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2)
)
INSERT INTO "Document.keywords" VALUES ($1, 'top-priority')
''',
doc_id,
user_id,
)
self.assertEqual(res, 'INSERT 0 1')
res = await self.squery_values(
'''
SELECT source, target FROM "Document.shared_with"
'''
)
self.assertEqual(res, [[doc_id, user_id]]) | WITH
d AS (INSERT INTO "Document" (id) VALUES ($1)),
u AS (INSERT INTO "User" (id) VALUES ($2)),
dsw AS (
INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2)
)
INSERT INTO "Document.keywords" VALUES ($1, 'top-priority')
''',
doc_id,
user_id,
)
self.assertEqual(res, 'INSERT 0 1')
res = await self.squery_values( | test_sql_dml_insert_43 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_44(self):
# Test that RETURNING supports "Table".col format
res = await self.squery_values(
'''
INSERT INTO "Document" (title) VALUES ('Test returning')
RETURNING "Document".id
'''
)
docid = res[0][0]
res = await self.squery_values('SELECT id, title FROM "Document"')
self.assertEqual(res, [[docid, 'Test returning (new)']]) | INSERT INTO "Document" (title) VALUES ('Test returning')
RETURNING "Document".id | test_sql_dml_insert_44 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_insert_45(self):
# Test that properties ending in _id work.
res = await self.scon.execute(
'''
INSERT INTO "Numbered" (num_id) VALUES (10)
'''
)
res = await self.squery_values('SELECT num_id FROM "Numbered"')
self.assertEqual(res, [[10]]) | INSERT INTO "Numbered" (num_id) VALUES (10) | test_sql_dml_insert_45 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_01(self):
# delete, inspect CommandComplete tag
await self.scon.execute(
'''
INSERT INTO "Document" (title)
VALUES ('Report'), ('Report'), ('Briefing')
'''
)
res = await self.scon.execute(
'''
DELETE FROM "Document"
WHERE title = 'Report (new)'
''',
)
self.assertEqual(res, 'DELETE 2') | INSERT INTO "Document" (title)
VALUES ('Report'), ('Report'), ('Briefing') | test_sql_dml_delete_01 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_04(self):
# delete with using clause
users = await self.squery_values(
'''
INSERT INTO "User" (id) VALUES (DEFAULT), (DEFAULT) RETURNING id
'''
)
await self.squery_values(
'''
WITH u(id) as (VALUES ($1), ($2))
INSERT INTO "Document" (title, owner_id)
SELECT 'Report', u.id FROM u
RETURNING title, owner_id
''',
str(users[0][0]),
str(users[1][0]),
)
res = await self.squery_values(
'''
DELETE FROM "Document"
USING "User" u
WHERE "Document".owner_id = u.id AND title = 'Report (new)'
RETURNING title, owner_id
''',
)
self.assertEqual(
res,
[
['Report (new)', res[0][1]],
['Report (new)', res[1][1]],
],
) | INSERT INTO "User" (id) VALUES (DEFAULT), (DEFAULT) RETURNING id | test_sql_dml_delete_04 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_06(self):
# delete returning *
await self.scon.execute(
'''
INSERT INTO "Document" (title) VALUES ('Report')
'''
)
res = await self.squery_values(
'''
DELETE FROM "Document" RETURNING *
''',
)
self.assertEqual(res, [[res[0][0], res[0][1], None, 'Report (new)']])
self.assertIsInstance(res[0][0], uuid.UUID)
self.assertIsInstance(res[0][1], uuid.UUID) | INSERT INTO "Document" (title) VALUES ('Report') | test_sql_dml_delete_06 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_07(self):
# delete with CTEs
await self.scon.execute(
'''
INSERT INTO "User" DEFAULT VALUES
'''
)
await self.scon.execute(
'''
INSERT INTO "Document" (title, owner_id)
VALUES
('Report', NULL),
('Briefing', (SELECT id FROM "User" LIMIT 1))
'''
)
res = await self.squery_values(
'''
WITH
users as (SELECT id FROM "User"),
not_owned as (
SELECT d.id
FROM "Document" d
LEFT JOIN users u ON d.owner_id = u.id
WHERE u.id IS NULL
)
DELETE FROM "Document"
USING not_owned
WHERE not_owned.id = "Document".id
RETURNING title
''',
)
self.assertEqual(res, [['Report (new)']]) | INSERT INTO "User" DEFAULT VALUES | test_sql_dml_delete_07 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_08(self):
[document] = await self.squery_values(
'INSERT INTO "Document" DEFAULT VALUES RETURNING id'
)
[user1] = await self.squery_values(
'INSERT INTO "User" DEFAULT VALUES RETURNING id'
)
[user2] = await self.squery_values(
'INSERT INTO "User" DEFAULT VALUES RETURNING id'
)
await self.scon.execute(
'''
INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2), ($1, $3)
''',
document[0],
user1[0],
user2[0],
)
# delete where false
res = await self.scon.execute(
'''
DELETE FROM "Document.shared_with" WHERE FALSE
''',
)
self.assertEqual(res, 'DELETE 0')
res = await self.squery_values(
'''
SELECT COUNT(*) FROM "Document.shared_with"
''',
)
self.assertEqual(res, [[2]])
# delete where source
res = await self.scon.execute(
'''
DELETE FROM "Document.shared_with" WHERE source = $1
''',
document[0],
)
self.assertEqual(res, 'DELETE 2')
await self.scon.execute(
'''
INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2), ($1, $3)
''',
document[0],
user1[0],
user2[0],
)
# delete where target
res = await self.scon.execute(
'''
DELETE FROM "Document.shared_with" WHERE target = $1
''',
user1[0],
)
self.assertEqual(res, 'DELETE 1')
await self.scon.execute(
'''
INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2), ($1, $3)
''',
document[0],
user1[0],
user2[0],
)
# delete all
res = await self.scon.execute(
'''
DELETE FROM "Document.shared_with"
'''
)
self.assertEqual(res, 'DELETE 2') | INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2), ($1, $3)
''',
document[0],
user1[0],
user2[0],
)
# delete where false
res = await self.scon.execute( | test_sql_dml_delete_08 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_09(self):
# delete with returning clause and using and CTEs
[document] = await self.squery_values(
'INSERT INTO "Document" DEFAULT VALUES RETURNING id'
)
[user1] = await self.squery_values(
'INSERT INTO "User" DEFAULT VALUES RETURNING id'
)
[user2] = await self.squery_values(
'INSERT INTO "User" DEFAULT VALUES RETURNING id'
)
await self.squery_values(
'''
INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2), ($1, $3)
''',
document[0],
user1[0],
user2[0],
)
deleted = await self.squery_values(
'''
WITH
users_to_keep as (SELECT id FROM "User" WHERE id = $1),
users_to_delete as (
SELECT u.id
FROM "User" u
LEFT JOIN users_to_keep utk ON (u.id = utk.id)
WHERE utk.id IS NULL
)
DELETE FROM "Document.shared_with" dsw
USING users_to_delete utd
WHERE utd.id = dsw.target
RETURNING source, target
''',
user2[0],
)
self.assertEqual(deleted, [[document[0], user1[0]]]) | INSERT INTO "Document.shared_with" (source, target)
VALUES ($1, $2), ($1, $3)
''',
document[0],
user1[0],
user2[0],
)
deleted = await self.squery_values( | test_sql_dml_delete_09 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_10(self):
# delete from a single link table
[user1] = await self.squery_values(
'INSERT INTO "User" DEFAULT VALUES RETURNING id'
)
[user2] = await self.squery_values(
'INSERT INTO "User" DEFAULT VALUES RETURNING id'
)
[doc1, _doc2] = await self.squery_values(
'''
INSERT INTO "Document" (owner_id) VALUES ($1), ($2) RETURNING id
''',
user1[0],
user2[0],
)
deleted = await self.squery_values(
'''
DELETE FROM "Document.owner"
WHERE source = $1
RETURNING source, target, is_author
''',
doc1[0],
)
self.assertEqual(deleted, [[doc1[0], user1[0], None]]) | INSERT INTO "Document" (owner_id) VALUES ($1), ($2) RETURNING id
''',
user1[0],
user2[0],
)
deleted = await self.squery_values( | test_sql_dml_delete_10 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_12(self):
# Create a new document and try to delete it immediately.
# This will not delete the document, since DELETE statement cannot "see"
# the document that has just been inserted (this is Postgres behavior).
res = await self.scon.execute(
'''
WITH inserted as (
INSERT INTO "Document" (title) VALUES ('Report') RETURNING id
)
DELETE FROM "Document" d USING inserted WHERE d.id = inserted.id
'''
)
self.assertEqual(res, 'DELETE 0')
res = await self.squery_values(
'SELECT COUNT(*) FROM "Document"',
)
self.assertEqual(res, [[1]]) | WITH inserted as (
INSERT INTO "Document" (title) VALUES ('Report') RETURNING id
)
DELETE FROM "Document" d USING inserted WHERE d.id = inserted.id | test_sql_dml_delete_12 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_13(self):
[[doc_id, user_id]] = await self.squery_values(
'''
WITH
d AS (INSERT INTO "Document" DEFAULT VALUES RETURNING id),
u AS (INSERT INTO "User" DEFAULT VALUES RETURNING id)
INSERT INTO "Document.shared_with" (source, target)
VALUES ((SELECT id FROM d), (SELECT id FROM u))
RETURNING source, target
'''
)
res = await self.scon.execute(
'''
WITH
inserted(s, t) AS (VALUES ($1::uuid, $2::uuid))
DELETE FROM "Document.shared_with" dsw
USING inserted
WHERE dsw.source = inserted.s AND dsw.target = inserted.t
''',
doc_id,
user_id,
)
self.assertEqual(res, 'DELETE 1') | WITH
d AS (INSERT INTO "Document" DEFAULT VALUES RETURNING id),
u AS (INSERT INTO "User" DEFAULT VALUES RETURNING id)
INSERT INTO "Document.shared_with" (source, target)
VALUES ((SELECT id FROM d), (SELECT id FROM u))
RETURNING source, target | test_sql_dml_delete_13 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_delete_14(self):
# Test that RETURNING supports "Table".col format
await self.scon.execute(
'''
INSERT INTO "Document" (title)
VALUES ('Test returning')
'''
)
res = await self.squery_values(
'''
DELETE FROM "Document"
WHERE title LIKE 'Test returning%'
RETURNING "Document".title
''',
)
self.assertEqual(res, [['Test returning (new)']]) | INSERT INTO "Document" (title)
VALUES ('Test returning') | test_sql_dml_delete_14 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_update_08(self):
# update with a trivial multi-ref
[user] = await self.squery_values(
'''
INSERT INTO "User" DEFAULT VALUES RETURNING id
'''
)
await self.scon.execute(
'''
INSERT INTO "Document" (title, owner_id)
VALUES (NULL, NULL)
'''
)
res = await self.squery_values(
'''
UPDATE "Document"
SET (title, owner_id) = ROW('hello', $1::uuid)
RETURNING title, owner_id
''',
user[0],
)
self.assertEqual(res, [['hello (updated)', user[0]]]) | INSERT INTO "User" DEFAULT VALUES RETURNING id | test_sql_dml_update_08 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_update_11(self):
# update set default
res = await self.squery_values(
'''
INSERT INTO "Post" (title, created_at)
VALUES (DEFAULT, DEFAULT)
RETURNING title, created_at
'''
)
self.assertEqual(res, [['untitled', None]])
res = await self.squery_values(
'''
UPDATE "Post" SET
title = 'Announcing EdgeDB 1.0',
created_at = '2024-08-08T08:08:08.000'::timestamp
RETURNING title, created_at::text
'''
)
self.assertEqual(
res, [['Announcing EdgeDB 1.0', '2024-08-08 08:08:08+00']]
)
res = await self.squery_values(
'''
UPDATE "Post" SET
title = DEFAULT,
created_at = DEFAULT
RETURNING title, created_at
'''
)
self.assertEqual(res, [['untitled', None]]) | INSERT INTO "Post" (title, created_at)
VALUES (DEFAULT, DEFAULT)
RETURNING title, created_at | test_sql_dml_update_11 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_update_13(self):
with self.assertRaisesRegex(
asyncpg.FeatureNotSupportedError,
'UPDATE of link tables is not supported',
):
await self.squery_values(
'''
UPDATE "Document.shared_with" SET can_edit = FALSE
'''
) | UPDATE "Document.shared_with" SET can_edit = FALSE | test_sql_dml_update_13 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_update_14(self):
# UPDATE will not match anything, because the inserted document is not
# yet "visible" during the UPDATE statement (this is Postgres behavior).
res = await self.scon.execute(
'''
WITH inserted as (
INSERT INTO "Document" (title) VALUES ('Report') RETURNING id
)
UPDATE "Document" d
SET title = 'Briefing'
FROM inserted
WHERE d.id = inserted.id
'''
)
self.assertEqual(res, 'UPDATE 0')
res = await self.squery_values(
'SELECT title FROM "Document" ORDER BY title',
)
self.assertEqual(res, [['Report (new)']])
# Now we remove UPDATE condition and expect all documents that existed
# *before* this statement to be updated.
res = await self.scon.execute(
'''
WITH inserted as (
INSERT INTO "Document" (title) VALUES ('Receipt') RETURNING id
)
UPDATE "Document" d
SET title = 'Briefing'
'''
)
self.assertEqual(res, 'UPDATE 1')
res = await self.squery_values(
'SELECT title FROM "Document" ORDER BY title',
)
self.assertEqual(res, [['Briefing (updated)'], ['Receipt (new)']]) | WITH inserted as (
INSERT INTO "Document" (title) VALUES ('Report') RETURNING id
)
UPDATE "Document" d
SET title = 'Briefing'
FROM inserted
WHERE d.id = inserted.id | test_sql_dml_update_14 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_update_14a(self):
await self.squery_values(
'INSERT INTO "Document" DEFAULT VALUES',
)
res = await self.scon.execute(
'''
WITH
u AS (INSERT INTO "User" DEFAULT VALUES RETURNING id)
UPDATE "Document" SET owner_id = (SELECT id FROM u)
'''
)
self.assertEqual(res, 'UPDATE 1')
res = await self.squery_values(
'SELECT owner_id IS NULL FROM "Document"',
)
self.assertEqual(res, [[False]]) | WITH
u AS (INSERT INTO "User" DEFAULT VALUES RETURNING id)
UPDATE "Document" SET owner_id = (SELECT id FROM u) | test_sql_dml_update_14a | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_update_15(self):
[[doc_id]] = await self.squery_values(
'''
INSERT INTO "Document" (title) VALUES ('Briefing') RETURNING id
'''
)
res = await self.scon.execute(
'''
WITH updated as (
UPDATE "Document" d
SET title = 'Report'
WHERE d.id = $1
RETURNING id, title
)
INSERT INTO "Document" (title)
SELECT 'X' || id::uuid || ',' || title FROM updated
''',
doc_id,
)
self.assertEqual(res, 'INSERT 0 1')
res = await self.squery_values(
'SELECT id, title FROM "Document" ORDER BY title',
)
self.assertEqual(len(res), 2)
existing_id, existing_title = res[0]
_inserted_id, inserted_title = res[1]
self.assertEqual(existing_title, 'Report (updated)')
self.assertEqual(
inserted_title,
'X' + str(existing_id) + ',' + existing_title + ' (new)',
) | INSERT INTO "Document" (title) VALUES ('Briefing') RETURNING id | test_sql_dml_update_15 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_update_16(self):
[[doc_id]] = await self.squery_values(
'INSERT INTO "Document" DEFAULT VALUES RETURNING id'
)
res = await self.squery_values(
'''
WITH
u1 as (
INSERT INTO "User" DEFAULT VALUES RETURNING id
)
UPDATE "Document" SET owner_id = u1.id
FROM u1
RETURNING id, owner_id
'''
)
user_id = res[0][1]
self.assertEqual(
res,
[
[doc_id, user_id],
],
)
res = await self.squery_values(
'''
SELECT id, owner_id FROM "Document"
'''
)
self.assertEqual(
res,
[
[doc_id, user_id],
],
) | WITH
u1 as (
INSERT INTO "User" DEFAULT VALUES RETURNING id
)
UPDATE "Document" SET owner_id = u1.id
FROM u1
RETURNING id, owner_id | test_sql_dml_update_16 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_update_17(self):
# Test that RETURNING supports "Table".col format
await self.scon.execute(
'''
INSERT INTO "Document" (title)
VALUES ('Report')
'''
)
res = await self.squery_values(
'''
UPDATE "Document"
SET title = 'Test returning'
WHERE title LIKE 'Report%'
RETURNING "Document".title
''',
)
self.assertEqual(res, [['Test returning (updated)']]) | INSERT INTO "Document" (title)
VALUES ('Report') | test_sql_dml_update_17 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_01(self):
# update/delete only
await self.scon.execute(
'''
INSERT INTO "Base" (prop) VALUES ('base')
'''
)
await self.scon.execute(
'''
INSERT INTO "Child" (prop) VALUES ('child')
'''
)
res = await self.squery_values('SELECT prop FROM "Base" ORDER BY prop')
self.assertEqual(res, [['base'], ['child']])
res = await self.squery_values('SELECT prop FROM ONLY "Base"')
self.assertEqual(res, [['base']])
res = await self.squery_values('SELECT prop FROM "Child"')
self.assertEqual(res, [['child']])
await self.scon.execute(
'''
UPDATE ONLY "Base" SET prop = 'a'
'''
)
res = await self.squery_values('SELECT prop FROM "Base" ORDER BY prop')
self.assertEqual(res, [['a'], ['child']])
await self.scon.execute(
'''
DELETE FROM ONLY "Base"
'''
)
res = await self.squery_values('SELECT prop FROM "Base" ORDER BY prop')
self.assertEqual(res, [['child']]) | INSERT INTO "Base" (prop) VALUES ('base') | test_sql_dml_01 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
async def test_sql_dml_02(self):
# globals
await self.scon.execute(
'''
INSERT INTO "Globals" DEFAULT VALUES
'''
)
await self.scon.execute(
"""
SET LOCAL "global default::y" TO 'Hello world!';
"""
)
await self.scon.execute(
'''
INSERT INTO "Globals" DEFAULT VALUES
'''
)
res = await self.squery_values('SELECT gy FROM "Globals" ORDER BY gy')
self.assertEqual(res, [['Hello world!'], [None]]) | INSERT INTO "Globals" DEFAULT VALUES | test_sql_dml_02 | python | geldata/gel | tests/test_sql_dml.py | https://github.com/geldata/gel/blob/master/tests/test_sql_dml.py | Apache-2.0 |
def test_schema_overloaded_prop_01(self):
"""
type UniqueName {
property name -> str {
constraint exclusive
}
};
type UniqueName_2 extending UniqueName {
overloaded property name -> str {
constraint exclusive
}
};
""" | type UniqueName {
property name -> str {
constraint exclusive
}
};
type UniqueName_2 extending UniqueName {
overloaded property name -> str {
constraint exclusive
}
}; | test_schema_overloaded_prop_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_02(self):
"""
type UniqueName {
property name -> str {
constraint exclusive
}
};
type UniqueName_2 extending UniqueName {
property name -> str {
constraint exclusive
}
};
""" | type UniqueName {
property name -> str {
constraint exclusive
}
};
type UniqueName_2 extending UniqueName {
property name -> str {
constraint exclusive
}
}; | test_schema_overloaded_prop_02 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_03(self):
"""
type UniqueName {
overloaded property name -> str
};
""" | type UniqueName {
overloaded property name -> str
}; | test_schema_overloaded_prop_03 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_04(self):
"""
type UniqueName {
property val -> str {
constraint exclusive;
}
};
type UniqueName_2 extending UniqueName {
overloaded property val -> str {
using ('bad');
}
};
""" | type UniqueName {
property val -> str {
constraint exclusive;
}
};
type UniqueName_2 extending UniqueName {
overloaded property val -> str {
using ('bad');
}
}; | test_schema_overloaded_prop_04 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_05(self):
"""
type UniqueName {
property val := 'ok';
};
type UniqueName_2 extending UniqueName {
# This doesn't appear to be a computable property, but
# it is due to inheritance.
overloaded property val -> str {
constraint exclusive;
}
};
""" | type UniqueName {
property val := 'ok';
};
type UniqueName_2 extending UniqueName {
# This doesn't appear to be a computable property, but
# it is due to inheritance.
overloaded property val -> str {
constraint exclusive;
}
}; | test_schema_overloaded_prop_05 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_06(self):
"""
type UniqueName {
property val := 'ok';
};
type UniqueName_2 {
property val -> str;
};
type UniqueName_3 extending UniqueName, UniqueName_2;
""" | type UniqueName {
property val := 'ok';
};
type UniqueName_2 {
property val -> str;
};
type UniqueName_3 extending UniqueName, UniqueName_2; | test_schema_overloaded_prop_06 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_07(self):
"""
type UniqueName {
property val := 'ok';
};
type UniqueName_2 {
property val := 'ok';
};
# It's illegal to extend 2 computable properties even if
# the expression is the same for them.
type UniqueName_3 extending UniqueName, UniqueName_2;
""" | type UniqueName {
property val := 'ok';
};
type UniqueName_2 {
property val := 'ok';
};
# It's illegal to extend 2 computable properties even if
# the expression is the same for them.
type UniqueName_3 extending UniqueName, UniqueName_2; | test_schema_overloaded_prop_07 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_08(self):
"""
type UniqueName {
property val -> str;
};
type UniqueName_2 {
property val := 'ok';
};
type UniqueName_3 extending UniqueName_2;
type UniqueName_4 extending UniqueName, UniqueName_3;
""" | type UniqueName {
property val -> str;
};
type UniqueName_2 {
property val := 'ok';
};
type UniqueName_3 extending UniqueName_2;
type UniqueName_4 extending UniqueName, UniqueName_3; | test_schema_overloaded_prop_08 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_09(self):
# Overloading implicitly via a type UNION.
"""
type UniqueName {
property val -> str;
};
type UniqueName_2 {
property val := 'ok';
};
alias Combo := {UniqueName, UniqueName_2};
""" | type UniqueName {
property val -> str;
};
type UniqueName_2 {
property val := 'ok';
};
alias Combo := {UniqueName, UniqueName_2}; | test_schema_overloaded_prop_09 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_10(self):
# Overloading implicitly via a type UNION.
"""
type UniqueName {
property val -> str;
};
type UniqueName_2 {
property val := 'ok';
};
type Combo {
multi link comp := {UniqueName, UniqueName_2};
}
""" | type UniqueName {
property val -> str;
};
type UniqueName_2 {
property val := 'ok';
};
type Combo {
multi link comp := {UniqueName, UniqueName_2};
} | test_schema_overloaded_prop_10 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_prop_11(self):
"""
type UniqueName {
property name -> str;
};
type UniqueName_2 extending UniqueName {
overloaded property name -> bytes;
};
""" | type UniqueName {
property name -> str;
};
type UniqueName_2 extending UniqueName {
overloaded property name -> bytes;
}; | test_schema_overloaded_prop_11 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_link_01(self):
"""
type Foo;
type UniqueName {
link foo -> Foo;
};
type UniqueName_2 extending UniqueName {
overloaded link foo -> Foo {
using (SELECT Foo LIMIT 1);
}
};
""" | type Foo;
type UniqueName {
link foo -> Foo;
};
type UniqueName_2 extending UniqueName {
overloaded link foo -> Foo {
using (SELECT Foo LIMIT 1);
}
}; | test_schema_overloaded_link_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_link_02(self):
"""
type Foo;
type UniqueName {
link foo := (SELECT Foo LIMIT 1);
};
type UniqueName_2 extending UniqueName {
# This doesn't appear to be a computable link, but
# it is due to inheritance.
overloaded link foo -> Foo {
constraint exclusive;
}
};
""" | type Foo;
type UniqueName {
link foo := (SELECT Foo LIMIT 1);
};
type UniqueName_2 extending UniqueName {
# This doesn't appear to be a computable link, but
# it is due to inheritance.
overloaded link foo -> Foo {
constraint exclusive;
}
}; | test_schema_overloaded_link_02 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_link_03(self):
"""
type Foo;
type UniqueName {
link foo := (SELECT Foo LIMIT 1);
};
type UniqueName_2 {
link foo -> Foo;
};
type UniqueName_3 extending UniqueName, UniqueName_2;
""" | type Foo;
type UniqueName {
link foo := (SELECT Foo LIMIT 1);
};
type UniqueName_2 {
link foo -> Foo;
};
type UniqueName_3 extending UniqueName, UniqueName_2; | test_schema_overloaded_link_03 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_overloaded_link_04(self):
"""
type Foo;
type UniqueName {
link foo := (SELECT Foo LIMIT 1);
};
type UniqueName_2 {
link foo := (SELECT Foo LIMIT 1);
};
# It's illegal to extend 2 computable links even if
# the expression is the same for them.
type UniqueName_3 extending UniqueName, UniqueName_2;
""" | type Foo;
type UniqueName {
link foo := (SELECT Foo LIMIT 1);
};
type UniqueName_2 {
link foo := (SELECT Foo LIMIT 1);
};
# It's illegal to extend 2 computable links even if
# the expression is the same for them.
type UniqueName_3 extending UniqueName, UniqueName_2; | test_schema_overloaded_link_04 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_index_computed_01(self):
"""
type SignatureStatus {
required property signature -> str;
link memo := (
select Memo filter .signature = SignatureStatus.signature limit 1);
index on (.memo);
}
type Memo {
required property signature -> str {
constraint exclusive;
}
}
""" | type SignatureStatus {
required property signature -> str;
link memo := (
select Memo filter .signature = SignatureStatus.signature limit 1);
index on (.memo);
}
type Memo {
required property signature -> str {
constraint exclusive;
}
} | test_schema_index_computed_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_index_computed_02(self):
"""
type SignatureStatus {
required property signature -> str;
link memo := (
select Memo filter .signature = SignatureStatus.signature limit 1);
index on (__subject__ { lol := .memo }.lol);
}
type Memo {
required property signature -> str {
constraint exclusive;
}
}
""" | type SignatureStatus {
required property signature -> str;
link memo := (
select Memo filter .signature = SignatureStatus.signature limit 1);
index on (__subject__ { lol := .memo }.lol);
}
type Memo {
required property signature -> str {
constraint exclusive;
}
} | test_schema_index_computed_02 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_index_computed_03(self):
"""
type SignatureStatus {
required property signature -> str;
link memo_: Memo;
link memo := .memo_;
index on (.memo);
}
type Memo {
required property signature -> str {
constraint exclusive;
}
}
""" | type SignatureStatus {
required property signature -> str;
link memo_: Memo;
link memo := .memo_;
index on (.memo);
}
type Memo {
required property signature -> str {
constraint exclusive;
}
} | test_schema_index_computed_03 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_link_01(self):
"""
type Object {
link foo -> str
};
""" | type Object {
link foo -> str
}; | test_schema_bad_link_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_link_02(self):
"""
type Object {
link foo := 1 + 1
};
""" | type Object {
link foo := 1 + 1
}; | test_schema_bad_link_02 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_link_03(self):
"""
type Object {
link foo -> FreeObject
};
""" | type Object {
link foo -> FreeObject
}; | test_schema_bad_link_03 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_link_04(self):
"""
type Object {
property foo -> str;
link bar := .foo;
};
""" | type Object {
property foo -> str;
link bar := .foo;
}; | test_schema_bad_link_04 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_link_05(self):
"""
type A;
type Foo {
required link foo -> A {
on target delete deferred restrict;
}
};
""" | type A;
type Foo {
required link foo -> A {
on target delete deferred restrict;
}
}; | test_schema_bad_link_05 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_link_06(self):
"""
abstract link abs { property foo: str };
type T { multi link following extending abs -> T {using (T)} }
""" | abstract link abs { property foo: str };
type T { multi link following extending abs -> T {using (T)} } | test_schema_bad_link_06 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_link_prop_on_prop_01(self):
"""
type Test1 {
title : str {
sub_title : str
}
};
""" | type Test1 {
title : str {
sub_title : str
}
}; | test_schema_link_prop_on_prop_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_deletion_policy_on_prop_01(self):
"""
type Test1 {
title : str {
on source delete allow;
}
};
""" | type Test1 {
title : str {
on source delete allow;
}
}; | test_schema_deletion_policy_on_prop_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_deletion_policy_on_prop_02(self):
"""
type Test1 {
title : str {
on target delete restrict;
}
};
""" | type Test1 {
title : str {
on target delete restrict;
}
}; | test_schema_deletion_policy_on_prop_02 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_partial_path_in_default_of_link_prop_01(self):
"""
module default {
type Person {
required name: str {
constraint exclusive;
}
multi friends : Person {
note: str {
default := .name
}
}
}
}
""" | module default {
type Person {
required name: str {
constraint exclusive;
}
multi friends : Person {
note: str {
default := .name
}
}
}
} | test_schema_partial_path_in_default_of_link_prop_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_partial_path_in_trigger_01(self):
"""
type Foo {
property wow: bool;
trigger prohibit_queue after insert for each do (
select assert(.wow, message := "wow!")
);
}
""" | type Foo {
property wow: bool;
trigger prohibit_queue after insert for each do (
select assert(.wow, message := "wow!")
);
} | test_schema_partial_path_in_trigger_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_prop_01(self):
"""
type Object {
property foo -> Object
};
""" | type Object {
property foo -> Object
}; | test_schema_bad_prop_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_prop_02(self):
"""
type Object {
property foo := (SELECT Object)
};
""" | type Object {
property foo := (SELECT Object)
}; | test_schema_bad_prop_02 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_prop_04(self):
"""
abstract property foo extending bar;
""" | abstract property foo extending bar; | test_schema_bad_prop_04 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_prop_05(self):
"""
abstract link foo extending bar;
""" | abstract link foo extending bar; | test_schema_bad_prop_05 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_prop_06(self):
"""
abstract link foo extending foo;
""" | abstract link foo extending foo; | test_schema_bad_prop_06 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_prop_07(self):
"""
type Person {
required property name := str {
# empty block
}
}
""" | type Person {
required property name := str {
# empty block
}
} | test_schema_bad_prop_07 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_01(self):
"""
type Object {
property foo -> int
};
""" | type Object {
property foo -> int
}; | test_schema_bad_type_01 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_02(self):
"""
type Foo;
type Base {
property foo -> array<Foo>;
}
""" | type Foo;
type Base {
property foo -> array<Foo>;
} | test_schema_bad_type_02 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_03(self):
"""
type Foo;
type Base {
property foo -> tuple<Foo>;
}
""" | type Foo;
type Base {
property foo -> tuple<Foo>;
} | test_schema_bad_type_03 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_04(self):
"""
type Foo;
type Base {
property foo -> tuple<str, array<Foo>>;
}
""" | type Foo;
type Base {
property foo -> tuple<str, array<Foo>>;
} | test_schema_bad_type_04 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_05(self):
"""
type Foo extending Bar;
""" | type Foo extending Bar; | test_schema_bad_type_05 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_06(self):
"""
type Foo {
link val -> Bar;
};
""" | type Foo {
link val -> Bar;
}; | test_schema_bad_type_06 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_07(self):
"""
type Foo {
annotation bar := 'Bogus';
};
""" | type Foo {
annotation bar := 'Bogus';
}; | test_schema_bad_type_07 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_08(self):
"""
type Foo {
property val -> str {
constraint bogus(5);
}
};
""" | type Foo {
property val -> str {
constraint bogus(5);
}
}; | test_schema_bad_type_08 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_09(self):
"""
type Foo extending Foo;
""" | type Foo extending Foo; | test_schema_bad_type_09 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_10(self):
"""
type Foo0 extending Foo1;
type Foo1 extending Foo2;
type Foo2 extending Foo3;
type Foo3 extending Foo0;
""" | type Foo0 extending Foo1;
type Foo1 extending Foo2;
type Foo2 extending Foo3;
type Foo3 extending Foo0; | test_schema_bad_type_10 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_11(self):
"""
type Foo;
type Bar;
type Spam {
multi link foobar := Foo[IS Bar];
}
""" | type Foo;
type Bar;
type Spam {
multi link foobar := Foo[IS Bar];
} | test_schema_bad_type_11 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_12(self):
"""
type Foo {
property val -> anytype;
}
""" | type Foo {
property val -> anytype;
} | test_schema_bad_type_12 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_13(self):
"""
type Foo {
link val -> anytype;
}
""" | type Foo {
link val -> anytype;
} | test_schema_bad_type_13 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_14(self):
"""
type Foo {
property val -> anytuple;
}
""" | type Foo {
property val -> anytuple;
} | test_schema_bad_type_14 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_15(self):
"""
scalar type Foo;
""" | scalar type Foo; | test_schema_bad_type_15 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_16(self):
"""
type Foo {
property val -> str;
index on (.val);
index on (.val);
};
""" | type Foo {
property val -> str;
index on (.val);
index on (.val);
}; | test_schema_bad_type_16 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_17a(self):
"""
type Foo {
property val -> str;
index fts::index on (
fts::with_options(.val, language := fts::Language.eng)
);
index fts::index on (
fts::with_options(.val, language := fts::Language.ita)
);
index fts::index on (
fts::with_options(.val, language := fts::Language.eng)
);
};
""" | type Foo {
property val -> str;
index fts::index on (
fts::with_options(.val, language := fts::Language.eng)
);
index fts::index on (
fts::with_options(.val, language := fts::Language.ita)
);
index fts::index on (
fts::with_options(.val, language := fts::Language.eng)
);
}; | test_schema_bad_type_17a | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_17b(self):
"""
type Foo {
property val -> str;
index fts::index on (
fts::with_options(.val, language := fts::Language.eng)
);
index fts::index on (
fts::with_options(.val, language := fts::Language.ita)
);
};
""" | type Foo {
property val -> str;
index fts::index on (
fts::with_options(.val, language := fts::Language.eng)
);
index fts::index on (
fts::with_options(.val, language := fts::Language.ita)
);
}; | test_schema_bad_type_17b | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_18(self):
"""
type Foo {
property val -> enum<VariantA, VariantB>;
};
""" | type Foo {
property val -> enum<VariantA, VariantB>;
}; | test_schema_bad_type_18 | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_19a(self):
"""
function foo() -> Bar using (1);
""" | function foo() -> Bar using (1); | test_schema_bad_type_19a | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
def test_schema_bad_type_19b(self):
"""
function foo(x: Bar) -> int64 using (1);
""" | function foo(x: Bar) -> int64 using (1); | test_schema_bad_type_19b | python | geldata/gel | tests/test_schema.py | https://github.com/geldata/gel/blob/master/tests/test_schema.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.