annotate 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
rev   line source
adam@2031 1 table images : { Id : int, Content : blob }
adam@2031 2 table tags : { Id : int, Tag : string }
adam@2031 3
adam@2031 4 datatype mode = Present | Absent
adam@2031 5 type condition = { Tag : string, Mode : mode }
adam@2031 6
adam@2031 7 type tag_query = sql_query [] [] [] [Id = int]
adam@2031 8
adam@2031 9 fun addCondition (c : condition) (q : tag_query) : tag_query =
adam@2031 10 case c.Mode of
adam@2031 11 Present => (SELECT I.Id AS Id
adam@2031 12 FROM ({{q}}) AS I
adam@2031 13 JOIN tags ON tags.Id = I.Id AND tags.Tag = {[c.Tag]})
adam@2031 14 | Absent => q
adam@2031 15
adam@2031 16 fun withConditions (cs : list condition) : tag_query =
adam@2031 17 List.foldl addCondition (SELECT images.Id AS Id FROM images) cs
adam@2031 18
adam@2031 19 fun main (cs : list condition) : transaction page =
adam@2031 20 x <- queryX (withConditions cs) (fn r => <xml><li>{[r.Id]}</li></xml>);
adam@2031 21 return <xml><body>
adam@2031 22 {x}
adam@2031 23 </body></xml>