X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FQ-Branch.git;a=blobdiff_plain;f=lib%2FSQL%2FAbstract%2FReference.pm;h=257fd735ed7313bfef805798b244b4243a449108;hp=e700b44924712a4046c2dc90efc2bb0faf2a624b;hb=f583cadcb747f7193d919b9861bf9c2cf5cfa662;hpb=79d30ac3e26f74a78a1de067a8b6f229c62764d5 diff --git a/lib/SQL/Abstract/Reference.pm b/lib/SQL/Abstract/Reference.pm index e700b44..257fd73 100644 --- a/lib/SQL/Abstract/Reference.pm +++ b/lib/SQL/Abstract/Reference.pm @@ -20,7 +20,7 @@ comment before a code block saying C<# expr>, this is what's being described. The explicit structure that an expression is converted into before it's rendered into SQL is referred to as an abstract query tree. If you see a variable with C in the name, or a comment before a code block saying -C<# aqt>#, this is what's being described. +C<# aqt>, this is what's being described. =head2 SQL and Bind Values (query) @@ -33,11 +33,49 @@ plus bind values for passing to DBI, ala: If you see a comment before a code block saying C<# query>, the SQL + bind array is what's being described. +=head2 Expander + +An expander subroutine is written as: + + sub { + my ($sqla, $name, $value, $k) = @_; + ... + return $aqt; + } + +$name is the expr node type for node expanders, the op name for op +expanders, and the clause name for clause expanders. + +$value is the body of the thing being expanded + +If an op expander is being called as the binary operator in a L +expression, $k will be the hash key to be used as the left hand side +identifier. + +This can trivially be converted to an C type AQT node with: + + my $ident = $sqla->expand_expr({ -ident => $k }); + +=head2 Renderer + +A renderer subroutine looks like: + + sub { + my ($sqla, $type, $value) = @_; + ... + $sqla->join_query_parts($join, @parts); + } + +and can be registered on a per-type, per-op or per-clause basis. + =head1 AQT node types An AQT node consists of a hashref with a single key, whose name is C<-type> where 'type' is the node type, and whose value is the data for the node. +The following is an explanation of the built-in AQT type renderers; +additional renderers can be registered as part of the extension system. + =head2 literal # expr @@ -108,7 +146,17 @@ Standard binop: bomb.status = ? [ 'unexploded' ] -Not: + +Prefix unop: + + # expr + { -op => [ '-', { -ident => 'foo' } ] } + + # query + - foo + [] + +Not as special case parenthesised unop: # expr { -op => [ 'not', { -ident => 'explosive' } ] } @@ -191,6 +239,15 @@ Comma (use -row for parens): VALUES (1, 2), (3, 4) [] +=head2 keyword + + # expr + { -keyword => 'insert_into' } + + # query + INSERT INTO + [] + =head2 statement types AQT node types are also provided for C