From 547fc262a0cdf2363f8eb9ec75bea2f3dcaa9e83 Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Wed, 25 Jun 2014 14:04:13 -0400 Subject: New syntactic shorthand for antiquoting subqueries --- tests/tags.ur | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/tags.ur (limited to 'tests/tags.ur') diff --git a/tests/tags.ur b/tests/tags.ur new file mode 100644 index 00000000..1213d824 --- /dev/null +++ b/tests/tags.ur @@ -0,0 +1,23 @@ +table images : { Id : int, Content : blob } +table tags : { Id : int, Tag : string } + +datatype mode = Present | Absent +type condition = { Tag : string, Mode : mode } + +type tag_query = sql_query [] [] [] [Id = int] + +fun addCondition (c : condition) (q : tag_query) : tag_query = + case c.Mode of + Present => (SELECT I.Id AS Id + FROM ({{q}}) AS I + JOIN tags ON tags.Id = I.Id AND tags.Tag = {[c.Tag]}) + | Absent => q + +fun withConditions (cs : list condition) : tag_query = + List.foldl addCondition (SELECT images.Id AS Id FROM images) cs + +fun main (cs : list condition) : transaction page = + x <- queryX (withConditions cs) (fn r =>
  • {[r.Id]}
  • ); + return + {x} + -- cgit v1.2.3