summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Benjamin Barenblat <bbaren@mit.edu>2013-04-21 17:06:35 -0400
committerGravatar Benjamin Barenblat <bbaren@mit.edu>2013-04-21 17:06:35 -0400
commit10698a19eeb4f6fbda18d601c0f8fd878734ab21 (patch)
tree779c4d1b21a9d9ae8844395882777773f2041dbc
parent7d189e95615b37106d504415ce21b8eec8710080 (diff)
Forum: Hook up to a database
-rw-r--r--.hgignore1
-rw-r--r--forum/forum.ur22
-rw-r--r--site.urp1
3 files changed, 21 insertions, 3 deletions
diff --git a/.hgignore b/.hgignore
index 6ceff3e..a2c2ad8 100644
--- a/.hgignore
+++ b/.hgignore
@@ -22,4 +22,5 @@ syntax: glob
*~
# Generated by the Ur/Web compiler
+setup.sql
*.exe
diff --git a/forum/forum.ur b/forum/forum.ur
index 8cb11da..6579e56 100644
--- a/forum/forum.ur
+++ b/forum/forum.ur
@@ -22,15 +22,31 @@ end) = struct
open Styles
+table question : { Id : int,
+ Body : string
+ } PRIMARY KEY Id
+sequence questionIdS
+
fun main () : transaction page =
+ newestQuestions <- queryX (SELECT * FROM question) (fn row =>
+ <xml>
+ <p>{[row.Question.Body]}</p>
+ </xml>);
return (
Template.generic (Some "Forum") <xml>
<div class={content}>
- <p>
- Coming soon!
- </p>
+ <p>All questions:</p>
+ {newestQuestions}
+ <p>Ask a new question:</p>
+ <form><textbox {#Body} /><submit action={ask} value="Ask" /></form>
</div>
</xml>
)
+and ask submission =
+ id <- nextval questionIdS;
+ dml (INSERT INTO question (Id, Body)
+ VALUES ({[id]}, {[submission.Body]}));
+ main ()
+
end
diff --git a/site.urp b/site.urp
index 6c754b2..e22de9e 100644
--- a/site.urp
+++ b/site.urp
@@ -16,6 +16,7 @@ rewrite url Main/main index
rewrite url Main/*
library meta
library forum
+sql setup.sql
config
styles