Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Mojo - Prepare cached query

by tobyink (Canon)
on Mar 03, 2020 at 13:37 UTC ( [id://11113702]=note: print w/replies, xml ) Need Help??


in reply to Mojo - Prepare cached query

I've not really used Mojo, but I think you probably want something like this...

app->attr(dbh => sub { my $self = shift; my $dsn = 'dbi:Oracle:schema'; my $usr = 'Scott'; my $pas = 'tiger'; my $dbh = DBI->connect_cached( $dsn, $usr, $pas ); return $dbh; }); app->attr(cached_query => sub { my $self = shift; my $sql = 'SQL QUERY HERE'; return $self->dbh->prepare_cached( $sql ); }); # later get '/query' => sub{ my $c = shift; my $dbh = $c->app->dbh; my $sth = $c->app->cached_query; # probably pull @values out from GET query or POST data my @values = do { ... }; my $results = $dbh->selectall_arrayref($sth, {}, @values); # and so on };

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11113702]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-04-16 16:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found