5 use Test::More tests => 3;
6 use Test::SQL::Translator qw(maybe_plan);
9 use SQL::Translator::Schema::View;
10 use SQL::Translator::Schema::Table;
11 use SQL::Translator::Producer::SQLite;
14 my $view1 = SQL::Translator::Schema::View->new( name => 'view_foo',
15 fields => [qw/id name/],
16 sql => 'SELECT id, name FROM thing',
21 my $create_opts = { no_comments => 1 };
22 my $view1_sql1 = [ SQL::Translator::Producer::SQLite::create_view($view1, $create_opts) ];
24 my $view_sql_replace = [ 'CREATE TEMPORARY VIEW IF NOT EXISTS "view_foo" AS
25 SELECT id, name FROM thing' ];
26 is_deeply($view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL');
29 my $view2 = SQL::Translator::Schema::View->new( name => 'view_foo',
30 fields => [qw/id name/],
31 sql => 'SELECT id, name FROM thing',);
33 my $view1_sql2 = [ SQL::Translator::Producer::SQLite::create_view($view2, $create_opts) ];
34 my $view_sql_noreplace = [ 'CREATE VIEW "view_foo" AS
35 SELECT id, name FROM thing' ];
36 is_deeply($view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL');
41 my $table = SQL::Translator::Schema::Table->new(
45 name => 'foreign_key',
46 data_type => 'integer',
48 my $constraint = SQL::Translator::Schema::Constraint->new(
51 type => 'FOREIGN_KEY',
52 fields => ['foreign_key'],
53 reference_fields => ['id'],
54 reference_table => 'foo',
55 on_delete => 'RESTRICT',
56 on_update => 'CASCADE',
59 my $expected = [ 'FOREIGN KEY ("foreign_key") REFERENCES "foo"("id") ON DELETE RESTRICT ON UPDATE CASCADE'];
60 my $result = [SQL::Translator::Producer::SQLite::create_foreignkey($constraint,$create_opts)];
61 is_deeply($result, $expected, 'correct "FOREIGN KEY"');