summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-10-23 18:45:10 -0400
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-10-23 18:45:10 -0400
commit9569ae99c75cb74aeeb6fa02e6eec9eff2c7669f (patch)
tree6d1b3b0450e7d90ffb86bc43ce2c479ba9b7c78f /demo
parentfbde7928c43149e02806949343783dc6e885ab0f (diff)
Crud2 demo
Diffstat (limited to 'demo')
-rw-r--r--demo/crud2.sql6
-rw-r--r--demo/crud2.ur34
-rw-r--r--demo/crud2.urp5
-rw-r--r--demo/prose4
4 files changed, 49 insertions, 0 deletions
diff --git a/demo/crud2.sql b/demo/crud2.sql
new file mode 100644
index 00000000..88568f2a
--- /dev/null
+++ b/demo/crud2.sql
@@ -0,0 +1,6 @@
+CREATE TABLE uw_Crud2_t(uw_id int8 NOT NULL, uw_nam text NOT NULL,
+ uw_ready bool NOT NULL);
+
+ CREATE SEQUENCE uw_Crud2_Crud_Make_seq;
+
+ \ No newline at end of file
diff --git a/demo/crud2.ur b/demo/crud2.ur
new file mode 100644
index 00000000..1db376d4
--- /dev/null
+++ b/demo/crud2.ur
@@ -0,0 +1,34 @@
+table t : {Id : int, Nam : string, Ready : bool}
+
+open Crud.Make(struct
+ val tab = t
+
+ val title = "Are you ready?"
+
+ val cols = {Nam = Crud.string "Name",
+ Ready = {Nam = "Ready",
+ Show = (fn b => if b then
+ <xml>Ready!</xml>
+ else
+ <xml>Not ready</xml>),
+ Widget = (fn (nm :: Name) => <xml>
+ <select{nm}>
+ <option>Ready</option>
+ <option>Not ready</option>
+ </select>
+ </xml>),
+ WidgetPopulated = (fn (nm :: Name) b => <xml>
+ <select{nm}>
+ <option selected={b}>Ready</option>
+ <option selected={not b}>Not ready</option>
+ </select>
+ </xml>),
+ Parse = (fn s =>
+ case s of
+ "Ready" => True
+ | "Not ready" => False
+ | _ => error <xml>Invalid ready/not ready</xml>),
+ Inject = _
+ }
+ }
+ end)
diff --git a/demo/crud2.urp b/demo/crud2.urp
new file mode 100644
index 00000000..d552e1a7
--- /dev/null
+++ b/demo/crud2.urp
@@ -0,0 +1,5 @@
+database dbname=test
+sql crud2.sql
+
+crud
+crud2
diff --git a/demo/prose b/demo/prose
index 6b7ddf29..3b9d9ebb 100644
--- a/demo/prose
+++ b/demo/prose
@@ -152,3 +152,7 @@ crud1.urp
<p>Looking at <tt>crud1.ur</tt>, we see that a use of the functor is almost trivial. Only the value components of the argument structure must be provided. The column row type is inferred, and the disjointness constraint is proved automatically.</p>
<p>We won't go into detail on the implementation of <tt>Crud.Make</tt>. The types of the functions used there can be found in the signatures of the built-in <tt>Basis</tt> module and the <tt>Top</tt> module from the standard library. The signature of the first and the signature and implementation of the second can be found in the <tt>lib</tt> directory of the Ur/Web distribution.</p>
+
+crud2.urp
+
+<p>This example shows another application of <tt>Crud.Make</tt>. We mix one standard column with one customized column. We write an underscore for the <tt>Inject</tt> field of meta-data, since the type class facility can infer that witness.</p>