Giter VIP home page Giter VIP logo

plack-middleware-dbic-querylog's Introduction

NAME

Plack::Middleware::DBIC::QueryLog - Expose a DBIC QueryLog Instance in Middleware

SYNOPSIS

use Plack::Builder;
builder {
  enable 'DBIC::QueryLog',
    querylog_args => {passthrough => 1};
  $app;
};

DESCRIPTION

Plack::Middleware::DBIC::QueryLog does one thing, it places an object that is either an instance of DBIx::Class::QueryLog OR a compatible object into the $env under plack.middleware.dbic.querylog. A new instance is created for each incoming request.

The querylog is intended to be used by DBIX::Class to log and profile SQL queries, particularly during the context of a web request handled by your Plack application. See the documentation for DBIx::Class::QueryLog and in LDBIx::Class::Storage/debugobj for more information.

This middleware is intended to act as a bridge between DBIx::Class, which can consume and populate the querylog, with a reporting tool such as seen in Plack::Middleware::Debug::DBIC::QueryLog. This functionality was refactored out of Plack::Middleware::Debug::DBIC::QueryLog to facilitate interoperation with other types of reporting tools. For example, you may want query logging but you don't need the Plack debug panels (maybe you are building an RPC or REST application server and want sql query logging, is a possible use case).

Unless you are building some custom logging tools, you probably just want to use the existing debug panel (Plack::Middleware::Debug::DBIC::QueryLog) rather than building something custom around this middleware.

If you are using an existing web application development system such as Catalyst, you can use Catalyst::TraitFor::Model::DBIC::Schema::QueryLog::AdoptPlack to 'hook' the query log into your DBIx::Class schema model. If you are using a different framework, or building your own, please consider releasing your code or sending me a document patch suitable for including in a workbook or FAQ.

ARGUMENTS

This middleware accepts the following arguments.

querylog_class

This is the class which is used to build the querylog unless one is already defined. It defaults to DBIx::Class::QueryLog. You should probably leave this alone unless you need to subclass or augment DBIx::Class::QueryLog.

If the class name you pass has not already been included (via use or require) we will automatically try to require it.

querylog_args

Accepts a HashRef of data which will be passed to "querylog_class" when building the querylog.

SUBROUTINES

This middleware defines the following public subroutines

PSGI_KEY

Returns the PSGI $env key under which you'd expect to find an instance of DBIx::Class::QueryLog.

get_querylog_from_env

Given a Plack $env, returns a DBIx::Class::QueryLog, if one exists. You should use this in your code that is trying to access the querylog. For example:

use Plack::Middleware::DBIC::QueryLog;

sub get_querylog_from_env {
  my ($self, $env) = @_;
  Plack::Middleware::DBIC::QueryLog->get_querylog_from_env($env);
}

This returns undef if it does not exist. This is the officially supported interface for extracting a DBIx::Class::QueryLog from a Plack request.

SEE ALSO

Plack, Plack::Middleware, Plack::Middleware::Debug::DBIC::QueryLog, Catalyst::TraitFor::Model::DBIC::Schema::QueryLog::AdoptPlack

AUTHOR

John Napiorkowski, <[email protected]>

COPYRIGHT & LICENSE

Copyright 2011, John Napiorkowski

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

plack-middleware-dbic-querylog's People

Contributors

jjn1056 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.