📄 dbd::gofer.3
字号:
like to use it. You do that my adding a \f(CW\*(C`go_last_insert_id_args\*(C'\fR attribute tothe \fIdo()\fR or \fIprepare()\fR method calls. For example:.PP.Vb 1\& $dbh\->do($sql, { go_last_insert_id_args => [...] });.Ve.PPor.PP.Vb 1\& $sth = $dbh\->prepare($sql, { go_last_insert_id_args => [...] });.Ve.PPThe array reference should contains the args that you want passed to the\&\fIlast_insert_id()\fR method..Sh "execute_for_fetch".IX Subsection "execute_for_fetch"The array methods \fIbind_param_array()\fR and \fIexecute_array()\fR are supported.When \fIexecute_array()\fR is called the data is serialized and executed in a singleround-trip to the Gofer server. This makes it very fast, but requires enoughmemory to store all the serialized data..PPThe \fIexecute_for_fetch()\fR method currently isn't optimised, it uses the \s-1DBI\s0fallback behaviour of executing each tuple individually.(It could be implemented as a wrapper for \fIexecute_array()\fR \- patches welcome.).SH "TRANSPORTS".IX Header "TRANSPORTS"DBD::Gofer doesn't concern itself with transporting requests and responses to and fro.For that it uses special Gofer transport modules..PPGofer transport modules usually come in pairs: one for the 'client' DBD::Goferdriver to use and one for the remote 'server' end. They have very similar names:.PP.Vb 2\& DBD::Gofer::Transport::<foo>\& DBI::Gofer::Transport::<foo>.Ve.PPSometimes the transports on the \s-1DBD\s0 and \s-1DBI\s0 sides may have different names. Forexample DBD::Gofer::Transport::http is typically used with DBI::Gofer::Transport::mod_perl(DBD::Gofer::Transport::http and DBI::Gofer::Transport::mod_perl modules arepart of the GoferTransport-http distribution)..Sh "Bundled Transports".IX Subsection "Bundled Transports"Several transport modules are provided with DBD::Gofer:.PP\fInull\fR.IX Subsection "null".PPThe null transport is the simplest of them all. It doesn't actually transport the request anywhere.It just serializes (freezes) the request into a string, then thaws it back intoa data structure before passing it to DBI::Gofer::Execute to execute. The samefreeze and thaw is applied to the results..PPThe null transport is the best way to test if your application will work with Gofer.Just set the \s-1DBI_AUTOPROXY\s0 environment variable to "\f(CW\*(C`dbi:Gofer:transport=null;policy=pedantic\*(C'\fR"(see \*(L"Using \s-1DBI_AUTOPROXY\s0\*(R" below) and run your application, or ideally its test suite, as usual..PPIt doesn't take any parameters..PP\fIpipeone\fR.IX Subsection "pipeone".PPThe pipeone transport launches a subprocess for each request. It passes in therequest and reads the response..PPThe fact that a new subprocess is started for each request ensures that theserver side is truly stateless. While this does make the transport \fIvery\fR slow,it is useful as a way to test that your application doesn't depend onper-connection state, such as temporary tables, persisting between requests..PPIt's also useful both as a proof of concept and as a base class for the streamdriver..PP\fIstream\fR.IX Subsection "stream".PPThe stream driver also launches a subprocess and writes requests and readsresponses, like the pipeone transport. In this case, however, the subprocessis expected to handle more that one request. (Though it will be automiticallyrestarted if it exits.).PPThis is the first transport that is truly useful because it can launch thesubprocess on a remote machine using \f(CW\*(C`ssh\*(C'\fR. This means you can now use DBD::Goferto easily access any databases that's accessible from any system you can login to.You also get all the benefits of ssh, including encryption and optional compression..PPSee \*(L"Using \s-1DBI_AUTOPROXY\s0\*(R" below for an example..Sh "Other Transports".IX Subsection "Other Transports"Implementing a Gofer transport is \fIvery\fR simple, and more transports are very welcome.Just take a look at any existing transports that are similar to your needs..PP\fIhttp\fR.IX Subsection "http".PPSee the GoferTransport-http distribution on \s-1CPAN:\s0 http://search.cpan.org/dist/GoferTransport\-http/.PP\fIGearman\fR.IX Subsection "Gearman".PPI know Ask Bjo\*/rn Hansen has implemented a transport for the \f(CW\*(C`gearman\*(C'\fR distributedjob system, though it's not on \s-1CPAN\s0 at the time of writing this..SH "CONNECTING".IX Header "CONNECTING"Simply prefix your existing \s-1DSN\s0 with "\f(CW\*(C`dbi:Gofer:transport=$transport;dsn=\*(C'\fR"where \f(CW$transport\fR is the name of the Gofer transport you want to use (see \*(L"\s-1TRANSPORTS\s0\*(R").The \f(CW\*(C`transport\*(C'\fR and \f(CW\*(C`dsn\*(C'\fR attributes must be specified and the \f(CW\*(C`dsn\*(C'\fR attributes must be last..PPOther attributes can be specified in the \s-1DSN\s0 to configure DBD::Gofer and/or theGofer transport module being used. The main attributes after \f(CW\*(C`transport\*(C'\fR, are\&\f(CW\*(C`url\*(C'\fR and \f(CW\*(C`policy\*(C'\fR. These and other attributes are described below..Sh "Using \s-1DBI_AUTOPROXY\s0".IX Subsection "Using DBI_AUTOPROXY"The simplest way to try out DBD::Gofer is to set the \s-1DBI_AUTOPROXY\s0 environment variable.In this case you don't include the \f(CW\*(C`dsn=\*(C'\fR part. For example:.PP.Vb 1\& export DBI_AUTOPROXY="dbi:Gofer:transport=null".Ve.PPor, for a more useful example, try:.PP.Vb 1\& export DBI_AUTOPROXY="dbi:Gofer:transport=stream;url=ssh:user@example.com".Ve.Sh "Connection Attributes".IX Subsection "Connection Attributes"These attributes can be specified in the \s-1DSN\s0. They can also be passed in the\&\e%attr parameter of the \s-1DBI\s0 connect method by adding a "\f(CW\*(C`go_\*(C'\fR" prefix to the name..PP\fItransport\fR.IX Subsection "transport".PPSpecifies the Gofer transport class to use. Required. See \*(L"\s-1TRANSPORTS\s0\*(R" above..PPIf the value does not include \f(CW\*(C`::\*(C'\fR then "\f(CW\*(C`DBD::Gofer::Transport::\*(C'\fR" is prefixed..PPThe transport object can be accessed via \f(CW$h\fR\->{go_transport}..PP\fIdsn\fR.IX Subsection "dsn".PPSpecifies the \s-1DSN\s0 for the remote side to connect to. Required, and must be last..PP\fIurl\fR.IX Subsection "url".PPUsed to tell the transport where to connect to. The exact form of the value depends on the transport used..PP\fIpolicy\fR.IX Subsection "policy".PPSpecifies the policy to use. See \*(L"\s-1CONFIGURING\s0 \s-1BEHAVIOUR\s0 \s-1POLICY\s0\*(R"..PPIf the value does not include \f(CW\*(C`::\*(C'\fR then "\f(CW\*(C`DBD::Gofer::Policy\*(C'\fR" is prefixed..PPThe policy object can be accessed via \f(CW$h\fR\->{go_policy}..PP\fItimeout\fR.IX Subsection "timeout".PPSpecifies a timeout, in seconds, to use when waiting for responses from the server side..PP\fIretry_limit\fR.IX Subsection "retry_limit".PPSpecifies the number of times a failed request will be retried. Default is 0..PP\fIretry_hook\fR.IX Subsection "retry_hook".PPSpecifies a code reference to be called to decide if a failed request should be retried.The code reference is called like this:.PP.Vb 2\& $transport = $h\->{go_transport};\& $retry = $transport\->go_retry_hook\->($request, $response, $transport);.Ve.PPIf it returns true then the request will be retried, upto the \f(CW\*(C`retry_limit\*(C'\fR.If it returns a false but defined value then the request will not be retried.If it returns undef then the default behaviour will be used, as if \f(CW\*(C`retry_hook\*(C'\fRhad not been specified..PPThe default behaviour is to retry requests where \f(CW$request\fR\->is_idempotent is true,or the error message matches \f(CW\*(C`/induced by DBI_GOFER_RANDOM/\*(C'\fR..PP\fIcache\fR.IX Subsection "cache".PPSpecifies that client-side caching should be performed. The value is the nameof a cache class to use..PPAny class implementing get($key) and set($key, \f(CW$value\fR) methods can be used.That includes a great many powerful caching classes on \s-1CPAN\s0, including theCache and Cache::Cache distributions..PPYou can use "\f(CW\*(C`cache=1\*(C'\fR\*(L" is a shortcut for \*(R"\f(CW\*(C`cache=DBI::Util::CacheMemory\*(C'\fR".See DBI::Util::CacheMemory for a description of this simple fast default cache..PPThe cache object can be accessed via \f(CW$h\fR\->go_cache. For example:.PP.Vb 1\& $dbh\->go_cache\->clear; # free up memory being used by the cache.Ve.PPThe cache keys are the frozen (serialized) requests, and the values are thefrozen responses..PPThe default behaviour is to only use the cache for requests where\&\f(CW$request\fR\->is_idempotent is true (i.e., the dbh has the ReadOnly attribute setor the \s-1SQL\s0 statement is obviously a \s-1SELECT\s0 without a \s-1FOR\s0 \s-1UPDATE\s0 clause.).PPFor even more control you can use the \f(CW\*(C`go_cache\*(C'\fR attribute to pass in aninstanciated cache object. Individual methods, including \fIprepare()\fR, can alsospecify alternative caches via the \f(CW\*(C`go_cache\*(C'\fR attribute. For example, tospecify no caching for a particular query, you could use.PP.Vb 1\& $sth = $dbh\->prepare( $sql, { go_cache => 0 } );.Ve.PPThis can be used to implement different caching policies for different statements..PPIt's interesting to note that DBD::Gofer can be used to add client-side cachingto any (gofer compatible) application, with no code changes and no need for agofer server. Just set the \s-1DBI_AUTOPROXY\s0 environment variable like this:.PP.Vb 1\& DBI_AUTOPROXY=\*(Aqdbi:Gofer:transport=null;cache=1\*(Aq.Ve.SH "CONFIGURING BEHAVIOUR POLICY".IX Header "CONFIGURING BEHAVIOUR POLICY"DBD::Gofer supports a 'policy' mechanism that allows you to fine-tune the number of round-trips to the Gofer server.The policies are grouped into classes (which may be subclassed) and referenced by the name of the class..PPThe DBD::Gofer::Policy::Base class is the base class for all the policypackages and describes all the available policies..PPThree policy packages are supplied with DBD::Gofer:.PPDBD::Gofer::Policy::pedantic is most 'transparent' but slowest because itmakes more round-trips to the Gofer server..PPDBD::Gofer::Policy::classic is a reasonable compromise \- it's the default policy..PPDBD::Gofer::Policy::rush is fastest, but may require code changes in your applications..PPGenerally the default \f(CW\*(C`classic\*(C'\fR policy is fine. When first testing an existingapplication with Gofer it is a good idea to start with the \f(CW\*(C`pedantic\*(C'\fR policyfirst and then switch to \f(CW\*(C`classic\*(C'\fR or a custom policy, for final testing..SH "AUTHOR".IX Header "AUTHOR"Tim Bunce, <http://www.tim.bunce.name>.SH "LICENCE AND COPYRIGHT".IX Header "LICENCE AND COPYRIGHT"Copyright (c) 2007, Tim Bunce, Ireland. All rights reserved..PPThis module is free software; you can redistribute it and/ormodify it under the same terms as Perl itself. See perlartistic..SH "ACKNOWLEDGEMENTS".IX Header "ACKNOWLEDGEMENTS"The development of DBD::Gofer and related modules was sponsored byShopzilla.com (<http://Shopzilla.com>), where I currently work..SH "SEE ALSO".IX Header "SEE ALSO"DBI::Gofer::Request, DBI::Gofer::Response, DBI::Gofer::Execute..PPDBI::Gofer::Transport::Base, DBD::Gofer::Policy::Base..PP\&\s-1DBI\s0.SH "Caveats for specific drivers".IX Header "Caveats for specific drivers"This section aims to record issues to be aware of when using Gofer with specific drivers.It usually only documents issues that are not natural consequences of the limitationsof the Gofer approach \- as documented avove..SH "TODO".IX Header "TODO"This is just a random brain dump... (There's more in the source of the Changes file, not the pod).PPDocument policy mechanism.PPAdd mechanism for transports to list config params and for Gofer to apply any that match (and warn if any left over?).PPDriver-private sth attributes \- set via \fIprepare()\fR \- change \s-1DBI\s0 spec.PPadd hooks into transport base class for checking & updating a result set cache ie via a standard cache interface such as: http://search.cpan.org/~robm/Cache\-FastMmap/FastMmap.pm http://search.cpan.org/~bradfitz/Cache\-Memcached/lib/Cache/Memcached.pm http://search.cpan.org/~dclinton/Cache\-Cache/ http://search.cpan.org/~cleishman/Cache/Also caching instructions could be passed through the httpd transport layerin such a way that appropriate http cache headers are added to the resultsso that web caches (squid etc) could be used to implement the caching.(\s-1MUST\s0 require the use of \s-1GET\s0 rather than \s-1POST\s0 requests.).PPRework handling of installed_methods to not piggback on dbh_attributes?.PPPerhaps support transactions for transports where it's possible (ie null and stream)?Would make stream transport (ie ssh) more useful to more people..PPMake sth_result_attr more like dbh_attributes (using '*' etc).PPAdd \f(CW@val\fR = FETCH_many(@names) to \s-1DBI\s0 in C and use in Gofer/Execute?.PPImplement _new_sth in C.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -