From: Prog Rammer Date: Fri, 24 Aug 2012 20:00:38 +0000 (-0500) Subject: like sql.t but using ExprHelpers directly X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fda85b28582bbaa21efb5b23182c6fc01a358a46;p=dbsrgits%2FData-Query.git like sql.t but using ExprHelpers directly Only a few features that I've figured out so far. --- diff --git a/t/expr-helpers.t b/t/expr-helpers.t new file mode 100644 index 0000000..bef44c1 --- /dev/null +++ b/t/expr-helpers.t @@ -0,0 +1,44 @@ +use strictures 1; +use Test::More qw(no_plan); + +use Devel::Dwarn; +use Data::Query::Renderer::SQL::Naive; +use Data::Query::ExprHelpers; + +my $rend = Data::Query::Renderer::SQL::Naive->new({ quote_chars => [ "'" ] }); + +sub binding { map perl_scalar_value($_), @_ } + +sub dq_sql_is { + my $expr = shift; +#::Dwarn($expr); return; + my $rendered = $rend->render($expr); + is_deeply($rendered, @_); +} + +dq_sql_is + Select([ Identifier('*') ], Identifier('foo')), + ['SELECT * FROM foo'], + 'simple select'; + +dq_sql_is + Join( + Select([ Identifier('*') ], Identifier('foo')), + Identifier('bar'), + perl_operator('==', Identifier('foo', 'x'), Identifier('bar', 'y')) + ), + ['SELECT * FROM foo JOIN bar ON foo.x = bar.y'], + 'join on with dots'; + +dq_sql_is + Where( + perl_operator( + '==', + Identifier('x'), + Literal('SQL', '?', [ binding(1) ],), + ), + Select([ Identifier('*') ], Identifier('foo')), + ), + ['SELECT * FROM foo WHERE x = ?', binding(1)], + 'simple select with where and bind'; +