3 use base qw(Gearman::Driver::Worker);
6 use Data::Dump qw(dump);
11 sub prefix { 'Store_' }
14 my ( $self, $orig, $job_name ) = @_;
15 warn "# process_name $orig $job_name\n";
16 return "$orig ($job_name)";
20 DBI->connect_cached('DBI:Pg:dbname=apkpm','','', {
27 my ( $self, $table, $h ) = @_;
32 my $sql = "INSERT INTO $table (" . join(',',@c) . ') values (' . join(',', map { '?' } 0 .. $#c) . ')';
34 my $sth = $self->dbh->prepare($sql);
35 $sth->execute( map { $h->{$_} } @c );
38 sub insert : Job : Decode(d_json) {
39 my ( $self, $job, $workload ) = @_;
40 my $table = delete $workload->{_table} || die "no _table";
41 $self->pg_insert($table => $workload);
44 sub sql : Job : Encode(e_json) {
45 my ( $self, $job, $workload ) = @_;
47 my $sth = $self->dbh->prepare($workload);
48 my $rows = eval { $sth->execute };
49 return { error => $@ } if $@;
51 warn "# $rows rows get_username_table $workload\n";
54 columns => $sth->{NAME},
55 rows => $sth->fetchall_arrayref,