在琥珀色水晶(花岗岩ORM)中执行postgresql查询

时间:2019-04-25 06:33:14

标签: crystal-lang amber-framework

WITH RECURSIVE pops (id, level, name, name_path) AS ( 
  SELECT id, 0, name, ARRAY[name] 
  FROM categories 
  WHERE parent_category_id is null 
  UNION ALL 
  SELECT p.id, t0.level + 1, p.name, ARRAY_APPEND(t0.name_path, p.name) 
  FROM categories p 
    INNER JOIN pops t0 ON t0.id = p.parent_category_id
) 
SELECT id,level, name_path[1] AS category, ARRAY_TO_STRING(name_path, ' > ') 
FROM pops;

如何使用花岗岩orm在琥珀色水晶应用中执行上述查询

0 个答案:

没有答案