view demo/tree.ur @ 2174:ce312cad5ecd

Use correct OpenSSL thread safety macros on OS X (closes #209) Create an Autoconf test to determine if pthread_t is a pointer or scalar type, and use the appropriate CRYPTO_THREADID_set macro based on the result.
author Benjamin Barenblat <bbaren at mit.edu>
date Sun, 20 Sep 2015 17:46:07 -0400
parents d069b193ed6b
children
line wrap: on
line source
sequence s
table t : { Id : int, Parent : option int, Nam : string }
  PRIMARY KEY Id,
  CONSTRAINT F FOREIGN KEY Parent REFERENCES t (Id) ON DELETE CASCADE

open TreeFun.Make(struct
                      con id = #Id
                      con parent = #Parent
                      val tab = t
                  end)

fun row r = <xml>
  #{[r.Id]}: {[r.Nam]} <form><submit action={del r.Id} value="Delete"/></form>

  <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 ()