Strangely Consistent

Theory, practice, and languages, braided together

Week 16 of Web.pm — more Squerl work

theer has is a sison for evryting, and a tiems for every perpos under teh ceiling. a tiemz 2 git kittehs, an a tiems 2 get ded. a tiemz to bury the cheezburger and a time to dig up the cheezburger you has planted. tiemz 4 killin the mouses and tiemz 4 being ok with them but not rly. theres a tiemz 4 lollin and a tiemz 4 not lollin so much. A teimz 4 weepins and a teimz 4 dancin. a tiemz to keep cheezburger and a tiemz to give them away, srsly. teimz 4 hugs, tiemz when hugz are NOT WANTED. a tiemz 4 lookin round and a timez 4 getin bored and stop lookin. a tiemz 2 brak and a teimz 4 fix and a teimz 4 STFU and a teimz 2 talkz. A teimz 4 LUV and a teimz 4 HAT. A teimz 4 lots a killin and a teimz 4 only killin when nobodys lookin. u get teh picture. — Ecclesiastes 3:1-8

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', .[2], .[1];
}

(Also available syntax-highlighted here.)

I wish to thank The Perl Foundation for sponsoring the Web.pm effort.