Compare commits
4 commits
1d831585bd
...
35230b6c37
Author | SHA1 | Date | |
---|---|---|---|
Simon Bruder | 35230b6c37 | ||
Simon Bruder | faeec629a0 | ||
Simon Bruder | 27ebe5770a | ||
Simon Bruder | e83bc8316e |
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"db_name": "PostgreSQL",
|
"db_name": "PostgreSQL",
|
||||||
"query": "\n WITH RECURSIVE cte AS (\n SELECT\n id,\n ARRAY[]::UUID[] AS parents,\n ARRAY[]::VARCHAR[] AS parent_names,\n ARRAY[]::VARCHAR[] AS parent_class_names\n FROM items\n WHERE parent IS NULL\n\n UNION\n\n SELECT\n items.id,\n cte.parents || items.parent,\n cte.parent_names || items.name,\n cte.parent_class_names || item_classes.name\n FROM items\n JOIN cte\n ON items.parent = cte.id\n JOIN item_classes\n ON items.class = item_classes.id\n )\n SELECT\n cte.id AS \"id!\",\n items.name,\n items.class,\n item_classes.name AS \"class_name\",\n cte.parents AS \"parents!\",\n cte.parent_names AS \"parent_names!: Vec<Option<String>>\",\n cte.parent_class_names AS \"parent_class_names!\"\n FROM cte\n JOIN items\n ON cte.id = items.id\n JOIN item_classes\n ON items.class = item_classes.id\n ORDER BY items.created_at\n ",
|
"query": "\n WITH RECURSIVE cte AS (\n SELECT\n id,\n ARRAY[]::UUID[] AS parents,\n ARRAY[]::VARCHAR[] AS parent_names,\n ARRAY[]::VARCHAR[] AS parent_class_names\n FROM items\n WHERE parent IS NULL\n\n UNION\n\n SELECT\n items.id,\n cte.parents || items.parent,\n cte.parent_names || parent.name,\n cte.parent_class_names || parent_class.name\n FROM cte\n JOIN items\n ON items.parent = cte.id\n JOIN items AS \"parent\"\n ON parent.id = cte.id\n JOIN item_classes AS \"parent_class\"\n ON parent.class = parent_class.id\n )\n SELECT\n cte.id AS \"id!\",\n items.name,\n items.class,\n item_classes.name AS \"class_name\",\n cte.parents AS \"parents!\",\n cte.parent_names AS \"parent_names!: Vec<Option<String>>\",\n cte.parent_class_names AS \"parent_class_names!\"\n FROM cte\n JOIN items\n ON cte.id = items.id\n JOIN item_classes\n ON items.class = item_classes.id\n ORDER BY items.created_at\n ",
|
||||||
"describe": {
|
"describe": {
|
||||||
"columns": [
|
"columns": [
|
||||||
{
|
{
|
||||||
|
@ -52,5 +52,5 @@
|
||||||
null
|
null
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"hash": "5dac9aa215abdc07cda1f4d46db4bcafec45b6264efcb8a175580a71e48c7421"
|
"hash": "3dedb7b184103c1d418f7b94e26c75aea0c7d22e009299d1b87443e350578171"
|
||||||
}
|
}
|
|
@ -44,13 +44,15 @@ async fn get(pool: web::Data<PgPool>, user: Identity) -> actix_web::Result<impl
|
||||||
SELECT
|
SELECT
|
||||||
items.id,
|
items.id,
|
||||||
cte.parents || items.parent,
|
cte.parents || items.parent,
|
||||||
cte.parent_names || items.name,
|
cte.parent_names || parent.name,
|
||||||
cte.parent_class_names || item_classes.name
|
cte.parent_class_names || parent_class.name
|
||||||
FROM items
|
FROM cte
|
||||||
JOIN cte
|
JOIN items
|
||||||
ON items.parent = cte.id
|
ON items.parent = cte.id
|
||||||
JOIN item_classes
|
JOIN items AS "parent"
|
||||||
ON items.class = item_classes.id
|
ON parent.id = cte.id
|
||||||
|
JOIN item_classes AS "parent_class"
|
||||||
|
ON parent.class = parent_class.id
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
cte.id AS "id!",
|
cte.id AS "id!",
|
||||||
|
|
Loading…
Reference in a new issue