diff options
-rw-r--r-- | lib/ur/basis.urs | 15 | ||||
-rw-r--r-- | lib/ur/top.ur | 7 | ||||
-rw-r--r-- | lib/ur/top.urs | 5 | ||||
-rw-r--r-- | src/monoize.sml | 32 |
4 files changed, 57 insertions, 2 deletions
diff --git a/lib/ur/basis.urs b/lib/ur/basis.urs index 9bba1ee1..b9d1f55f 100644 --- a/lib/ur/basis.urs +++ b/lib/ur/basis.urs @@ -256,6 +256,11 @@ val foreign_key : mine1 ::: Name -> t ::: Type -> mine ::: {Type} -> munused ::: -> sql_constraint ([mine1 = t] ++ mine ++ munused) [] con sql_exp :: {{Type}} -> {{Type}} -> {Type} -> Type -> Type +val sql_exp_weaken : fs ::: {{Type}} -> agg ::: {{Type}} -> exps ::: {Type} -> t ::: Type + -> fs' ::: {{Type}} -> agg' ::: {{Type}} -> exps' ::: {Type} + -> [fs ~ fs'] => [agg ~ agg'] => [exps ~ exps'] => + sql_exp fs agg exps t + -> sql_exp (fs ++ fs') (agg ++ agg') (exps ++ exps') t val check : fs ::: {Type} -> sql_exp [] [] fs bool @@ -274,6 +279,12 @@ val sql_subset : keep_drop :: {({Type} * {Type})} (map (fn fields :: ({Type} * {Type}) => fields.1 ++ fields.2) keep_drop) (map (fn fields :: ({Type} * {Type}) => fields.1) keep_drop) val sql_subset_all : tables :: {{Type}} -> sql_subset tables tables +val sql_subset_concat : big1 ::: {{Type}} -> little1 ::: {{Type}} + -> big2 ::: {{Type}} -> little2 ::: {{Type}} + -> [big1 ~ big2] => [little1 ~ little2] => + sql_subset big1 little1 + -> sql_subset big2 little2 + -> sql_subset (big1 ++ big2) (little1 ++ little2) con sql_from_items :: {{Type}} -> Type @@ -343,10 +354,10 @@ val sql_relop : tables1 ::: {{Type}} -> sql_relop -> sql_query1 tables1 selectedFields selectedExps -> sql_query1 tables2 selectedFields selectedExps - -> sql_query1 selectedFields selectedFields selectedExps + -> sql_query1 [] selectedFields selectedExps val sql_forget_tables : tables ::: {{Type}} -> selectedFields ::: {{Type}} -> selectedExps ::: {Type} -> sql_query1 tables selectedFields selectedExps - -> sql_query1 selectedFields selectedFields selectedExps + -> sql_query1 [] selectedFields selectedExps type sql_direction val sql_asc : sql_direction diff --git a/lib/ur/top.ur b/lib/ur/top.ur index ffdd85bf..8b737179 100644 --- a/lib/ur/top.ur +++ b/lib/ur/top.ur @@ -234,6 +234,13 @@ fun queryX' [tables ::: {{Type}}] [exps ::: {Type}] [ctx ::: {Unit}] [inp ::: {T return <xml>{acc}{r}</xml>) <xml/> +fun hasRows [tables ::: {{Type}}] [exps ::: {Type}] + [tables ~ exps] + (q : sql_query tables exps) = + query q + (fn _ _ => return True) + False + fun oneOrNoRows [tables ::: {{Type}}] [exps ::: {Type}] [tables ~ exps] (q : sql_query tables exps) = diff --git a/lib/ur/top.urs b/lib/ur/top.urs index 2b6248fc..59ffec92 100644 --- a/lib/ur/top.urs +++ b/lib/ur/top.urs @@ -139,6 +139,11 @@ val queryX' : tables ::: {{Type}} -> exps ::: {Type} -> ctx ::: {Unit} -> inp :: -> transaction (xml ctx inp [])) -> transaction (xml ctx inp []) +val hasRows : tables ::: {{Type}} -> exps ::: {Type} + -> [tables ~ exps] => + sql_query tables exps + -> transaction bool + val oneOrNoRows : tables ::: {{Type}} -> exps ::: {Type} -> [tables ~ exps] => sql_query tables exps diff --git a/src/monoize.sml b/src/monoize.sml index 3998a49f..b92b9c70 100644 --- a/src/monoize.sml +++ b/src/monoize.sml @@ -1587,6 +1587,28 @@ fun monoExp (env, st, fm) (all as (e, loc)) = fm) end + | L.ECApp ( + (L.ECApp ( + (L.ECApp ( + (L.ECApp ( + (L.ECApp ( + (L.ECApp ( + (L.ECApp ( + (L.EFfi ("Basis", "sql_exp_weaken"), _), + _), _), + _), _), + _), _), + _), _), + _), _), + _), _), + _) => + let + val string = (L'.TFfi ("Basis", "string"), loc) + in + ((L'.EAbs ("e", string, string, (L'.ERel 0, loc)), loc), + fm) + end + | L.ECApp ((L.EFfi ("Basis", "check"), _), _) => let val string = (L'.TFfi ("Basis", "string"), loc) @@ -1993,6 +2015,16 @@ fun monoExp (env, st, fm) (all as (e, loc)) = ((L'.ERecord [], loc), fm) | L.ECApp ((L.EFfi ("Basis", "sql_subset_all"), _), _) => ((L'.ERecord [], loc), fm) + | L.ECApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_subset_concat"), + _), _), _), _), _), _), _), _) => + let + val un = (L'.TRecord [], loc) + in + ((L'.EAbs ("_", un, (L'.TFun (un, un), loc), + (L'.EAbs ("_", un, un, + (L'.ERecord [], loc)), loc)), loc), + fm) + end | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "fieldsOf_table"), _), _), _), _) => ((L'.ERecord [], loc), fm) |