From ab13bbf764595fe6c01fcb5fe61bdf464d77f7fe Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 15 Dec 2009 11:11:49 -0500 Subject: Allow same constructor shorthand for 'view' sig items as for 'table' --- lib/ur/top.ur | 15 ++++++++++++++- lib/ur/top.urs | 15 ++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/ur/top.ur b/lib/ur/top.ur index 78a799b1..9a27f6b2 100644 --- a/lib/ur/top.ur +++ b/lib/ur/top.ur @@ -224,6 +224,13 @@ fun queryX [tables ::: {{Type}}] [exps ::: {Type}] [ctx ::: {Unit}] [inp ::: {Ty (fn fs acc => return {acc}{f fs}) +fun queryX1 [nm ::: Name] [fs ::: {Type}] [ctx ::: {Unit}] [inp ::: {Type}] + (q : sql_query [nm = fs] []) + (f : $fs -> xml ctx inp []) = + query q + (fn fs acc => return {acc}{f fs.nm}) + + fun queryX' [tables ::: {{Type}}] [exps ::: {Type}] [ctx ::: {Unit}] [inp ::: {Type}] [tables ~ exps] (q : sql_query tables exps) (f : $(exps ++ map (fn fields :: {Type} => $fields) tables) @@ -253,7 +260,7 @@ fun oneOrNoRows1 [nm ::: Name] [fs ::: {Type}] (q : sql_query [nm = fs] []) = (fn fs _ => return (Some fs.nm)) None -fun oneOrNoRowsE1 [tab ::: Name] [nm ::: Name] [t ::: Type] [[tab] ~ [nm]] (q : sql_query [tab = []] [nm = t]) = +fun oneOrNoRowsE1 [tabs ::: {Unit}] [nm ::: Name] [t ::: Type] [tabs ~ [nm]] (q : sql_query (mapU [] tabs) [nm = t]) = query q (fn fs _ => return (Some fs.nm)) None @@ -265,6 +272,12 @@ fun oneRow [tables ::: {{Type}}] [exps ::: {Type}] None => error Query returned no rows | Some r => r) +fun oneRow1 [nm ::: Name] [fs ::: {Type}] (q : sql_query [nm = fs] []) = + o <- oneOrNoRows q; + return (case o of + None => error Query returned no rows + | Some r => r.nm) + fun oneRowE1 [tabs ::: {Unit}] [nm ::: Name] [t ::: Type] [tabs ~ [nm]] (q : sql_query (mapU [] tabs) [nm = t]) = o <- oneOrNoRows q; return (case o of diff --git a/lib/ur/top.urs b/lib/ur/top.urs index 57bc2b1e..92fb9edd 100644 --- a/lib/ur/top.urs +++ b/lib/ur/top.urs @@ -132,6 +132,11 @@ val queryX : tables ::: {{Type}} -> exps ::: {Type} -> ctx ::: {Unit} -> inp ::: -> xml ctx inp []) -> transaction (xml ctx inp []) +val queryX1 : nm ::: Name -> fs ::: {Type} -> ctx ::: {Unit} -> inp ::: {Type} + -> sql_query [nm = fs] [] + -> ($fs -> xml ctx inp []) + -> transaction (xml ctx inp []) + val queryX' : tables ::: {{Type}} -> exps ::: {Type} -> ctx ::: {Unit} -> inp ::: {Type} -> [tables ~ exps] => sql_query tables exps @@ -156,9 +161,9 @@ val oneOrNoRows1 : nm ::: Name -> fs ::: {Type} -> sql_query [nm = fs] [] -> transaction (option $fs) -val oneOrNoRowsE1 : tab ::: Name -> nm ::: Name -> t ::: Type - -> [[tab] ~ [nm]] => - sql_query [tab = []] [nm = t] +val oneOrNoRowsE1 : tabs ::: {Unit} -> nm ::: Name -> t ::: Type + -> [tabs ~ [nm]] => + sql_query (mapU [] tabs) [nm = t] -> transaction (option t) val oneRow : tables ::: {{Type}} -> exps ::: {Type} @@ -168,6 +173,10 @@ val oneRow : tables ::: {{Type}} -> exps ::: {Type} $(exps ++ map (fn fields :: {Type} => $fields) tables) +val oneRow1 : nm ::: Name -> fs ::: {Type} + -> sql_query [nm = fs] [] + -> transaction $fs + val oneRowE1 : tabs ::: {Unit} -> nm ::: Name -> t ::: Type -> [tabs ~ [nm]] => sql_query (mapU [] tabs) [nm = t] -- cgit v1.2.3