Skip to content

Instantly share code, notes, and snippets.

View SysPete's full-sized avatar

Peter Mottram SysPete

View GitHub Profile
@SysPete
SysPete / R::TaxZone.pm
Created March 27, 2014 20:34
old TaxZone.pm
use utf8;
package Interchange6::Schema::Result::TaxRule;
=head1 NAME
Interchange6::Schema::Result::TaxRule
=cut
use strict;
use warnings;
use Test::More;
use Test::DBIx::Class {
schema_class => 'Interchange6::Schema',
traits => 'Testpostgresql',
resultsets => [ qw/ Order User / ],
};
any [ 'get', 'post' ] => '/checkout' => require_login sub {
return forward 404 if config->{shop_disabled};
return redirect '/cart' if cart->count == 0;
my ( $data, $form, $form_last, $forms_ref, $params );
my $posted = 1;
@SysPete
SysPete / gist:b8c3c0e13d02b307de06
Last active August 29, 2015 14:06
overloading Interchange6 schema result classes
use utf8;
package Interchange6::Schema;
use strict;
use warnings;
use base 'DBIx::Class::Schema';
use Interchange6::Schema::Result::Order;
use Interchange6::Schema::Result::Product;
@SysPete
SysPete / Schema.pm
Created September 30, 2014 08:44
switch password to simple Digest
package Interchange6::Schema;
use strict;
use warnings;
use base 'DBIx::Class::Schema';
use Interchange6::Schema::Result::User;
Interchange6::Schema::Result::User->load_components(
SELECT product.sku, product.name, product.short_description, product.description, product.price
, product.uri, product.weight, product.priority, product.gtin, product.canonical_sku
, product.active, product.inventory_exempt, product.created, product.last_modified
, price_modifier.selling_price
FROM navigation_products me
JOIN products product
ON product.sku = me.sku
LEFT JOIN ( SELECT me.sku, MIN (me.price) AS selling_price
FROM price_modifiers me
LEFT JOIN roles role ON role.roles_id = me.roles_id
@SysPete
SysPete / gist:c12774af596d8725dce2
Created December 11, 2014 13:53
PostgreSQL Dancer::Plugin::DBIC example config
plugins:
DBIC:
default:
dsn: dbi:Pg:dbname=danceshop
user: dancepower
password: dancethenightaway
schema_class: Interchange6::Schema
options:
RaiseError: 1
PrintError: 1
@SysPete
SysPete / gist:62e9dd7263770c7cc0a9
Last active August 29, 2015 14:11
fixup Address::state relationship which should be left join in Schema.pm
use utf8;
package Interchange6::Schema;
use strict;
use warnings;
use base 'DBIx::Class::Schema';
use Interchange6::Schema::Result::Address;
@SysPete
SysPete / gist:51b8cbe797ea325d27d9
Created December 16, 2014 13:16
join on navigations, navigation_products, products, price_modifiers, products_reviews and messages
SELECT products.sku, products.name, products.uri, products.price, products.short_description,
COALESCE( MIN( price_modifiers.price ), products.price ) AS selling_price,
ROUND (( products.price - MIN( price_modifiers.price ) )
/ products.price * 100 - 0.5 ) AS discount_percent,
ROUND( AVG ( messages.rating ), 1 ) AS rating,
inventories.quantity AS inventory
FROM navigations navigation
JOIN navigation_products
ON navigation.navigation_id = navigation_products.navigation_id
JOIN products
@SysPete
SysPete / dev.pl
Created December 31, 2014 11:43
dev.pl for using querylog middleware
#!/usr/bin/env perl
use Plack::Builder;
use Plack::Middleware::Debug::DBIC::QueryLog;
use Plack::Middleware::DBIC::QueryLog;
use Dancer;
use Dancer::Plugin::DBIC;
use Dancer::Handler;
use lib 'lib';
use DanceShop;