routerAdd("GET", "/api/extras/random/:parent", (c) => { const result = new DynamicModel({ "id": "", "name": "", }); const query = `WITH RECURSIVE descendants(id) AS ( VALUES({:parent}) UNION ALL SELECT l.id FROM lists l JOIN descendants d ON d.id = l.parent ) SELECT t.id, t.name FROM tasks t JOIN descendants d ON t.list = d.id WHERE t.schedule <= DATE('now') ORDER BY RANDOM() LIMIT 1`; const queryNull = `SELECT id, name FROM tasks WHERE schedule <= DATE('now') ORDER BY RANDOM() LIMIT 1`; const parent = c.pathParam("parent"); $app.dao().db() .newQuery(parent === "null" ? queryNull : query) .bind({ parent }) .one(result) return c.json(200, result) })