Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3414a32bd6 | |||
| 06432cf0f5 | |||
| 0d4b7c3dec | |||
| b2f9fe387c | |||
| 020286d603 | |||
| 1619ca4400 |
@ -1027,16 +1027,31 @@
|
||||
"name": "user",
|
||||
"module": "test",
|
||||
"source": "test",
|
||||
"hierarchy": ["user"],
|
||||
"variations": ["user"],
|
||||
"fields": ["id", "email"],
|
||||
"lookup_fields": ["email"],
|
||||
"hierarchy": [
|
||||
"user"
|
||||
],
|
||||
"variations": [
|
||||
"user"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
"email"
|
||||
],
|
||||
"lookup_fields": [
|
||||
"email"
|
||||
],
|
||||
"schemas": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": { "type": "string", "format": "uuid" },
|
||||
"email": { "type": "string", "format": "email" }
|
||||
"id": {
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
},
|
||||
"email": {
|
||||
"type": "string",
|
||||
"format": "email"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1072,7 +1087,9 @@
|
||||
"indexes": [
|
||||
{
|
||||
"table": "user",
|
||||
"columns": ["email"]
|
||||
"columns": [
|
||||
"email"
|
||||
]
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
@ -1082,16 +1099,31 @@
|
||||
"name": "user",
|
||||
"module": "test",
|
||||
"source": "test",
|
||||
"hierarchy": ["user"],
|
||||
"variations": ["user"],
|
||||
"fields": ["id", "email"],
|
||||
"lookup_fields": ["email"],
|
||||
"hierarchy": [
|
||||
"user"
|
||||
],
|
||||
"variations": [
|
||||
"user"
|
||||
],
|
||||
"fields": [
|
||||
"id",
|
||||
"email"
|
||||
],
|
||||
"lookup_fields": [
|
||||
"email"
|
||||
],
|
||||
"schemas": {
|
||||
"user": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": { "type": "string", "format": "uuid" },
|
||||
"email": { "type": "string", "format": "email" }
|
||||
"id": {
|
||||
"type": "string",
|
||||
"format": "uuid"
|
||||
},
|
||||
"email": {
|
||||
"type": "string",
|
||||
"format": "email"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,11 +120,18 @@
|
||||
"indexes": [
|
||||
{
|
||||
"table": "person",
|
||||
"columns": ["first_name", "last_name", "date_of_birth", "pronouns"]
|
||||
"columns": [
|
||||
"first_name",
|
||||
"last_name",
|
||||
"date_of_birth",
|
||||
"pronouns"
|
||||
]
|
||||
},
|
||||
{
|
||||
"table": "user",
|
||||
"columns": ["name"]
|
||||
"columns": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
],
|
||||
"types": [
|
||||
@ -1206,7 +1213,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -1216,7 +1224,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -1226,7 +1235,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -1240,7 +1250,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'IncompleteLast',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1316,7 +1327,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
@ -1343,7 +1354,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -1353,7 +1365,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -1363,7 +1376,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -1383,7 +1397,8 @@
|
||||
" 'LookupLast',",
|
||||
" 'they/them',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1469,14 +1484,14 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
"LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.id}}'",
|
||||
"UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"UNION SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
@ -1503,7 +1518,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -1513,7 +1529,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -1523,7 +1540,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -1543,7 +1561,8 @@
|
||||
" 'LookupLast',",
|
||||
" 'they/them',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1631,14 +1650,14 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
"LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.id}}'",
|
||||
"UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"UNION SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
@ -1648,7 +1667,7 @@
|
||||
" AND \"last_name\" = 'LookupLast'",
|
||||
" AND \"date_of_birth\" = '{{timestamp}}'",
|
||||
" AND \"pronouns\" = 'they/them')",
|
||||
"UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"UNION SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
@ -1672,7 +1691,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -1684,7 +1704,8 @@
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'LookupName',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -1694,7 +1715,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -1714,7 +1736,8 @@
|
||||
" 'LookupLast',",
|
||||
" 'they/them',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1802,14 +1825,14 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
"LEFT JOIN agreego.\"person\" t4 ON t4.id = t1.id",
|
||||
"WHERE",
|
||||
" t1.id = '{{uuid:data.id}}'",
|
||||
"UNION SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"UNION SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
@ -1836,7 +1859,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -1846,7 +1870,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -1856,7 +1881,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:data.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -1874,7 +1900,8 @@
|
||||
" 'LookupLast',",
|
||||
" 'they/them',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -1951,7 +1978,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
@ -1975,7 +2002,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -1985,7 +2013,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -1995,7 +2024,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -2009,7 +2039,8 @@
|
||||
" '{{uuid:mocks.0.id}}',",
|
||||
" 'NewLast',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2074,7 +2105,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
@ -2098,7 +2129,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -2108,7 +2140,8 @@
|
||||
"VALUES (",
|
||||
" '123',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -2118,7 +2151,8 @@
|
||||
"VALUES (",
|
||||
" '123',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -2136,7 +2170,8 @@
|
||||
" 'Doe',",
|
||||
" NULL,",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2226,7 +2261,8 @@
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" '{{uuid:generated_1}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -2236,7 +2272,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -2246,7 +2283,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -2262,7 +2300,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'Smith',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2306,7 +2345,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"order\" (",
|
||||
@ -2320,7 +2360,8 @@
|
||||
" '{{uuid:generated_3}}',",
|
||||
" 100,",
|
||||
" 'order'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"order\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2413,7 +2454,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"order\" t2 ON t2.id = t1.id",
|
||||
"WHERE",
|
||||
@ -2435,7 +2476,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"order\" (",
|
||||
@ -2447,7 +2489,8 @@
|
||||
" 'abc',",
|
||||
" 99,",
|
||||
" 'order'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"order\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
@ -2465,7 +2508,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"order_line\" (",
|
||||
@ -2481,7 +2525,8 @@
|
||||
" 99,",
|
||||
" 'Widget',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"order_line\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2630,7 +2675,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -2640,7 +2686,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -2650,7 +2697,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -2664,7 +2712,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'Test',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
@ -2682,7 +2731,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'phone_number'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"phone_number\" (",
|
||||
@ -2690,7 +2740,8 @@
|
||||
")",
|
||||
"VALUES (",
|
||||
" '555-0001'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"phone_number\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2731,7 +2782,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'contact'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"relationship\" (",
|
||||
@ -2745,7 +2797,8 @@
|
||||
" 'person',",
|
||||
" '{{uuid:generated_1}}',",
|
||||
" 'phone_number'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"relationship\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"contact\" (",
|
||||
@ -2753,7 +2806,8 @@
|
||||
")",
|
||||
"VALUES (",
|
||||
" true",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"contact\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2798,7 +2852,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'email_address'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"email_address\" (",
|
||||
@ -2806,7 +2861,8 @@
|
||||
")",
|
||||
"VALUES (",
|
||||
" 'test@example.com'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"email_address\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2847,7 +2903,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'contact'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"relationship\" (",
|
||||
@ -2861,7 +2918,8 @@
|
||||
" 'person',",
|
||||
" '{{uuid:generated_5}}',",
|
||||
" 'email_address'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"relationship\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"contact\" (",
|
||||
@ -2869,7 +2927,8 @@
|
||||
")",
|
||||
"VALUES (",
|
||||
" false",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"contact\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2914,7 +2973,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'email_address'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"email_address\" (",
|
||||
@ -2922,7 +2982,8 @@
|
||||
")",
|
||||
"VALUES (",
|
||||
" 'test2@example.com'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"email_address\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -2963,7 +3024,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'contact'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"relationship\" (",
|
||||
@ -2977,7 +3039,8 @@
|
||||
" 'person',",
|
||||
" '{{uuid:generated_9}}',",
|
||||
" 'email_address'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"relationship\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"contact\" (",
|
||||
@ -2985,7 +3048,8 @@
|
||||
")",
|
||||
"VALUES (",
|
||||
" false",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"contact\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -3215,7 +3279,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*) || to_jsonb(t3.*) || to_jsonb(t4.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}') || COALESCE(to_jsonb(t3.*), '{}') || COALESCE(to_jsonb(t4.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"organization\" t2 ON t2.id = t1.id",
|
||||
"LEFT JOIN agreego.\"user\" t3 ON t3.id = t1.id",
|
||||
@ -3241,7 +3305,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -3251,7 +3316,8 @@
|
||||
"VALUES (",
|
||||
" 'abc-archived',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -3261,7 +3327,8 @@
|
||||
"VALUES (",
|
||||
" 'abc-archived',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -3271,7 +3338,8 @@
|
||||
"VALUES (",
|
||||
" 'abc-archived',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -3353,7 +3421,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'attachment'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"attachment\" (",
|
||||
@ -3373,7 +3442,8 @@
|
||||
" '{",
|
||||
" \"type\": \"type_metadata\"",
|
||||
" }'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"attachment\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -3480,7 +3550,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"order_line\" (",
|
||||
@ -3496,7 +3567,8 @@
|
||||
" 99,",
|
||||
" 'Widget',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"order_line\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -3568,7 +3640,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"order_line\" t2 ON t2.id = t1.id",
|
||||
"WHERE",
|
||||
@ -3590,7 +3662,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"order_line\" (",
|
||||
@ -3606,7 +3679,8 @@
|
||||
" 99,",
|
||||
" 'Widget',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"order_line\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -3692,7 +3766,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"invoice\" t2 ON t2.id = t1.id",
|
||||
"WHERE",
|
||||
@ -3714,7 +3788,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'invoice'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"invoice\" (",
|
||||
@ -3746,7 +3821,8 @@
|
||||
" }',",
|
||||
" 200,",
|
||||
" 'invoice'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"invoice\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -3808,7 +3884,7 @@
|
||||
"success": true,
|
||||
"sql": [
|
||||
[
|
||||
"(SELECT to_jsonb(t1.*) || to_jsonb(t2.*)",
|
||||
"(SELECT COALESCE(to_jsonb(t1.*), '{}') || COALESCE(to_jsonb(t2.*), '{}')",
|
||||
"FROM agreego.\"entity\" t1",
|
||||
"LEFT JOIN agreego.\"account\" t2 ON t2.id = t1.id",
|
||||
"WHERE",
|
||||
@ -3830,7 +3906,8 @@
|
||||
" '{{timestamp}}',",
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'account'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"account\" (",
|
||||
@ -3844,7 +3921,8 @@
|
||||
" 'checking',",
|
||||
" '123456789',",
|
||||
" 'account'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"account\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -3936,7 +4014,8 @@
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" '{{uuid:generated_1}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"organization\" (",
|
||||
@ -3946,7 +4025,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"organization\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"user\" (",
|
||||
@ -3956,7 +4036,8 @@
|
||||
"VALUES (",
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"user\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"person\" (",
|
||||
@ -3970,7 +4051,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" 'Person',",
|
||||
" 'person'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"person\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -4015,7 +4097,8 @@
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'parent-org-id',",
|
||||
" 'order'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"order\" (",
|
||||
@ -4027,7 +4110,8 @@
|
||||
" '{{uuid:generated_0}}',",
|
||||
" '{{uuid:generated_3}}',",
|
||||
" 'order'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"order\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"entity\" (",
|
||||
@ -4047,7 +4131,8 @@
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'parent-org-id',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"order_line\" (",
|
||||
@ -4059,7 +4144,8 @@
|
||||
" '{{uuid:generated_4}}',",
|
||||
" '{{uuid:generated_3}}',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"order_line\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
@ -4103,7 +4189,8 @@
|
||||
" '00000000-0000-0000-0000-000000000000',",
|
||||
" 'explicit-org-id',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"entity\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.\"order_line\" (",
|
||||
@ -4115,7 +4202,8 @@
|
||||
" '{{uuid:generated_6}}',",
|
||||
" '{{uuid:generated_3}}',",
|
||||
" 'order_line'",
|
||||
")"
|
||||
")",
|
||||
"RETURNING to_jsonb(\"order_line\".*)"
|
||||
],
|
||||
[
|
||||
"INSERT INTO agreego.change (",
|
||||
|
||||
@ -1739,20 +1739,20 @@
|
||||
" AND entity_1.created_at <= ($16 #>> '{}')::TIMESTAMPTZ",
|
||||
" AND entity_1.created_at <> ($17 #>> '{}')::TIMESTAMPTZ",
|
||||
" AND person_3.first_name ILIKE $18 #>> '{}'",
|
||||
" AND person_3.first_name > ($19 #>> '{)",
|
||||
" AND person_3.first_name >= ($20 #>> '{)",
|
||||
" AND person_3.first_name < ($21 #>> '{)",
|
||||
" AND person_3.first_name <= ($22 #>> '{)",
|
||||
" AND person_3.first_name NOT ILIKE $23 #>> '{}'",
|
||||
" AND person_3.first_name NOT IN (SELECT value FROM jsonb_array_elements_text(($24 #>> '{}')::jsonb))",
|
||||
" AND person_3.first_name IN (SELECT value FROM jsonb_array_elements_text(($25 #>> '{}')::jsonb))",
|
||||
" AND entity_1.id = ($26 #>> '{}')::UUID",
|
||||
" AND entity_1.id <> ($27 #>> '{}')::UUID",
|
||||
" AND entity_1.id NOT IN (SELECT value::UUID FROM jsonb_array_elements_text(($28 #>> '{}')::jsonb))",
|
||||
" AND entity_1.id IN (SELECT value::UUID FROM jsonb_array_elements_text(($29 #>> '{}')::jsonb))",
|
||||
" AND person_3.last_name ILIKE $30 #>> '{}'",
|
||||
" AND person_3.last_name NOT ILIKE $31 #>> '{}'",
|
||||
" ))))"
|
||||
" AND person_3.first_name > ($19 #>> '{}')",
|
||||
" AND person_3.first_name >= ($20 #>> '{}')",
|
||||
" AND person_3.first_name < ($21 #>> '{}')",
|
||||
" AND person_3.first_name <= ($22 #>> '{}')",
|
||||
" AND person_3.first_name NOT ILIKE $23 #>> '{}'",
|
||||
" AND person_3.first_name NOT IN (SELECT value FROM jsonb_array_elements_text(($24 #>> '{}')::jsonb))",
|
||||
" AND person_3.first_name IN (SELECT value FROM jsonb_array_elements_text(($25 #>> '{}')::jsonb))",
|
||||
" AND entity_1.id = ($26 #>> '{}')::UUID",
|
||||
" AND entity_1.id <> ($27 #>> '{}')::UUID",
|
||||
" AND entity_1.id NOT IN (SELECT value::UUID FROM jsonb_array_elements_text(($28 #>> '{}')::jsonb))",
|
||||
" AND entity_1.id IN (SELECT value::UUID FROM jsonb_array_elements_text(($29 #>> '{}')::jsonb))",
|
||||
" AND person_3.last_name ILIKE $30 #>> '{}'",
|
||||
" AND person_3.last_name NOT ILIKE $31 #>> '{}'",
|
||||
"))))"
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
@ -57,7 +57,7 @@ pub fn jspg_setup(database: Json) -> Json {
|
||||
Json(serde_json::to_value(drop).unwrap())
|
||||
}
|
||||
|
||||
#[cfg_attr(not(test), pg_extern)]
|
||||
#[cfg_attr(not(test), pg_extern(volatile))]
|
||||
pub fn jspg_merge(schema_id: &str, data: JsonB) -> JsonB {
|
||||
// Try to acquire a read lock to get a clone of the Engine Arc
|
||||
let engine_opt = {
|
||||
@ -74,7 +74,7 @@ pub fn jspg_merge(schema_id: &str, data: JsonB) -> JsonB {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(not(test), pg_extern)]
|
||||
#[cfg_attr(not(test), pg_extern(volatile))]
|
||||
pub fn jspg_merge_ordered(schema_id: &str, data: Json) -> Json {
|
||||
let engine_opt = {
|
||||
let lock = GLOBAL_JSPG.read().unwrap();
|
||||
|
||||
@ -508,7 +508,7 @@ impl Merger {
|
||||
entity_change_kind.as_deref().unwrap_or(""),
|
||||
&type_name,
|
||||
type_def,
|
||||
&entity_fields,
|
||||
&mut entity_fields,
|
||||
entity_fetched.as_ref(),
|
||||
)?;
|
||||
|
||||
@ -787,7 +787,7 @@ impl Merger {
|
||||
let fetch_sql_template = if let Some(cached) = self.cache.get(entity_type_name) {
|
||||
cached
|
||||
} else {
|
||||
let mut select_list = String::from("to_jsonb(t1.*)");
|
||||
let mut select_list = String::from("COALESCE(to_jsonb(t1.*), '{}')");
|
||||
let mut join_clauses = format!("FROM agreego.\"{}\" t1", entity_type.hierarchy[0]);
|
||||
|
||||
for (i, table_name) in entity_type.hierarchy.iter().enumerate().skip(1) {
|
||||
@ -796,7 +796,7 @@ impl Merger {
|
||||
" LEFT JOIN agreego.\"{}\" {} ON {}.id = t1.id",
|
||||
table_name, t_alias, t_alias
|
||||
));
|
||||
select_list.push_str(&format!(" || to_jsonb({}.*)", t_alias));
|
||||
select_list.push_str(&format!(" || COALESCE(to_jsonb({}.*), '{{}}')", t_alias));
|
||||
}
|
||||
|
||||
let template = format!("SELECT {} {}", select_list, join_clauses);
|
||||
@ -899,7 +899,7 @@ impl Merger {
|
||||
change_kind: &str,
|
||||
entity_type_name: &str,
|
||||
entity_type: &crate::database::r#type::Type,
|
||||
entity_fields: &serde_json::Map<String, Value>,
|
||||
entity_fields: &mut serde_json::Map<String, Value>,
|
||||
_entity_fetched: Option<&serde_json::Map<String, Value>>,
|
||||
) -> Result<(), Error> {
|
||||
if change_kind.is_empty() {
|
||||
@ -907,7 +907,7 @@ impl Merger {
|
||||
}
|
||||
|
||||
let id_str = match entity_fields.get("id").and_then(|v| v.as_str()) {
|
||||
Some(id) => id,
|
||||
Some(id) => id.to_string(),
|
||||
None => {
|
||||
return Err(Error {
|
||||
code: "MISSING_ENTITY_ID".to_string(),
|
||||
@ -950,7 +950,7 @@ impl Merger {
|
||||
};
|
||||
|
||||
let mut entity_pairs = serde_json::Map::new();
|
||||
for (k, v) in entity_fields {
|
||||
for (k, v) in entity_fields.iter() {
|
||||
if table_fields.contains(k) {
|
||||
entity_pairs.insert(k.clone(), v.clone());
|
||||
}
|
||||
@ -984,20 +984,33 @@ impl Merger {
|
||||
}
|
||||
|
||||
let sql = format!(
|
||||
"INSERT INTO agreego.\"{}\" ({}) VALUES ({})",
|
||||
"INSERT INTO agreego.\"{}\" ({}) VALUES ({}) RETURNING to_jsonb(\"{}\".*)",
|
||||
table_name,
|
||||
columns.join(", "),
|
||||
values.join(", ")
|
||||
values.join(", "),
|
||||
table_name
|
||||
);
|
||||
if let Err(e) = self.db.execute(&sql, None) {
|
||||
return Err(Error {
|
||||
code: "DATABASE_SPI_ERROR".to_string(),
|
||||
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||
details: ErrorDetails {
|
||||
cause: Some(e),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
match self.db.query(&sql, None) {
|
||||
Ok(Value::Array(rows)) => {
|
||||
if let Some(Value::Object(row_map)) = rows.into_iter().next() {
|
||||
for (k, v) in row_map {
|
||||
if !v.is_null() {
|
||||
entity_fields.insert(k, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(Error {
|
||||
code: "DATABASE_SPI_ERROR".to_string(),
|
||||
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||
details: ErrorDetails {
|
||||
cause: Some(e),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else if change_kind == "update" || change_kind == "delete" {
|
||||
entity_pairs.remove("id");
|
||||
@ -1025,20 +1038,33 @@ impl Merger {
|
||||
}
|
||||
|
||||
let sql = format!(
|
||||
"UPDATE agreego.\"{}\" SET {} WHERE id = {}",
|
||||
"UPDATE agreego.\"{}\" SET {} WHERE id = {} RETURNING to_jsonb(\"{}\".*)",
|
||||
table_name,
|
||||
set_clauses.join(", "),
|
||||
Self::quote_literal(&Value::String(id_str.to_string()))
|
||||
Self::quote_literal(&Value::String(id_str.to_string())),
|
||||
table_name
|
||||
);
|
||||
if let Err(e) = self.db.execute(&sql, None) {
|
||||
return Err(Error {
|
||||
code: "DATABASE_SPI_ERROR".to_string(),
|
||||
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||
details: ErrorDetails {
|
||||
cause: Some(e),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
match self.db.query(&sql, None) {
|
||||
Ok(Value::Array(rows)) => {
|
||||
if let Some(Value::Object(row_map)) = rows.into_iter().next() {
|
||||
for (k, v) in row_map {
|
||||
if !v.is_null() {
|
||||
entity_fields.insert(k, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
return Err(Error {
|
||||
code: "DATABASE_SPI_ERROR".to_string(),
|
||||
values: Some(IndexMap::from([("error".to_string(), e.clone())])),
|
||||
details: ErrorDetails {
|
||||
cause: Some(e),
|
||||
..Default::default()
|
||||
},
|
||||
});
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,7 +97,14 @@ impl SqlFormatter {
|
||||
self.push_line("VALUES (");
|
||||
self.indent += 2;
|
||||
|
||||
let vals = if suffix.ends_with(")") { &suffix[..suffix.len() - 1] } else { suffix };
|
||||
let (vals, returning_clause) = if let Some(ret_idx) = suffix.rfind(") RETURNING ") {
|
||||
(&suffix[..ret_idx], Some(&suffix[ret_idx + 2..]))
|
||||
} else if suffix.ends_with(")") {
|
||||
(&suffix[..suffix.len() - 1], None)
|
||||
} else {
|
||||
(suffix, None)
|
||||
};
|
||||
|
||||
let mut val_tokens = Vec::new();
|
||||
let mut curr = String::new();
|
||||
let mut in_str = false;
|
||||
@ -119,7 +126,7 @@ impl SqlFormatter {
|
||||
for (i, val) in val_tokens.iter().enumerate() {
|
||||
let comma = if i < val_tokens.len() - 1 { "," } else { "" };
|
||||
|
||||
if val.starts_with("'{") && val.ends_with("}'") {
|
||||
if val.starts_with("'{") && val.ends_with("}'") && val.len() > 4 {
|
||||
let inner = &val[1..val.len() - 1];
|
||||
// Unescape single quotes from SQL strings
|
||||
let unescaped = inner.replace("''", "'");
|
||||
@ -146,6 +153,9 @@ impl SqlFormatter {
|
||||
}
|
||||
self.indent -= 2;
|
||||
self.push_line(")");
|
||||
if let Some(ret) = returning_clause {
|
||||
self.push_line(ret);
|
||||
}
|
||||
} else {
|
||||
self.push_line(&s);
|
||||
}
|
||||
@ -168,10 +178,19 @@ impl SqlFormatter {
|
||||
self.indent -= 2;
|
||||
|
||||
if let Some(w) = where_idx {
|
||||
self.push_line("WHERE");
|
||||
self.indent += 2;
|
||||
self.push_line(&after_set[w + 7..]);
|
||||
self.indent -= 2;
|
||||
let where_clause = &after_set[w + 7..];
|
||||
if let Some(ret_idx) = where_clause.find(" RETURNING ") {
|
||||
self.push_line("WHERE");
|
||||
self.indent += 2;
|
||||
self.push_line(&where_clause[..ret_idx]);
|
||||
self.indent -= 2;
|
||||
self.push_line(&where_clause[ret_idx + 1..]);
|
||||
} else {
|
||||
self.push_line("WHERE");
|
||||
self.indent += 2;
|
||||
self.push_line(where_clause);
|
||||
self.indent -= 2;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
self.push_line(&s);
|
||||
@ -341,7 +360,7 @@ impl SqlFormatter {
|
||||
}
|
||||
|
||||
Expr::Value(sqlparser::ast::ValueWithSpan { value: Value::SingleQuotedString(s), .. }) | Expr::Value(sqlparser::ast::ValueWithSpan { value: Value::EscapedStringLiteral(s), .. }) => {
|
||||
if s.starts_with('{') && s.ends_with('}') {
|
||||
if s.starts_with('{') && s.ends_with('}') && s.len() > 2 {
|
||||
if let Ok(json) = serde_json::from_str::<serde_json::Value>(s) {
|
||||
if let Ok(pretty) = serde_json::to_string_pretty(&json) {
|
||||
let lines: Vec<&str> = pretty.split('\n').collect();
|
||||
|
||||
Reference in New Issue
Block a user