# HG changeset patch # User Adam Chlipala # Date 1403719453 14400 # Node ID d11a7a9c4a738bd936156d6626a17556014cf638 # Parent 6add6d00ef5f9d501dc5f2f8b418871ad53bba0c New syntactic shorthand for antiquoting subqueries diff -r 6add6d00ef5f -r d11a7a9c4a73 doc/manual.tex --- a/doc/manual.tex Sun Jun 15 21:13:12 2014 +0000 +++ b/doc/manual.tex Wed Jun 25 14:04:13 2014 -0400 @@ -2280,7 +2280,7 @@ &&& \{\{e\}\} \; \mt{AS} \; \{c\} & \textrm{computed table expression, with computed local name} \\ \textrm{$\mt{FROM}$ items} & F &::=& T \mid \{\{e\}\} \mid F \; J \; \mt{JOIN} \; F \; \mt{ON} \; E \\ &&& \mid F \; \mt{CROSS} \; \mt{JOIN} \ F \\ - &&& \mid (Q) \; \mt{AS} \; t \\ + &&& \mid (Q) \; \mt{AS} \; t \mid (\{\{e\}\}) \; \mt{AS} \; t \\ \textrm{Joins} & J &::=& [\mt{INNER}] \\ &&& \mid [\mt{LEFT} \mid \mt{RIGHT} \mid \mt{FULL}] \; [\mt{OUTER}] \\ \textrm{SQL expressions} & E &::=& t.f & \textrm{column references} \\ diff -r 6add6d00ef5f -r d11a7a9c4a73 src/urweb.grm --- a/src/urweb.grm Sun Jun 15 21:13:12 2014 +0000 +++ b/src/urweb.grm Wed Jun 25 14:04:13 2014 -0400 @@ -1981,6 +1981,14 @@ in ([tname], (EApp (e, query), loc)) end) + | LPAREN LBRACE LBRACE eexp RBRACE RBRACE RPAREN AS tname (let + val loc = s (LPARENleft, RPARENright) + + val e = (EVar (["Basis"], "sql_from_query", Infer), loc) + val e = (ECApp (e, tname), loc) + in + ([tname], (EApp (e, eexp), loc)) + end) | LPAREN fitem RPAREN (fitem) tname : CSYMBOL (CName CSYMBOL, s (CSYMBOLleft, CSYMBOLright)) diff -r 6add6d00ef5f -r d11a7a9c4a73 tests/tags.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/tags.ur Wed Jun 25 14:04:13 2014 -0400 @@ -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} + diff -r 6add6d00ef5f -r d11a7a9c4a73 tests/tags.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/tags.urp Wed Jun 25 14:04:13 2014 -0400 @@ -0,0 +1,6 @@ +database dbname=test +sql tags.sql +rewrite url Tags/* + +$/list +tags