comparison tests/tags.ur @ 2031:d11a7a9c4a73

New syntactic shorthand for antiquoting subqueries
author Adam Chlipala <adam@chlipala.net>
date Wed, 25 Jun 2014 14:04:13 -0400
parents
children 884673e5f7d5
comparison
equal deleted inserted replaced
2030:6add6d00ef5f 2031:d11a7a9c4a73
1 table images : { Id : int, Content : blob }
2 table tags : { Id : int, Tag : string }
3
4 datatype mode = Present | Absent
5 type condition = { Tag : string, Mode : mode }
6
7 type tag_query = sql_query [] [] [] [Id = int]
8
9 fun addCondition (c : condition) (q : tag_query) : tag_query =
10 case c.Mode of
11 Present => (SELECT I.Id AS Id
12 FROM ({{q}}) AS I
13 JOIN tags ON tags.Id = I.Id AND tags.Tag = {[c.Tag]})
14 | Absent => q
15
16 fun withConditions (cs : list condition) : tag_query =
17 List.foldl addCondition (SELECT images.Id AS Id FROM images) cs
18
19 fun main (cs : list condition) : transaction page =
20 x <- queryX (withConditions cs) (fn r => <xml><li>{[r.Id]}</li></xml>);
21 return <xml><body>
22 {x}
23 </body></xml>