Skip to content

Instantly share code, notes, and snippets.

@kmcgrath
Created August 20, 2011 17:59
Show Gist options
  • Select an option

  • Save kmcgrath/1159414 to your computer and use it in GitHub Desktop.

Select an option

Save kmcgrath/1159414 to your computer and use it in GitHub Desktop.
SimpleDB::Class with Decimal type
# Working on adding decimal type to SimpleDB::Class
# https://github.com/kmcgrath/SimpleDB-Class
package SDBTest;
use Moose;
use lib '/home/kmcgrath/SimpleDB-Class/lib';
extends 'SimpleDB::Class';
__PACKAGE__->load_namespaces();
1;
package SDBTest::Item;
use Moose;
extends 'SimpleDB::Class::Item';
__PACKAGE__->set_domain_name('sdbtest');
__PACKAGE__->add_attributes(
title => { isa => 'Str', default => 'Untitled' },
price => { isa => 'Decimal'},
quantity => { isa => 'Int' },
);
1;
package main;
use 5.010;
use DateTime;
import SDBTest;
use Getopt::Std;
our ($opt_a, $opt_s);
getopt('a:s:');
my $sdb = SDBTest->new(access_key => $opt_a, secret_key => $opt_s, cache_servers => [{ host => '127.0.0.1', port=> '11211' }] );
$sdb->domain('sdbtest')->create;
$sdb->domain('sdbtest')->insert(
{
title => 'Test 1',
price => 1.75,
quantity => 1
}
);
$sdb->domain('sdbtest')->insert(
{
title => 'Test 2',
price => 10.75,
quantity => 10
}
);
$sdb->domain('sdbtest')->insert(
{
title => 'Test 3',
price => 2.33,
quantity => 2
}
);
$sdb->domain('sdbtest')->insert(
{
title => 'Test 4',
price => 20.87,
quantity => 20
}
);
sleep 2;
print "All items by price\n";
print "------------------\n";
print_items(
$sdb->domain('sdbtest')->search(where=>{-intersection => { price => 'is not null' } }, order_by=>'price' )
);
print 'Items that cost more than $1.75'."\n";
print "-------------------------------\n";
print_items(
$sdb->domain('sdbtest')->search(where=>{price => [ '>', 1.75] }, order_by=>'price' )
);
print "Items whose quantity is more than 10\n";
print "------------------------------------\n";
print_items(
$sdb->domain('sdbtest')->search(where=>{price => [ '>=', 10] }, order_by=>'price' )
);
sub print_items {
my $items = shift;
while (my $item = $items->next) {
print $item->title . "\n";
print $item->price . "\n";
print $item->quantity . "\n";
print "\n\n";
}
}
$sdb->domain('sdbtest')->delete;
@kmcgrath
Copy link
Author

First time using Gist = First bonehead mistake

Left AWS keys in code. IDIOT.

Luckily no harm done. Removed and Deactivated keys. Command line params now.

Filed under, always read what you post, dummy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment