AppFlowy-Cloud/.sqlx/query-62ed61bcf92fc0c3756f57d0fe05cdd12e70072f5646fe48790ad189a6e96b12.json

245 lines
11 KiB
JSON

{
"db_name": "PostgreSQL",
"query": "\n WITH template_with_creator_account_link AS (\n SELECT\n template.view_id,\n template.creator_id,\n COALESCE(\n ARRAY_AGG((link_type, url)::account_link_type) FILTER (WHERE link_type IS NOT NULL),\n '{}'\n ) AS account_links\n FROM af_template_view template\n JOIN af_published_collab\n USING (view_id)\n JOIN af_template_creator creator\n USING (creator_id)\n LEFT OUTER JOIN af_template_creator_account_link account_link\n USING (creator_id)\n WHERE view_id = $1\n GROUP BY (view_id, template.creator_id)\n ),\n related_template_with_category AS (\n SELECT\n template.related_view_id,\n ARRAY_AGG(\n (\n template_category.category_id,\n template_category.name,\n template_category.icon,\n template_category.bg_color\n )::template_category_minimal_type\n ) AS categories\n FROM af_related_template_view template\n JOIN af_template_view_template_category template_template_category\n ON template.related_view_id = template_template_category.view_id\n JOIN af_template_category template_category\n USING (category_id)\n WHERE template.view_id = $1\n GROUP BY template.related_view_id\n ),\n template_with_related_template AS (\n SELECT\n template.view_id,\n ARRAY_AGG(\n (\n template.related_view_id,\n related_template.created_at,\n related_template.updated_at,\n related_template.name,\n related_template.description,\n related_template.view_url,\n (\n creator.creator_id,\n creator.name,\n creator.avatar_url\n )::template_creator_minimal_type,\n related_template_with_category.categories,\n related_template.is_new_template,\n related_template.is_featured\n )::template_minimal_type\n ) AS related_templates\n FROM af_related_template_view template\n JOIN af_template_view related_template\n ON template.related_view_id = related_template.view_id\n JOIN af_template_creator creator\n ON related_template.creator_id = creator.creator_id\n JOIN related_template_with_category\n ON template.related_view_id = related_template_with_category.related_view_id\n WHERE template.view_id = $1\n GROUP BY template.view_id\n ),\n template_with_category AS (\n SELECT\n view_id,\n COALESCE(\n ARRAY_AGG((\n vtc.category_id,\n name,\n icon,\n bg_color,\n description,\n category_type,\n priority\n )) FILTER (WHERE vtc.category_id IS NOT NULL),\n '{}'\n ) AS categories\n FROM af_template_view_template_category vtc\n JOIN af_template_category tc\n ON vtc.category_id = tc.category_id\n WHERE view_id = $1\n GROUP BY view_id\n ),\n creator_number_of_templates AS (\n SELECT\n creator_id,\n COUNT(*) AS number_of_templates\n FROM af_template_view\n GROUP BY creator_id\n )\n\n SELECT\n template.view_id,\n template.created_at,\n template.updated_at,\n template.name,\n template.description,\n template.about,\n template.view_url,\n (\n creator.creator_id,\n creator.name,\n creator.avatar_url,\n template_with_creator_account_link.account_links,\n creator_number_of_templates.number_of_templates\n )::template_creator_type AS \"creator!: AFTemplateCreatorRow\",\n template_with_category.categories AS \"categories!: Vec<AFTemplateCategoryRow>\",\n COALESCE(template_with_related_template.related_templates, '{}') AS \"related_templates!: Vec<AFTemplateMinimalRow>\",\n template.is_new_template,\n template.is_featured\n FROM af_template_view template\n JOIN af_template_creator creator\n USING (creator_id)\n JOIN template_with_creator_account_link\n ON template.view_id = template_with_creator_account_link.view_id\n LEFT OUTER JOIN template_with_related_template\n ON template.view_id = template_with_related_template.view_id\n JOIN template_with_category\n ON template.view_id = template_with_category.view_id\n LEFT OUTER JOIN creator_number_of_templates\n ON template.creator_id = creator_number_of_templates.creator_id\n WHERE template.view_id = $1\n\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "view_id",
"type_info": "Uuid"
},
{
"ordinal": 1,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 2,
"name": "updated_at",
"type_info": "Timestamptz"
},
{
"ordinal": 3,
"name": "name",
"type_info": "Text"
},
{
"ordinal": 4,
"name": "description",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "about",
"type_info": "Text"
},
{
"ordinal": 6,
"name": "view_url",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "creator!: AFTemplateCreatorRow",
"type_info": {
"Custom": {
"name": "template_creator_type",
"kind": {
"Composite": [
[
"creator_id",
"Uuid"
],
[
"name",
"Text"
],
[
"avatar_url",
"Text"
],
[
"account_links",
{
"Custom": {
"name": "account_link_type[]",
"kind": {
"Array": {
"Custom": {
"name": "account_link_type",
"kind": {
"Composite": [
[
"link_type",
"Text"
],
[
"url",
"Text"
]
]
}
}
}
}
}
}
],
[
"number_of_templates",
"Int4"
]
]
}
}
}
},
{
"ordinal": 8,
"name": "categories!: Vec<AFTemplateCategoryRow>",
"type_info": "RecordArray"
},
{
"ordinal": 9,
"name": "related_templates!: Vec<AFTemplateMinimalRow>",
"type_info": {
"Custom": {
"name": "template_minimal_type[]",
"kind": {
"Array": {
"Custom": {
"name": "template_minimal_type",
"kind": {
"Composite": [
[
"view_id",
"Uuid"
],
[
"created_at",
"Timestamptz"
],
[
"updated_at",
"Timestamptz"
],
[
"name",
"Text"
],
[
"description",
"Text"
],
[
"view_url",
"Text"
],
[
"creator",
{
"Custom": {
"name": "template_creator_minimal_type",
"kind": {
"Composite": [
[
"creator_id",
"Uuid"
],
[
"name",
"Text"
],
[
"avatar_url",
"Text"
]
]
}
}
}
],
[
"categories",
{
"Custom": {
"name": "template_category_minimal_type[]",
"kind": {
"Array": {
"Custom": {
"name": "template_category_minimal_type",
"kind": {
"Composite": [
[
"category_id",
"Uuid"
],
[
"name",
"Text"
],
[
"icon",
"Text"
],
[
"bg_color",
"Text"
]
]
}
}
}
}
}
}
],
[
"is_new_template",
"Bool"
],
[
"is_featured",
"Bool"
]
]
}
}
}
}
}
}
},
{
"ordinal": 10,
"name": "is_new_template",
"type_info": "Bool"
},
{
"ordinal": 11,
"name": "is_featured",
"type_info": "Bool"
}
],
"parameters": {
"Left": [
"Uuid"
]
},
"nullable": [
false,
false,
false,
false,
false,
false,
false,
null,
null,
null,
false,
false
]
},
"hash": "62ed61bcf92fc0c3756f57d0fe05cdd12e70072f5646fe48790ad189a6e96b12"
}