adamc@339: con colMeta = fn t_formT :: (Type * Type) => { adamc@339: Nam : string, adamc@339: Show : t_formT.1 -> xbody, adamc@339: Widget : nm :: Name -> xml form [] [nm = t_formT.2], adamc@341: WidgetPopulated : nm :: Name -> t_formT.1 -> xml form [] [nm = t_formT.2], adamc@339: Parse : t_formT.2 -> t_formT.1, adamc@339: Inject : sql_injectable t_formT.1 adamc@339: } adamc@339: con colsMeta = fn cols :: {(Type * Type)} => $(Top.mapT2T colMeta cols) adamc@326: adamc@325: functor Make(M : sig adamc@339: con cols :: {(Type * Type)} adamc@325: constraint [Id] ~ cols adamc@339: val tab : sql_table ([Id = int] ++ mapT2T fstTT cols) adamc@325: adamc@325: val title : string adamc@325: adamc@339: val cols : colsMeta cols adamc@325: end) = struct adamc@325: adamc@325: open constraints M adamc@325: val tab = M.tab adamc@325: adamc@339: sequence seq adamc@339: adamc@339: fun create (inputs : $(mapT2T sndTT M.cols)) = adamc@339: id <- nextval seq; adamc@339: () <- dml (insert tab (foldT2R2 [sndTT] [colMeta] adamc@339: [fn cols => $(mapT2T (fn t :: (Type * Type) => adamc@342: sql_exp [] [] [] t.1) cols)] adamc@339: (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) => adamc@339: [[nm] ~ rest] => adamc@339: fn input col acc => acc with nm = sql_inject col.Inject (col.Parse input)) adamc@339: {} [M.cols] inputs M.cols adamc@339: with #Id = (SQL {id}))); adamc@339: return
adamc@339: Inserted with ID {txt _ id}. adamc@339: adamc@339: adamc@342: fun save (id : int) (inputs : $(mapT2T sndTT M.cols)) = adamc@342: () <- dml (update [mapT2T fstTT M.cols] (foldT2R2 [sndTT] [colMeta] adamc@342: [fn cols => $(mapT2T (fn t :: (Type * Type) => adamc@342: sql_exp [T = [Id = int] ++ mapT2T fstTT M.cols] [] [] t.1) cols)] adamc@342: (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) => adamc@342: [[nm] ~ rest] => adamc@342: fn input col acc => acc with nm = sql_inject col.Inject (col.Parse input)) adamc@342: {} [M.cols] inputs M.cols) adamc@342: tab (WHERE T.Id = {id})); adamc@341: return adamc@342: Saved! adamc@341: adamc@341: adamc@341: fun update (id : int) = adamc@341: fso <- oneOrNoRows (SELECT tab.{{mapT2T fstTT M.cols}} FROM tab WHERE tab.Id = {id}); adamc@341: case fso : (Basis.option {Tab : $(mapT2T fstTT M.cols)}) of adamc@341: None => return Not found! adamc@341: | Some fs => returnAre you sure you want to delete ID #{txt _ id}?
adamc@337: adamc@337: adamc@337: adamc@337: adamc@334: fun main () : transaction page = adamc@334: rows <- queryX (SELECT * FROM tab AS T) adamc@339: (fn (fs : {T : $([Id = int] ++ mapT2T fstTT M.cols)}) => adamc@326:ID | adamc@339: {foldT2RX [colMeta] [tr] adamc@339: (fn (nm :: Name) (t :: (Type * Type)) (rest :: {(Type * Type)}) => adamc@336: [[nm] ~ rest] => adamc@336: fn col =>
---|
{cdata col.Nam} | adamc@336: