File: 57-class-dbi.t

package info (click to toggle)
libsql-translator-perl 0.11024-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,572 kB
  • sloc: perl: 67,471; sql: 3,809; xml: 258; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,279 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/perl
# vim: set ft=perl:

use strict;
use Test::More tests => 2;
use Test::SQL::Translator qw(maybe_plan);
use FindBin qw/$Bin/;

use SQL::Translator::Schema::View;
use SQL::Translator::Producer::SQLite;

{
    my $view1 = SQL::Translator::Schema::View->new(
        name   => 'view_foo',
        fields => [qw/id name/],
        sql    => 'SELECT id, name FROM thing',
        extra  => {
            temporary     => 1,
            if_not_exists => 1,
        }
    );
    my $create_opts = { no_comments => 1 };
    my $view1_sql1 =
      [ SQL::Translator::Producer::SQLite::create_view( $view1, $create_opts ) ];

    my $view_sql_replace = [ 'CREATE TEMPORARY VIEW IF NOT EXISTS view_foo AS
    SELECT id, name FROM thing' ];
    is_deeply( $view1_sql1, $view_sql_replace, 'correct "CREATE TEMPORARY VIEW" SQL' );

    my $view2 = SQL::Translator::Schema::View->new(
        name   => 'view_foo',
        fields => [qw/id name/],
        sql    => 'SELECT id, name FROM thing',
    );

    my $view1_sql2 =
      [ SQL::Translator::Producer::SQLite::create_view( $view2, $create_opts ) ];
    my $view_sql_noreplace = [ 'CREATE VIEW view_foo AS
    SELECT id, name FROM thing' ];
    is_deeply( $view1_sql2, $view_sql_noreplace, 'correct "CREATE VIEW" SQL' );
}