> sub bulk_insert {
>   my ($self, $table, $records, $options) = @_;
>   my ($stmt) = $self->pg->abstract->insert($table, $records->[0], 
> $options);
>   eval {
>     my $tx = $self->pg->db->begin;
>     my $i = $self->pg->db->dbh->prepare($stmt);
>     while ( my $next = shift @$records ) {
>       $i->execute(@$next{sort keys %$next});
>     }
>     $tx->commit;
>   };
>   return $@ if $@;
> }
There's a lot wrong with this. You should hold on to $db objects, there's a 
pool of connections in
Mojo::Pg. Manual prepare/execute is pointless, Mojo::Pg::Database has a 
transparent statement
handle cache, once you hold on to the $db object you get caching for free 
without having to do
anything. Just pass the same data structure to ->insert or same SQL to 
->query and you're done.


You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mojolicious+unsubscr...@googlegroups.com.
To post to this group, send email to mojolicious@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to