Skip to content

Commit b648562

Browse files
committed
simple DBIish example
1 parent b51078e commit b648562

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
use v6;
2+
3+
=begin pod
4+
5+
=TITLE Executing SQL with DBIish
6+
7+
=AUTHOR stmuk
8+
9+
Execute some SQL commands using the DBIish database driver
10+
11+
=end pod
12+
13+
use DBIish;
14+
15+
my $dbh = DBIish.connect('SQLite', database => 'video.db');
16+
17+
$dbh.do('DROP TABLE IF EXISTS video');
18+
19+
my $sql = q:to"END";
20+
CREATE TABLE video(
21+
id integer primary key not null,
22+
title text not null,
23+
uri text not null
24+
)
25+
END
26+
27+
$dbh.do($sql);
28+
29+
my $st = $dbh.prepare('INSERT INTO video(title, uri) VALUES(?, ?)');
30+
31+
# put some data in
32+
33+
$st.execute("Larry Wall - Keynote, APW2014 2014-10-10 ", "https://www.youtube.com/watch?v=enlqVqit62Y");
34+
$st.execute("Carl Mäsak - Regexes in Perl 6 - Zero to Perl 6 Training", "https://www.youtube.com/watch?v=oo-gA9Z9SaA");
35+
36+
# get some data out
37+
38+
$st = $dbh.prepare('SELECT title,uri FROM video');
39+
$st.execute;
40+
41+
my @rows = $st.fetchall-AoH;
42+
43+
say @rows.gist;
44+
45+
# vim: expandtab shiftwidth=4 ft=perl6
Binary file not shown.

0 commit comments

Comments
 (0)