view demo/tree.ur @ 674:fab5998b840e

Type class reductions, but no inclusions yet
author Adam Chlipala <adamc@hcoop.net>
date Thu, 26 Mar 2009 14:37:31 -0400
parents 20fab0e96217
children 1a317a707d71
line wrap: on
line source
sequence s
table t : { Id : int, Parent : option int, Nam : string }

open TreeFun.Make(struct
                      val tab = t
                  end)

fun row r = <xml>
  #{[r.Id]}: {[r.Nam]} <a link={del r.Id}>[Delete]</a>

  <form>
    Add child: <textbox{#Nam}/> <submit action={add (Some r.Id)}/>
  </form>
</xml>

and main () =
    xml <- tree row None;
    return <xml><body>
      {xml}

      <form>
        Add a top-level node: <textbox{#Nam}/> <submit action={add None}/>
      </form>
    </body></xml>

and add parent r =
    id <- nextval s;
    dml (INSERT INTO t (Id, Parent, Nam) VALUES ({[id]}, {[parent]}, {[r.Nam]}));
    main ()

and del id =
    dml (DELETE FROM t WHERE Id = {[id]});
    main ()