* the 12 is just to show a call returning nothing.
#;16> (load "wiki/db.scm")
; loading wiki/db.scm ...
#;17> (import wiki/db)
#;18> (get-breadcrumbs db 12)
()
#;19> (get-breadcrumbs db 4)
(((id . 4) (title . "title123") (level . 0)) ((id . 2) (title . "shild123123") (level . 1)) ((id . 1) (title . "root..") (level . 2)))
#;20>
Here's the code ... i love it so much :P
I am working on a way to use optional list arg
and not need to have that 'a b c arg semantics.
But, I also like the 'a b c, because it's clear that
is a placeholder of 3 things.
(like 'a b c d e is clearly a placeholder for 5 things.)
#|
Get a list of nodes from the current node
up to the root.
|#
(define (get-breadcrumbs db node-id)
(let* ((sql #<#_end_
WITH RECURSIVE hierarchy AS (
SELECT id, parent_id, title, 0 as level
FROM wiki_node
WHERE id = #node-id
UNION ALL
SELECT w.id, w.parent_id, w.title, level + 1
FROM wiki_node as w, hierarchy as h
WHERE w.id = h.parent_id
AND h.parent_id IS NOT NULL
)
SELECT id, title, level
FROM hierarchy
_end_
))
(sqli:map-row
(lambda (a b c)
(zip-alist '(id title level) (list a b c)))
db
sql)))
#scheme #chicken #sql #CTE
* I normally use #ssql but they don't have the 'with recursive thing,
and anyways chicken's multi-line literals with substitution are
pretty great :)






