Skip to content

Instantly share code, notes, and snippets.

@msouth
Last active January 18, 2017 08:12
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 msouth/f1529624c700da9639e42c70bea1903a to your computer and use it in GitHub Desktop.
Save msouth/f1529624c700da9639e42c70bea1903a to your computer and use it in GitHub Desktop.
quick test of inflate/deflate stuff using column filter in DBIX::Class
perl -ni -e '$cutting = 1 if /#.*start_inflate/; print unless ($cutting or $_=~/\s*1;\s*/); $cutting = 0 if /#.*end_inflate/;' lib/Test/Schema/Result/TestDeflate.pm
cat inflate_snippet.pl >> lib/Test/Schema/Result/TestDeflate.pm
mysql test -e 'DROP TABLE IF EXISTS `test_deflate`; CREATE TABLE `test_deflate` ( `id` int(11) NOT NULL auto_increment, `name` varchar(31) DEFAULT NULL, PRIMARY KEY (`id`) ); '
./drop_and_create_table.sh
perl make_schema.pl
./add_inflate_snippet.sh
perl test_deflate.pl
mysql test -e 'select * from test_deflate'
# start_inflate
__PACKAGE__->load_components(qw( FilterColumn ));
__PACKAGE__->filter_column( name => {
filter_from_storage => sub {
my $db_data = $_[1];
warn "look at me, I'm inflating [$db_data] to uc!!!!";
return uc $db_data,
},
filter_to_storage => sub {
my $user_data = $_[1];
warn "look at me, I'm deflating [$user_data] to lc!!!!";
return lc $user_data;
},
});
# end_inflate
1;
use DBIx::Class::Schema::Loader qw/ make_schema_at /;
make_schema_at (
'Test::Schema',
{
use_namespaces => 1,
dump_directory => './lib',
},
[ 'dbi:mysql:test;host=admin03' ],
);
use strict;
use lib './lib';
use Test::Schema;
my $schema = Test::Schema->connection('dbi:mysql:dbname=test');
my $get_one = sub {
my $td = $schema->resultset('TestDeflate')->search(
{
id=>'1',
},
{
order_by => "id DESC",
rows => 1,
}
)->single;
return $td;
};
my $td = $get_one->();
unless ($td) {
my $new_guy = $schema->resultset('TestDeflate')->new( {id=>1, name=>'TEST AT '.scalar localtime time()} )->insert();
$td = $get_one->();
}
$td->name('TEST_THIS '.scalar localtime time());
$td->update();
@msouth
Copy link
Author

msouth commented Jan 18, 2017

chmod +x *.sh
./go.sh

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