Description
I use sequelize-postgres npm for my nodejs project. The structure of my db
id: Sequelize.INTEGER,
sponsor: Sequelize.INTEGER,
depth: Sequelize.INTEGER,
path: Sequelize.TEXT,
parents: Sequelize.INTEGER,
cycle: Sequelize.INTEGER
Query for db
WITH RECURSIVE
nodes_cte(id, sponsor, depth, path, parents, cycle) AS (
SELECT tn.id, tn.sponsor,
1 AS depth,
'tn.id' AS path,
ARRAY[tn.id],
false
FROM referrals tn
WHERE tn.sponsor = 0
UNION ALL
SELECT c.id, c.sponsor,
p.depth + 1 AS depth,
(p.path || '->' || c.id),
p.parents || p.id,
c.id = ANY(p.parents)
FROM nodes_cte AS p,
referrals AS c
WHERE c.sponsor = p.id
AND NOT p.cycle
)
SELECT * FROM nodes_cte AS n;
If i make the query through Sequelize - i receive empty array. But when i do it through console i receive normal result.
Help me to solve my problem please.