summaryrefslogtreecommitdiff
path: root/demo/constraints.ur
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2009-05-03 12:01:55 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2009-05-03 12:01:55 -0400
commitebbae2ae752fe3b0774207920c7510853ffcbdcf (patch)
tree49c6b55d21a08b6b675a910fbc69fffbc82b78a4 /demo/constraints.ur
parent9d959303231d6790e9ffbc631e775abbeaee4584 (diff)
constraints demo
Diffstat (limited to 'demo/constraints.ur')
-rw-r--r--demo/constraints.ur38
1 files changed, 38 insertions, 0 deletions
diff --git a/demo/constraints.ur b/demo/constraints.ur
new file mode 100644
index 00000000..bcd88bbd
--- /dev/null
+++ b/demo/constraints.ur
@@ -0,0 +1,38 @@
+table t : { Id : int, Nam : string, Parent : option int }
+ PRIMARY KEY Id,
+ CONSTRAINT Nam UNIQUE Nam,
+ CONSTRAINT Id CHECK Id >= 0,
+ CONSTRAINT Parent FOREIGN KEY Parent REFERENCES t(Id)
+
+fun main () =
+ list <- queryX (SELECT * FROM t)
+ (fn r => <xml><tr>
+ <td>{[r.T.Id]}</td>
+ <td>{[r.T.Nam]}</td>
+ <td>{case r.T.Parent of
+ None => <xml>NULL</xml>
+ | Some id => <xml>{[id]}</xml>}</td>
+ </tr></xml>);
+ return <xml><body>
+ <table>
+ <tr> <th>Id</th> <th>Name</th> <th>Parent</th> </tr>
+ {list}
+ </table>
+
+ <form>
+ <table>
+ <tr> <th>Id:</th> <td><textbox{#Id}/></td> </tr>
+ <tr> <th>Name:</th> <td><textbox{#Nam}/></td> </tr>
+ <tr> <th>Parent:</th> <td><textbox{#Parent}/></td> </tr>
+ <tr> <th/> <td><submit action={add}/></td> </tr>
+ </table>
+ </form>
+ </body></xml>
+
+and add r =
+ dml (INSERT INTO t (Id, Nam, Parent)
+ VALUES ({[readError r.Id]}, {[r.Nam]},
+ {[case r.Parent of
+ "" => None
+ | s => Some (readError s)]}));
+ main ()