annotate demo/tree.ur @ 1275:74150edf1134

Undo fancy wildification; instead, client code should include extra wildcard con declarations
author Adam Chlipala <adamc@hcoop.net>
date Thu, 03 Jun 2010 14:44:08 -0400
parents d069b193ed6b
children
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@1078 7 con id = #Id
adamc@1078 8 con parent = #Parent
adamc@1079 9 val tab = t
adamc@469 10 end)
adamc@469 11
adamc@469 12 fun row r = <xml>
adamc@732 13 #{[r.Id]}: {[r.Nam]} <form><submit action={del r.Id} value="Delete"/></form>
adamc@471 14
adamc@471 15 <form>
adamc@471 16 Add child: <textbox{#Nam}/> <submit action={add (Some r.Id)}/>
adamc@471 17 </form>
adamc@469 18 </xml>
adamc@469 19
adamc@471 20 and main () =
adamc@469 21 xml <- tree row None;
adamc@469 22 return <xml><body>
adamc@469 23 {xml}
adamc@471 24
adamc@471 25 <form>
adamc@471 26 Add a top-level node: <textbox{#Nam}/> <submit action={add None}/>
adamc@471 27 </form>
adamc@469 28 </body></xml>
adamc@471 29
adamc@471 30 and add parent r =
adamc@471 31 id <- nextval s;
adamc@471 32 dml (INSERT INTO t (Id, Parent, Nam) VALUES ({[id]}, {[parent]}, {[r.Nam]}));
adamc@471 33 main ()
adamc@471 34
adamc@732 35 and del id () =
adamc@471 36 dml (DELETE FROM t WHERE Id = {[id]});
adamc@471 37 main ()