SQL-Translator
view release on metacpan or search on metacpan
t/47postgres-producer.t view on Meta::CPAN
is($PRODUCER->($simple_default), q{str_default character varying(10) DEFAULT 'foo'}, 'default str',);
}
{
my $null_default = SQL::Translator::Schema::Field->new(
%field,
name => 'null_default',
default_value => \'NULL',
);
is($PRODUCER->($null_default), q{null_default character varying(10) DEFAULT NULL}, 'default null',);
}
{
my $null_default = SQL::Translator::Schema::Field->new(
%field,
name => 'null_default_2',
default_value => 'NULL', # XXX: this should go away
);
is(
$PRODUCER->($null_default),
q{null_default_2 character varying(10) DEFAULT NULL},
'default null from special cased string',
);
}
{
my $func_default = SQL::Translator::Schema::Field->new(
%field,
name => 'func_default',
default_value => \'func(funky)',
);
is(
$PRODUCER->($func_default),
q{func_default character varying(10) DEFAULT func(funky)},
'unquoted default from scalar ref',
);
}
}
my $view1 = SQL::Translator::Schema::View->new(
name => 'view_foo',
fields => [qw/id name/],
sql => 'SELECT id, name FROM thing',
);
my $create_opts = { add_replace_view => 1, no_comments => 1 };
my $view1_sql1 = SQL::Translator::Producer::PostgreSQL::create_view($view1, $create_opts);
my $view_sql_replace = "CREATE VIEW view_foo ( id, name ) AS
SELECT id, name FROM thing
";
is($view1_sql1, $view_sql_replace, 'correct "CREATE OR REPLACE VIEW" SQL');
my $view2 = SQL::Translator::Schema::View->new(
name => 'view_foo2',
sql => 'SELECT id, name FROM thing',
extra => {
'temporary' => '1',
'check_option' => 'cascaded',
},
);
my $create2_opts = { add_replace_view => 1, no_comments => 1 };
my $view2_sql1 = SQL::Translator::Producer::PostgreSQL::create_view($view2, $create2_opts);
my $view2_sql_replace = "CREATE TEMPORARY VIEW view_foo2 AS
SELECT id, name FROM thing
WITH CASCADED CHECK OPTION";
is($view2_sql1, $view2_sql_replace, 'correct "CREATE OR REPLACE VIEW" SQL 2');
{
my $table = SQL::Translator::Schema::Table->new(
name => 'foobar',
fields => [qw( foo bar )]
);
my $quote = { quote_table_names => '"' };
{
my $index = $table->add_index(name => 'myindex', fields => ['foo']);
my ($def) = SQL::Translator::Producer::PostgreSQL::create_index($index);
is($def, "CREATE INDEX myindex on foobar (foo)", 'index created');
($def) = SQL::Translator::Producer::PostgreSQL::create_index($index, $quote);
is($def, 'CREATE INDEX "myindex" on "foobar" ("foo")', 'index created w/ quotes');
}
{
my $index = $table->add_index(
name => 'myindex',
fields => [ { name => 'foo', prefix_length => 20 } ]
);
my ($def) = SQL::Translator::Producer::PostgreSQL::create_index($index);
is($def, "CREATE INDEX myindex on foobar (foo)", 'index created');
($def) = SQL::Translator::Producer::PostgreSQL::create_index($index, $quote);
is($def, 'CREATE INDEX "myindex" on "foobar" ("foo")', 'index created w/ quotes');
}
{
my $index = $table->add_index(name => 'myindex', fields => ['lower(foo)']);
my ($def) = SQL::Translator::Producer::PostgreSQL::create_index($index);
is($def, "CREATE INDEX myindex on foobar (lower(foo))", 'index created');
($def) = SQL::Translator::Producer::PostgreSQL::create_index($index, $quote);
is($def, 'CREATE INDEX "myindex" on "foobar" (lower(foo))', 'index created w/ quotes');
}
{
my $index = $table->add_index(
name => 'myindex',
fields => [ 'bar', 'lower(foo)' ]
);
my ($def) = SQL::Translator::Producer::PostgreSQL::create_index($index);
is($def, "CREATE INDEX myindex on foobar (bar, lower(foo))", 'index created');
($def) = SQL::Translator::Producer::PostgreSQL::create_index($index, $quote);
is($def, 'CREATE INDEX "myindex" on "foobar" ("bar", lower(foo))', 'index created w/ quotes');
}
{
my $index = $table->add_index(
name => 'covering',
fields => ['bar'],
options => { include => [ 'lower(foo)', 'baz' ] }
( run in 0.947 second using v1.01-cache-2.11-cpan-524268b4103 )