Skip to content

Instantly share code, notes, and snippets.

@Skarsnik

Skarsnik/stuff Secret

Created March 7, 2016 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skarsnik/5970cec31a4b906b324a to your computer and use it in GitHub Desktop.
Save Skarsnik/5970cec31a4b906b324a to your computer and use it in GitHub Desktop.
#!/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