use
5.010_001;
ro
=> [
qw/row ctx/
],
);
use
version;
our
$VERSION
=
'v0.1.2'
;
{
no
strict
'refs'
;
for
my
$column
(
qw/job_id number run_host run_pid/
) {
*{ __PACKAGE__ .
'::'
.
$column
} =
sub
{
my
$self
=
shift
;
$self
->row->
$column
;
};
}
for
my
$column
(
qw/created_on run_date updated_at/
) {
*{ __PACKAGE__ .
'::'
.
$column
} =
sub
{
my
$self
=
shift
;
DateTime::Format::MySQL->parse_datetime(
$self
->row->
$column
)
->set_time_zone(
$self
->ctx->config->time_zone);
};
}
}
sub
new {
args(
my
$class
,
my
$row
=>
'Teng::Row'
,
my
$ctx
=>
'App::Koyomi::Context'
,
);
bless
+{
row
=>
$row
,
ctx
=>
$ctx
,
},
$class
;
}
sub
update_with_condition {
args(
my
$self
,
my
$data
=>
'HashRef'
,
my
$where
=>
'HashRef'
,
);
my
$teng
=
$self
->row->handle;
my
%stash
=
%$data
;
my
%cond
=
%$where
;
for
my
$col
(
qw/created_on run_date updated_at/
) {
if
(
$data
->{
$col
}) {
$stash
{
$col
} = DateTime::Format::MySQL->format_datetime(
$data
->{
$col
});
}
if
(
$where
->{
$col
}) {
$cond
{
$col
} = DateTime::Format::MySQL->format_datetime(
$where
->{
$col
});
}
}
my
$txn
=
$teng
->txn_scope;
my
$updated
=
$self
->row->update(\
%stash
, \
%cond
);
if
(
$updated
) {
$txn
->commit;
return
1;
}
else
{
$txn
->rollback;
return
0;
}
}
1;