From ed10a428abc7be47f8cce83db8dc64ac3cb6e84b Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 14 Oct 2008 17:18:59 -0400 Subject: Reusable column handlers for Crud --- tests/crud.ur | 22 ++++++++++++++++++++++ tests/crud.urs | 6 ++++++ tests/crud1.ur | 40 ++++------------------------------------ 3 files changed, 32 insertions(+), 36 deletions(-) (limited to 'tests') diff --git a/tests/crud.ur b/tests/crud.ur index b22cb157..02405f78 100644 --- a/tests/crud.ur +++ b/tests/crud.ur @@ -8,6 +8,28 @@ con colMeta = fn t_formT :: (Type * Type) => { } con colsMeta = fn cols :: {(Type * Type)} => $(Top.mapT2T colMeta cols) +fun default (t ::: Type) (sh : show t) (rd : read t) (inj : sql_injectable t) + name : colMeta (t, string) = + {Nam = name, + Show = txt _, + Widget = fn nm :: Name => , + WidgetPopulated = fn (nm :: Name) n => + , + Parse = readError _, + Inject = _} + +val int = default _ _ _ +val float = default _ _ _ +val string = default _ _ _ + +fun bool name = {Nam = name, + Show = txt _, + Widget = fn nm :: Name => , + WidgetPopulated = fn (nm :: Name) b => + , + Parse = fn x => x, + Inject = _} + functor Make(M : sig con cols :: {(Type * Type)} constraint [Id] ~ cols diff --git a/tests/crud.urs b/tests/crud.urs index 866853d5..0b3a4191 100644 --- a/tests/crud.urs +++ b/tests/crud.urs @@ -8,6 +8,12 @@ con colMeta = fn t_formT :: (Type * Type) => Inject : sql_injectable t_formT.1} con colsMeta = fn cols :: {(Type * Type)} => $(mapT2T colMeta cols) +val default : t ::: Type -> show t -> read t -> sql_injectable t -> string -> colMeta (t, string) +val int : string -> colMeta (int, string) +val float : string -> colMeta (float, string) +val string : string -> colMeta (string, string) +val bool : string -> colMeta (bool, bool) + functor Make(M : sig con cols :: {(Type * Type)} constraint [Id] ~ cols diff --git a/tests/crud1.ur b/tests/crud1.ur index 80b2b103..3849e822 100644 --- a/tests/crud1.ur +++ b/tests/crud1.ur @@ -1,44 +1,12 @@ table t1 : {Id : int, A : int, B : string, C : float, D : bool} -val a = {Nam = "A", - Show = txt _, - Widget = fn nm :: Name => , - WidgetPopulated = fn (nm :: Name) n => - , - Parse = readError _, - Inject = _} - -val b = {Nam = "B", - Show = txt _, - Widget = fn nm :: Name => , - WidgetPopulated = fn (nm :: Name) s => - , - Parse = readError _, - Inject = _} - -val c = {Nam = "C", - Show = txt _, - Widget = fn nm :: Name => , - WidgetPopulated = fn (nm :: Name) n => - , - Parse = readError _, - Inject = _} - -val d = {Nam = "D", - Show = txt _, - Widget = fn nm :: Name => , - WidgetPopulated = fn (nm :: Name) b => - , - Parse = fn x => x, - Inject = _} - open Crud.Make(struct val tab = t1 val title = "Crud1" - val cols = {A = a, - B = b, - C = c, - D = d} + val cols = {A = Crud.int "A", + B = Crud.string "B", + C = Crud.float "C", + D = Crud.bool "D"} end) -- cgit v1.2.3