Changeset 8255 for lang/perl/Catalyst-Model-Jifty-DBI/trunk/lib/Catalyst
- Timestamp:
- 03/21/08 21:33:57 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Catalyst-Model-Jifty-DBI/trunk/lib/Catalyst/Model/Jifty/DBI.pm
r2067 r8255 6 6 use base qw( Catalyst::Model Class::Accessor::Fast ); 7 7 8 our $VERSION = '0.0 3';8 our $VERSION = '0.04'; 9 9 10 10 use NEXT; … … 206 206 sub simple_query { shift->handle->simple_query( @_ ) } 207 207 sub fetch_result { shift->handle->fetch_result( @_ ) } 208 209 sub trace { 210 my ($self, $code) = @_; 211 212 if ( ref $code eq 'CODE' ) { 213 $self->handle->log_sql_statements(1); 214 $self->handle->log_sql_hook( trace => $code ); 215 } 216 elsif ( $code ) { 217 require Data::Dump; 218 $self->handle->log_sql_statements(1); 219 $self->handle->log_sql_hook( 220 trace => sub { print STDERR Data::Dump::dump(@_) } 221 ); 222 } 223 else { 224 $self->handle->log_sql_statements(0); 225 } 226 } 208 227 209 228 1; … … 307 326 ->simple_query( $sql_statement, @binds ); 308 327 328 When you want to debug (against the default handle): 329 330 $c->model('JDBI')->trace(1); # start logging 331 $c->model('JDBI')->trace(0); # stop logging 332 309 333 =head1 BACKWARD INCOMPATIBILITY 310 334 … … 335 359 =head2 new 336 360 337 creates a model. Database connection may be ornot be prepared, according to the number of connect_info. See above for the configuration.361 creates a model. Database connection may or may not be prepared, according to the number of connect_info. See above for the configuration. 338 362 339 363 =head2 record … … 365 389 =head2 collection 366 390 367 creates and returns a corresponding (new) Jifty::DBI::Collection object. If you haven't created a Collection class but only a Schema/Record class, this model creates a plain Collection class on the fly. I recommend not to omit the obvious 'Collection' part of the class name, but if you prefer, you can spare that partwhen you explicitly call model("Model")->collection("Schema") (you can't omit if you follow the model("Model::Schema") convention). Other general usage and caveats are the same as ->record.391 creates and returns a corresponding (new) Jifty::DBI::Collection object. If you haven't created a Collection class but only a Schema/Record class, this model creates a plain Collection class on the fly. I recommend not to omit the obvious 'Collection' part of the class name, but if you prefer, you can spare that when you explicitly call model("Model")->collection("Schema") (you can't omit if you follow the model("Model::Schema") convention). Other general usage and caveats are the same as ->record. 368 392 369 393 # this works. … … 465 489 This also is a shortcut to ->handle->disconnect. You can pass an optional hash to specify target database. 466 490 491 =head2 trace 492 493 turns on and off the logging of sql statements. If this is set to true, C::M::Jifty::DBI spits the info to STDERR. If you want finer control, give it a code reference. 494 495 $c->model('JDBI')->trace(sub { 496 my ($time, $statement, $binding, $duration, $result) = @_; 497 warn $statement, "\n", @$binding; 498 }); 499 500 See L<Jifty::DBI::Handle> for details (log_sql_hook / sql_statement_log). 501 467 502 =head1 SEE ALSO 468 503
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)