Mercurial > urweb
annotate demo/tree.ur @ 825:7f871c03e3a1
Destructing local let, to the point where demo compiles
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 28 May 2009 12:07:05 -0400 |
parents | 5819fb63c93a |
children | b9321bcefb42 |
rev | line source |
---|---|
adamc@471 | 1 sequence s |
adamc@469 | 2 table t : { Id : int, Parent : option int, Nam : string } |
adamc@715 | 3 PRIMARY KEY Id, |
adamc@715 | 4 CONSTRAINT F FOREIGN KEY Parent REFERENCES t (Id) ON DELETE CASCADE |
adamc@469 | 5 |
adamc@469 | 6 open TreeFun.Make(struct |
adamc@469 | 7 val tab = t |
adamc@469 | 8 end) |
adamc@469 | 9 |
adamc@469 | 10 fun row r = <xml> |
adamc@732 | 11 #{[r.Id]}: {[r.Nam]} <form><submit action={del r.Id} value="Delete"/></form> |
adamc@471 | 12 |
adamc@471 | 13 <form> |
adamc@471 | 14 Add child: <textbox{#Nam}/> <submit action={add (Some r.Id)}/> |
adamc@471 | 15 </form> |
adamc@469 | 16 </xml> |
adamc@469 | 17 |
adamc@471 | 18 and main () = |
adamc@469 | 19 xml <- tree row None; |
adamc@469 | 20 return <xml><body> |
adamc@469 | 21 {xml} |
adamc@471 | 22 |
adamc@471 | 23 <form> |
adamc@471 | 24 Add a top-level node: <textbox{#Nam}/> <submit action={add None}/> |
adamc@471 | 25 </form> |
adamc@469 | 26 </body></xml> |
adamc@471 | 27 |
adamc@471 | 28 and add parent r = |
adamc@471 | 29 id <- nextval s; |
adamc@471 | 30 dml (INSERT INTO t (Id, Parent, Nam) VALUES ({[id]}, {[parent]}, {[r.Nam]})); |
adamc@471 | 31 main () |
adamc@471 | 32 |
adamc@732 | 33 and del id () = |
adamc@471 | 34 dml (DELETE FROM t WHERE Id = {[id]}); |
adamc@471 | 35 main () |