diff options
author | Adam Chlipala <adam@chlipala.net> | 2014-06-25 14:04:13 -0400 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2014-06-25 14:04:13 -0400 |
commit | 4d2154f281d63408567a4f063dc4a5f9846cbf44 (patch) | |
tree | aa657a36e2c449a4aa47aac3b924487db6097d9a /tests | |
parent | 0a45f32c63f2d9a3df8c8ea15ea67b8e8c0fef5a (diff) |
New syntactic shorthand for antiquoting subqueries
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tags.ur | 23 | ||||
-rw-r--r-- | tests/tags.urp | 6 |
2 files changed, 29 insertions, 0 deletions
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 => <xml><li>{[r.Id]}</li></xml>); + return <xml><body> + {x} + </body></xml> diff --git a/tests/tags.urp b/tests/tags.urp new file mode 100644 index 00000000..b2f21c5a --- /dev/null +++ b/tests/tags.urp @@ -0,0 +1,6 @@ +database dbname=test +sql tags.sql +rewrite url Tags/* + +$/list +tags |