1 |
package Frey::SQL; |
package Frey::SQL; |
2 |
use Moose; |
use Moose; |
3 |
|
extends 'Frey'; |
4 |
|
|
5 |
use MooseX::Types::Moose qw(Str Int ArrayRef); |
with 'Frey::Web'; |
|
use MooseX::Types::Structured qw/Dict/; |
|
6 |
|
|
7 |
use DBI; |
use DBI; |
8 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
9 |
|
|
10 |
|
with 'Frey::Sponge'; # has sponge |
11 |
|
|
12 |
has 'query' => ( |
has 'query' => ( |
13 |
is => 'rw', |
is => 'rw', |
14 |
isa => 'Str', |
isa => 'Str', |
15 |
required => 1, |
required => 1, |
16 |
default => 'select * from sponge', |
default => 'select * from sponge', |
17 |
|
documentation => 'SQL query to filter data', |
18 |
); |
); |
19 |
|
|
20 |
has table => ( |
has table => ( |
22 |
isa => 'Str', |
isa => 'Str', |
23 |
required => 1, |
required => 1, |
24 |
default => 'sponge', |
default => 'sponge', |
25 |
|
documentation => 'Name of table to create from sponge data', |
26 |
); |
); |
27 |
|
|
28 |
has 'sponge' => ( |
sub as_data { |
|
is => 'rw', |
|
|
isa => Dict[ |
|
|
rows => ArrayRef[ArrayRef], |
|
|
NAME => ArrayRef[Str], |
|
|
], |
|
|
required => 1, |
|
|
); |
|
|
|
|
|
sub data { |
|
29 |
my ($self) = @_; |
my ($self) = @_; |
30 |
|
|
31 |
my $dbh=DBI->connect('dbi:AnyData(RaiseError=>1):'); |
my $dbh=DBI->connect('dbi:AnyData(RaiseError=>1):'); |
32 |
|
|
|
|
|
|
|
|
33 |
my $data = $self->sponge->{rows}; |
my $data = $self->sponge->{rows}; |
34 |
unshift @$data, $self->sponge->{NAME}; |
unshift @$data, $self->sponge->{NAME}; |
35 |
|
|
36 |
warn "# data = ",dump( $data ); |
warn "# data = ",dump( $data ) if $self->debug; |
37 |
|
|
38 |
$dbh->func( $self->table, 'ARRAY', $data, 'ad_import' ); |
$dbh->func( $self->table, 'ARRAY', $data, 'ad_import' ); |
39 |
|
|