add database comments section
+28 −1 · 3 files changed
-
urblog.sql+9 −1 -
urblog.ur+17 −0 -
urblog.urp+2 −0
@@ -5,4 +5,12 @@ CREATE TABLE uw_Urblog_entry(uw_id int8 NOT NULL, uw_title text NOT NULL, ); - \ No newline at end of file + CREATE TABLE uw_Urblog_comment(uw_id int8 NOT NULL, uw_entry int8 NOT NULL, + uw_created timestamp NOT NULL, + uw_author text NOT NULL, uw_body text NOT NULL, + PRIMARY KEY (uw_id), + CONSTRAINT uw_Urblog_comment_Entry + FOREIGN KEY (uw_entry) REFERENCES uw_Urblog_entry (uw_id) + ); + + \ No newline at end of file @@ -1,7 +1,22 @@ table entry : { Id : int, Title : string, Created : time, Author : string, Body : string } PRIMARY KEY Id +table comment : {Id : int, Entry : int, Created : time, Author : string, Body : string } + PRIMARY KEY Id, + CONSTRAINT Entry FOREIGN KEY Entry REFERENCES entry(Id) + style blogEntry +style blogComment + +fun comments i : transaction xbody = + queryX (SELECT * FROM comment WHERE comment.Entry = {[i]}) + (fn row => + <xml> + <div class={blogComment}> + <p>{[row.Comment.Body]}</p> + <p>By {[row.Comment.Author]} at {[row.Comment.Created]}</p> + </div> + </xml>) fun list () = rows <- queryX (SELECT * FROM entry) @@ -27,6 +42,7 @@ fun list () = </xml> and detail (i:int) = res <- oneOrNoRows (SELECT * FROM entry WHERE entry.Id = {[i]}); + comm <- comments i; return (case res of None => <xml> @@ -46,6 +62,7 @@ and detail (i:int) = <div class={blogEntry}> <p>{[r.Entry.Body]}</p> </div> + {comm} <a link={list ()}>Back to all entries</a> </body> </xml>) @@ -1,5 +1,7 @@ allow url http://expdev.net/urtutorial/step3/style.css allow url http://expdev.net/urtutorial/step4/style.css +rewrite style Urblog/blogEntry blogEntry +rewrite style Urblog/blogComment blogComment database dbname=urblog sql urblog.sql