- insert method created_at and updated_at option...
...can receive scalar reference
| ... | ... |
@@ -1,4 +1,7 @@ |
| 1 | 1 |
0.1740 |
| 2 |
+ - insert method created_at and updated_at option can receive scalar reference |
|
| 3 |
+ - update method updated_at option can receive scalar reference |
|
| 4 |
+ - select column option [COLUMN => ALIAS] syntax is DEPRECATED! |
|
| 2 | 5 |
- added EXPERIMENTAL q method |
| 3 | 6 |
- execute method id option is DEPRECATED! |
| 4 | 7 |
0.1739 |
| ... | ... |
@@ -631,7 +631,8 @@ sub insert {
|
| 631 | 631 |
# Created time and updated time |
| 632 | 632 |
my @timestamp_cleanup; |
| 633 | 633 |
if (defined $opt{created_at} || defined $opt{updated_at}) {
|
| 634 |
- my $now = $self->now->(); |
|
| 634 |
+ my $now = $self->now; |
|
| 635 |
+ $now = $now->() if ref $now eq 'CODE'; |
|
| 635 | 636 |
if (defined $opt{created_at}) {
|
| 636 | 637 |
$param->{$opt{created_at}} = $now;
|
| 637 | 638 |
push @timestamp_cleanup, $opt{created_at};
|
| ... | ... |
@@ -922,6 +923,8 @@ sub select {
|
| 922 | 923 |
$column = $self->column(%$column) if ref $column eq 'HASH'; |
| 923 | 924 |
} |
| 924 | 925 |
elsif (ref $column eq 'ARRAY') {
|
| 926 |
+ warn "select column option [COLUMN => ALIAS] syntax is DEPRECATED!" . |
|
| 927 |
+ "use q method to quote the value"; |
|
| 925 | 928 |
if (@$column == 3 && $column->[1] eq 'as') {
|
| 926 | 929 |
warn "[COLUMN, as => ALIAS] is DEPRECATED! use [COLUMN => ALIAS]"; |
| 927 | 930 |
splice @$column, 1, 1; |
| ... | ... |
@@ -1128,6 +1131,8 @@ sub update {
|
| 1128 | 1131 |
# Created time and updated time |
| 1129 | 1132 |
my @timestamp_cleanup; |
| 1130 | 1133 |
if (defined $opt{updated_at}) {
|
| 1134 |
+ my $now = $self->now; |
|
| 1135 |
+ $now = $now->() if ref $now eq 'CODE'; |
|
| 1131 | 1136 |
$param->{$opt{updated_at}} = $self->now->();
|
| 1132 | 1137 |
push @timestamp_cleanup, $opt{updated_at};
|
| 1133 | 1138 |
} |
| ... | ... |
@@ -3449,6 +3454,7 @@ L<DBIx::Custom> |
| 3449 | 3454 |
update_param_tag # will be removed at 2017/1/1 |
| 3450 | 3455 |
|
| 3451 | 3456 |
# Options |
| 3457 |
+ select column option [COLUMN => ALIAS] syntax # will be removed 2017/1/1 |
|
| 3452 | 3458 |
execute method id option # will be removed 2017/1/1 |
| 3453 | 3459 |
update timestamp option # will be removed 2017/1/1 |
| 3454 | 3460 |
insert timestamp option # will be removed 2017/1/1 |
| ... | ... |
@@ -58,15 +58,38 @@ $result = $dbi->execute('select * from table1;');
|
| 58 | 58 |
$rows = $result->all; |
| 59 | 59 |
is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
|
| 60 | 60 |
|
| 61 |
+ |
|
| 62 |
+test 'insert created_at and updated_at scalar reference'; |
|
| 61 | 63 |
$dbi = DBIx::Custom->connect; |
| 62 | 64 |
eval { $dbi->execute('drop table table1') };
|
| 63 |
-$dbi->execute('create table table1 (key1 varchar, key2 varchar, primary key(key1));');
|
|
| 64 |
-$dbi->insert({key1 => 1, key2 => 2}, table => 'table1');
|
|
| 65 |
-$dbi->update({key2 => 4}, table => 'table1',
|
|
| 66 |
- where => {key1 => 1}, prefix => 'or replace');
|
|
| 67 |
-$result = $dbi->execute('select * from table1;');
|
|
| 68 |
-$rows = $result->all; |
|
| 69 |
-is_deeply($rows, [{key1 => 1, key2 => 4}], "basic");
|
|
| 65 |
+$dbi->execute('create table table1 (key1, key2, key3)');
|
|
| 66 |
+$dbi->now(\"datetime('now')");
|
|
| 67 |
+$dbi->insert({key1 => \"datetime('now')"}, created_at => 'key2', updated_at => 'key3', table => 'table1');
|
|
| 68 |
+$result = $dbi->select(table => 'table1'); |
|
| 69 |
+$row = $result->one; |
|
| 70 |
+is($row->{key1}, $row->{key2});
|
|
| 71 |
+is($row->{key1}, $row->{key3});
|
|
| 72 |
+ |
|
| 73 |
+test 'insert created_at and updated_at scalar reference'; |
|
| 74 |
+$dbi = DBIx::Custom->connect; |
|
| 75 |
+eval { $dbi->execute('drop table table1') };
|
|
| 76 |
+$dbi->execute('create table table1 (key1, key2, key3)');
|
|
| 77 |
+$dbi->now(\"datetime('now')");
|
|
| 78 |
+$dbi->insert({key1 => \"datetime('now')"}, created_at => 'key2', updated_at => 'key3', table => 'table1');
|
|
| 79 |
+$result = $dbi->select(table => 'table1'); |
|
| 80 |
+$row = $result->one; |
|
| 81 |
+is($row->{key1}, $row->{key2});
|
|
| 82 |
+is($row->{key1}, $row->{key3});
|
|
| 83 |
+ |
|
| 84 |
+test 'update updated_at scalar reference'; |
|
| 85 |
+$dbi = DBIx::Custom->connect; |
|
| 86 |
+eval { $dbi->execute('drop table table1') };
|
|
| 87 |
+$dbi->execute('create table table1 (key1, key2)');
|
|
| 88 |
+$dbi->now(\"datetime('now')");
|
|
| 89 |
+$dbi->insert({key1 => \"datetime('now')"}, updated_at => 'key2', table => 'table1');
|
|
| 90 |
+$result = $dbi->select(table => 'table1'); |
|
| 91 |
+$row = $result->one; |
|
| 92 |
+is($row->{key1}, $row->{key2});
|
|
| 70 | 93 |
|
| 71 | 94 |
test 'DBIX_CUSTOM_DEBUG ok'; |
| 72 | 95 |
{
|