Ok, here we go. Have a look at this:
use v6;
use Squerl;
my $DB = Squerl.sqlite('example.db');
$DB.create_table: 'fruits',
'id' => 'primary_key',
'name' => 'String',
'qty' => 'Int',
my $fruits = $DB<fruits>;
my $i = 0;
for <apples pears oranges ninjas peaches papayas>
Z < 50 20 70 3 15 35> -> $name, $qty {
$fruits.insert($i++, $name, +$qty);
}
# those ninjas get in anywhere
$fruits.filter('name' => 'ninjas').delete;
# new shipment of pears
$fruits.filter('name' => 'pears').update('qty' => 40);
for $fruits.filter(sql_number('qty').gt(35)).llist {
say sprintf 'There are %d %s',
}
(Also available syntax-highlighted here.)
web and perl6-sqlite in your PERL6LIB path.$DB<fruits> syntax. It's made possible by defining a method postcircumfix:<{ }> in Squerl::Database. Unfortunately, it also triggered [perl #69438], so I had to add a lot of preemptive semicolons everywhere. Oh well. It was worth it.sql_number('qty').gt(35), I could have used a < operator if 't weren't for [perl #66552]..list instead of.llist if not for another bug (which I can't find in RT right now) causing Rakudo to freak out as soon as someone defines a list method. The thing about workarounds, of course, is that they can be successively removed as Rakudo improves. So you get to feel good twice: first, for finding a bug, and then for improving your own code by removing workarounds.I wish to thank The Perl Foundation for sponsoring the Web.pm effort.
Week 16 of Web.pm -- more Squerl work 0 Comments More | Login | Reply /