comparison demo/crud.ur @ 499:12d163bb856f

Update Crud demo to use local functions
author Adam Chlipala <adamc@hcoop.net>
date Thu, 20 Nov 2008 10:41:58 -0500
parents 20fab0e96217
children d64533157f40
comparison
equal deleted inserted replaced
498:cbeb1683dc6a 499:12d163bb856f
108 <p>Inserted with ID {[id]}.</p> 108 <p>Inserted with ID {[id]}.</p>
109 109
110 {ls} 110 {ls}
111 </body></xml> 111 </body></xml>
112 112
113 and save (id : int) (inputs : $(mapT2T sndTT M.cols)) = 113 and upd (id : int) =
114 dml (update [mapT2T fstTT M.cols] 114 let
115 (foldT2R2 [sndTT] [colMeta] 115 fun save (inputs : $(mapT2T sndTT M.cols)) =
116 [fn cols => $(mapT2T (fn t :: (Type * Type) => 116 dml (update [mapT2T fstTT M.cols]
117 sql_exp [T = [Id = int] 117 (foldT2R2 [sndTT] [colMeta]
118 ++ mapT2T fstTT M.cols] 118 [fn cols => $(mapT2T (fn t :: (Type * Type) =>
119 [] [] t.1) cols)] 119 sql_exp [T = [Id = int]
120 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) 120 ++ mapT2T fstTT M.cols]
121 [[nm] ~ rest] => 121 [] [] t.1) cols)]
122 fn input col acc => acc ++ {nm = 122 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
123 @sql_inject col.Inject (col.Parse input)}) 123 [[nm] ~ rest] =>
124 {} [M.cols] inputs M.cols) 124 fn input col acc => acc ++ {nm =
125 tab (WHERE T.Id = {[id]})); 125 @sql_inject col.Inject (col.Parse input)})
126 ls <- list (); 126 {} [M.cols] inputs M.cols)
127 return <xml><body> 127 tab (WHERE T.Id = {[id]}));
128 <p>Saved!</p> 128 ls <- list ();
129 return <xml><body>
130 <p>Saved!</p>
129 131
130 {ls} 132 {ls}
131 </body></xml> 133 </body></xml>
134 in
135 fso <- oneOrNoRows (SELECT tab.{{mapT2T fstTT M.cols}} FROM tab WHERE tab.Id = {[id]});
136 case fso : (Basis.option {Tab : $(mapT2T fstTT M.cols)}) of
137 None => return <xml><body>Not found!</body></xml>
138 | Some fs => return <xml><body><form>
139 {foldT2R2 [fstTT] [colMeta] [fn cols :: {(Type * Type)} => xml form [] (mapT2T sndTT cols)]
140 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
141 [[nm] ~ rest] (v : t.1) (col : colMeta t)
142 (acc : xml form [] (mapT2T sndTT rest)) =>
143 <xml>
144 <li> {cdata col.Nam}: {col.WidgetPopulated [nm] v}</li>
145 {useMore acc}
146 </xml>)
147 <xml/>
148 [M.cols] fs.Tab M.cols}
132 149
133 and upd (id : int) = 150 <submit action={save}/>
134 fso <- oneOrNoRows (SELECT tab.{{mapT2T fstTT M.cols}} FROM tab WHERE tab.Id = {[id]}); 151 </form></body></xml>
135 case fso : (Basis.option {Tab : $(mapT2T fstTT M.cols)}) of 152 end
136 None => return <xml><body>Not found!</body></xml>
137 | Some fs => return <xml><body><form>
138 {foldT2R2 [fstTT] [colMeta] [fn cols :: {(Type * Type)} => xml form [] (mapT2T sndTT cols)]
139 (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)})
140 [[nm] ~ rest] (v : t.1) (col : colMeta t)
141 (acc : xml form [] (mapT2T sndTT rest)) =>
142 <xml>
143 <li> {cdata col.Nam}: {col.WidgetPopulated [nm] v}</li>
144 {useMore acc}
145 </xml>)
146 <xml/>
147 [M.cols] fs.Tab M.cols}
148 153
149 <submit action={save id}/> 154 and confirm (id : int) =
150 </form></body></xml> 155 let
151 156 fun delete () =
152 and delete (id : int) = 157 dml (DELETE FROM tab WHERE Id = {[id]});
153 dml (DELETE FROM tab WHERE Id = {[id]}); 158 ls <- list ();
154 ls <- list (); 159 return <xml><body>
155 return <xml><body> 160 <p>The deed is done.</p>
156 <p>The deed is done.</p> 161
157 162 {ls}
158 {ls} 163 </body></xml>
159 </body></xml> 164 in
160 165 return <xml><body>
161 and confirm (id : int) = return <xml><body> 166 <p>Are you sure you want to delete ID #{[id]}?</p>
162 <p>Are you sure you want to delete ID #{[id]}?</p> 167
163 168 <p><a link={delete ()}>I was born sure!</a></p>
164 <p><a link={delete id}>I was born sure!</a></p> 169 </body></xml>
165 </body></xml> 170 end
166 171
167 and main () = 172 and main () =
168 ls <- list (); 173 ls <- list ();
169 return <xml><head> 174 return <xml><head>
170 <title>{cdata M.title}</title> 175 <title>{cdata M.title}</title>