-
-
Save Skarsnik/5970cec31a4b906b324a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl6 | |
use v6; | |
use lib 'lib'; | |
use DBIish; | |
use NativeCall; | |
my $dbh = DBIish.connect( | |
"Pg", | |
##SNIP## | |
); | |
my $sth = $dbh.do(q:to/STATEMENT/); | |
DROP TABLE IF EXISTS sal_emp; | |
STATEMENT | |
class SalEmp { | |
has $.name; | |
has Int @.pay_by_quarter; | |
has @.schedule; | |
has Num @.salary_by_month; | |
}; | |
$sth = $dbh.do(q:to/STATEMENT/); | |
CREATE TABLE sal_emp ( | |
name text, | |
pay_by_quarter integer[], | |
schedule text[][], | |
salary_by_month float[] | |
); | |
STATEMENT | |
$sth = $dbh.do(q:to/STATEMENT/); | |
INSERT INTO sal_emp | |
VALUES ( | |
'Bill', | |
'{10000, 10000, 10000, 10000}', | |
'{{"meeting", "lunch"}, {"training day", "presentation"}}', | |
'{511.123, 622.345,1}' | |
); | |
STATEMENT | |
# $sth = $dbh.prepare(q:to/STATEMENT/); | |
# INSERT INTO sal_emp (name, pay_by_quarter, schedule) | |
# VALUES ( ?, ?, ? ) | |
#STATEMENT | |
# $sth.execute('TAFM', 'Mild fish taco', 1, 4.85); | |
# $sth.execute('BEOM', 'Medium size orange juice', 2, 1.20); | |
$sth = $dbh.prepare(q:to/STATEMENT/); | |
SELECT name, pay_by_quarter, schedule, salary_by_month | |
FROM sal_emp | |
STATEMENT | |
$sth.execute; | |
my %h = $sth.row(:hash); | |
dd %h; | |
my $se = SalEmp.new(|%h); | |
say $se; | |
# Cleanup | |
$sth.finish; | |
$dbh.disconnect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment