Executing SQL with DBIish

Author: stmuk

Execute some SQL commands using the DBIish database driver

Source code: 14-09-dbi-sql.p6

#!/usr/bin/env perl6

use v6;

use DBIish;

my $dbh = DBIish.connect('SQLite', database => 'video.db');

$dbh.do('DROP TABLE IF EXISTS video');

my $sql =  q:to"END";
    id integer primary key not null,
    title text not null,
    uri text not null


my $st = $dbh.prepare('INSERT INTO video(title, uri) VALUES(?, ?)');

# put some data in
$st.execute("Larry Wall - Keynote, APW2014 2014-10-10 ",
$st.execute("Carl Mäsak - Regexes in Perl 6 - Zero to Perl 6 Training",

# get some data out
$st = $dbh.prepare('SELECT title,uri FROM video');

my @rows =  $st.fetchall-AoH;

say @rows.gist;