fREWdiculous!
20 Sep
Thanks to arcanez, my color coding SQL Logging has been merged into DBIC’s master!
That means you can easily try out the new color coding! All you need to do to try it out is clone our master from git:
1 | git clone git://git.shadowcat.co.uk/dbsrgits/DBIx-Class.git |
Make sure you install any new deps. The main one will be SQL::Abstract 1.68.
1 | cpanm --installdeps . |
And then use that as your lib directory when you run your server or whatever:
1 | perl -I ~/DBIx-Class/lib scripts/foo_server.pl -rd |
Now, you won’t notice a difference till you set the DBIC_TRACE_PROFILE variable. It sets the color profile to use. If you are on Linux and install the ANSIColor package, you probably want to set it to “console”. If you are in win32 or do no want to install ANSIColor, set it to “console_monochrome”. Both profiles fill in placeholders for you, for excellent readability, so that’s extremely helpful.
If you would like to make a nicer colorscheme, or more importantly want to use modern 256 color consoles, feel free! The documentation for that is available at SQL::Abstract::Tree. The best way to define one of those is to make a json file (I do ~/dbic.json) and populate it with the profile information you like, and then set DBIC_TRACE_PROFILE to the full path of the file. That way you can experiment with various profiles and when you think you have one that’s worth sharing, send it to me and I’ll probably merge it in!
Anyway, we hope to cut a new release in a week or two, with lots of other great new stuff, so feel free to wait if you’d prefer.
6 Sep
Recently I read a post by ovid where he shows color coding SQL on test failures. I really wanted to steal his code for DBIx::Class‘s trace output. For MSSQL it would be especially helpful since our pagination involves two subqueries. ribasushi had pointed out in the past that all we need to do this (and do it correctly) was to refactor a bit of the test code and we’d have a proper parser and deparser.
Anyway, I got it into a state that I think is actually quite usable! Currently it’s in a dev release (1.67_01) of SQL::Abstract because we want to iron out any interface issues before blessing it. It’s also a little bit of a hassle to use at this point, but that will get worked out when it’s cored. To use it, just put the following in your MyApp::Schema:
1 2 3 4 5 6 7 8 9 10 11 12 | use DBIx::Class::Storage::PrettyPrinter; my $pp = DBIx::Class::Storage::PrettyPrinter->new({ profile => 'console' }); sub connection { my $self = shift; my $ret = $self->next::method(@_); $self->storage->debugobj($pp); $ret } |
Now if you set DBIC_TRACE you’ll get color-coded, indented, correctly nesting sql!
If you want to install it the easy way use App::CPAN::Fresh as follows:
1 | cpanf -dmi SQL::Abstract |
And lastly, but arguably most importantly, a screenshot.
It’s certainly not perfect, I’d like to add some kind of width parameter so that it wraps more nicely. There are lots of configurable bits that aren’t documented yet; at some point I’ll get that taken care of. Anyway, enjoy!