Last active
January 18, 2017 08:12
-
-
Save msouth/f1529624c700da9639e42c70bea1903a to your computer and use it in GitHub Desktop.
quick test of inflate/deflate stuff using column filter in DBIX::Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`) ); ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./drop_and_create_table.sh | |
perl make_schema.pl | |
./add_inflate_snippet.sh | |
perl test_deflate.pl | |
mysql test -e 'select * from test_deflate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ], | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chmod +x *.sh
./go.sh