Added INSERT with example
[dbsrgits/SQL-Abstract-2.0-ish.git] / t / 001_basic.t
CommitLineData
a0185af2 1use strict;
2use warnings;
3
924d940e 4use Test::More tests => 9;
5bf8c024 5use Test::Differences;
a0185af2 6
7use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
924d940e 8use_ok('SQL::Abstract::AST::v1') or BAIL_OUT( "$@" );
a0185af2 9
14774be0 10my $sqla = SQL::Abstract->create(1);
0bf8a8c4 11
12# TODO: once MXMS supports %args, use that here
7a56723e 13is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), "me.id",
a0185af2 14 "Simple name generator";
15
7a56723e 16is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
4ee32f41 17 "me.*",
18 "Simple name generator";
19
20$sqla->quote_chars(['`']);
21
7a56723e 22is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
4ee32f41 23 "`me`.*",
24 "Simple name generator";
25
26$sqla->disable_quoting;
27
c314b35d 28is $sqla->dispatch(
7a56723e 29 { -type => 'false' }
44cfd1f6 30), "0 = 1", "false value";
31
32is $sqla->dispatch(
7a56723e 33 { -type => 'true' }
44cfd1f6 34), "1 = 1", "true value";
35
36is $sqla->dispatch(
7a56723e 37 { -type => 'list',
38 args => [
39 { -type => name => args => [qw/me id/] },
40 { -type => name => args => [qw/me foo bar/] },
41 { -type => name => args => [qw/bar/] }
42 ]
43 }
a0185af2 44), "me.id, me.foo.bar, bar",
45 "List generator";
4769c837 46
c314b35d 47is $sqla->dispatch(
7a56723e 48 { -type => 'alias', ident => { -type => name => args => [qw/me id/]}, as => "foobar" }
4769c837 49), "me.id AS foobar",
50 "Alias generator";
51
d2582f0f 52