Mercurial > meta
diff sql.urs @ 15:6ebc2ca594b7
Sql.insertIfMissing and deleteByKey (partly from Ron de Bruijn)
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 11 Dec 2011 14:04:34 -0500 |
parents | d05943db55e8 |
children | 959583692166 |
line wrap: on
line diff
--- a/sql.urs Tue Jun 14 08:55:15 2011 -0400 +++ b/sql.urs Sun Dec 11 14:04:34 2011 -0500 @@ -15,3 +15,19 @@ => folder fs -> sql_exp [tn1 = ofs1 ++ fs, tn2 = ofs2 ++ fs] [] [] bool (* Declare equality of same-named columns from two tables. *) + +val insertIfMissing : keyCols ::: {Type} -> otherCols ::: {Type} -> otherKeys ::: {{Unit}} + -> [keyCols ~ otherCols] => [[Pkey] ~ otherKeys] + => sql_table (keyCols ++ otherCols) ([Pkey = map (fn _ => ()) keyCols] ++ otherKeys) + -> $(keyCols ++ otherCols) + -> folder keyCols -> $(map sql_injectable keyCols) + -> folder otherCols -> $(map sql_injectable otherCols) + -> transaction bool +(* Insert a row into an SQL table if its key isn't already present, returning [False] iff the key was already present *) + +val deleteByKey : keyCols ::: {Type} -> otherCols ::: {Type} -> otherKeys ::: {{Unit}} + -> [keyCols ~ otherCols] => [[Pkey] ~ otherKeys] + => sql_table (keyCols ++ otherCols) ([Pkey = map (fn _ => ()) keyCols] ++ otherKeys) + -> $keyCols -> folder keyCols -> $(map sql_injectable keyCols) + -> transaction {} +(* Delete a row from a table by matching its primary key against a given record. *)