DBD-Spanner

 view release on metacpan or  search on metacpan

env.json.example  view on Meta::CPAN

{
  "spanner_db_path": "projects/my-project/instances/my-instance/databases/my-database",
  "credentials_file": "/path/to/service-account-key.json"
}

lib/DBD/Spanner.pm  view on Meta::CPAN

        }
    }

    my $auth = $auth_cred;
    if (!$auth) {
        $auth = { get_token => sub { 'mock_token' } };
    }

    my $client = eval {
        Google::Cloud::Spanner::V1->new({
            credentials => $auth,
        });
    };

    my $transport = 'grpc';
    if ($dsn =~ /;transport=([^;]+)/i) {
        $transport = lc($1);
    } elsif ($ENV{SPANNER_TRANSPORT}) {
        $transport = lc($ENV{SPANNER_TRANSPORT});
    }

t/end-to-end/01-live-connection.t  view on Meta::CPAN

my ($db_path, $creds);

if ($ENV{SPANNER_DATABASE_PATH}) {
    $db_path = $ENV{SPANNER_DATABASE_PATH};
} elsif (-f 'env.json') {
    open my $fh, '<', 'env.json' or die $!;
    my $data = do { local $/; <$fh> };
    close $fh;
    my $cfg = decode_json($data);
    $db_path = $cfg->{spanner_db_path};
    $creds   = $cfg->{credentials_file};
}

if (!$db_path) {
    plan skip_all => 'Live Spanner credentials not configured (SPANNER_DATABASE_PATH or env.json missing)';
}

plan tests => 3;

$ENV{GOOGLE_APPLICATION_CREDENTIALS} = $creds if $creds && -f $creds;

my $dbh = DBI->connect("dbi:Spanner:$db_path", '', '', { RaiseError => 1 });
ok($dbh, 'Connected to live Cloud Spanner instance');
ok($dbh->ping(), 'Live ping succeeded');

t/end-to-end/02-live-async-query.t  view on Meta::CPAN

my ($db_path, $creds);

if ($ENV{SPANNER_DATABASE_PATH}) {
    $db_path = $ENV{SPANNER_DATABASE_PATH};
} elsif (-f 'env.json') {
    open my $fh, '<', 'env.json' or die $!;
    my $data = do { local $/; <$fh> };
    close $fh;
    my $cfg = decode_json($data);
    $db_path = $cfg->{spanner_db_path};
    $creds   = $cfg->{credentials_file};
}

if (!$db_path) {
    plan skip_all => 'Live Spanner credentials not configured (SPANNER_DATABASE_PATH or env.json missing)';
}

plan tests => 4;

$ENV{GOOGLE_APPLICATION_CREDENTIALS} = $creds if $creds && -f $creds;

my $dbh = DBI->connect("dbi:Spanner:$db_path", '', '', { RaiseError => 1 });
my $sth = $dbh->prepare('SELECT 42 AS val', { Async => 1 });
my $rv  = $sth->execute();

t/end-to-end/03-live-dml.t  view on Meta::CPAN

my ($db_path, $creds);

if ($ENV{SPANNER_DATABASE_PATH}) {
    $db_path = $ENV{SPANNER_DATABASE_PATH};
} elsif (-f 'env.json') {
    open my $fh, '<', 'env.json' or die $!;
    my $data = do { local $/; <$fh> };
    close $fh;
    my $cfg = decode_json($data);
    $db_path = $cfg->{spanner_db_path};
    $creds   = $cfg->{credentials_file};
}

if (!$db_path) {
    plan skip_all => 'Live Spanner credentials not configured (SPANNER_DATABASE_PATH or env.json missing)';
}

plan tests => 4;

$ENV{GOOGLE_APPLICATION_CREDENTIALS} = $creds if $creds && -f $creds;

my $dbh = DBI->connect("dbi:Spanner:$db_path", '', '', { RaiseError => 1 });

my $sth_ins = $dbh->prepare('INSERT INTO e2e_test (id, val) VALUES (?, ?)');
ok($sth_ins->execute(999, 'e2e_live_test'), 'Live DML INSERT executed');

t/end-to-end/04-live-transactions.t  view on Meta::CPAN

my ($db_path, $creds);

if ($ENV{SPANNER_DATABASE_PATH}) {
    $db_path = $ENV{SPANNER_DATABASE_PATH};
} elsif (-f 'env.json') {
    open my $fh, '<', 'env.json' or die $!;
    my $data = do { local $/; <$fh> };
    close $fh;
    my $cfg = decode_json($data);
    $db_path = $cfg->{spanner_db_path};
    $creds   = $cfg->{credentials_file};
}

if (!$db_path) {
    plan skip_all => 'Live Spanner credentials not configured (SPANNER_DATABASE_PATH or env.json missing)';
}

plan tests => 6;

$ENV{GOOGLE_APPLICATION_CREDENTIALS} = $creds if $creds && -f $creds;

my $dbh = DBI->connect("dbi:Spanner:$db_path", '', '', { RaiseError => 1, AutoCommit => 1 });
ok($dbh->FETCH('AutoCommit'), 'AutoCommit default 1');

# 1. Exercise begin_work and commit

t/end-to-end/05-live-concurrency-multi-fd.t  view on Meta::CPAN

my ($db_path, $creds);

if ($ENV{SPANNER_DATABASE_PATH}) {
    $db_path = $ENV{SPANNER_DATABASE_PATH};
} elsif (-f 'env.json') {
    open my $fh, '<', 'env.json' or die $!;
    my $data = do { local $/; <$fh> };
    close $fh;
    my $cfg = decode_json($data);
    $db_path = $cfg->{spanner_db_path};
    $creds   = $cfg->{credentials_file};
}

if (!$db_path) {
    plan skip_all => 'Live Spanner credentials not configured (SPANNER_DATABASE_PATH or env.json missing)';
}

plan tests => 5;

$ENV{GOOGLE_APPLICATION_CREDENTIALS} = $creds if $creds && -f $creds;

my $dbh = DBI->connect("dbi:Spanner:$db_path", '', '', { RaiseError => 1 });

my $sth1 = $dbh->prepare('SELECT 100 AS c1', { Async => 1 });
my $sth2 = $dbh->prepare('SELECT 200 AS c2', { Async => 1 });



( run in 2.348 seconds using v1.01-cache-2.11-cpan-007c89162af )