... | ... |
@@ -1,5 +1,6 @@ |
1 | 1 |
0.1649 |
2 | 2 |
- add DBIx::Custom::Model column_clause() method. |
3 |
+ - select method column option can receive string. |
|
3 | 4 |
- DBIx::Custom::Model select() and select_at() think about relation attirbute |
4 | 5 |
0.1648 |
5 | 6 |
- add experimental DBIx::Custom::Model relation() attribute |
... | ... |
@@ -550,6 +550,7 @@ sub select { |
550 | 550 |
: defined $table ? [$table] |
551 | 551 |
: []; |
552 | 552 |
my $columns = $args{column} || []; |
553 |
+ $columns = [$columns] unless ref $columns; |
|
553 | 554 |
my $selection = $args{selection} || ''; |
554 | 555 |
my $where = $args{where} || {}; |
555 | 556 |
my $relation = $args{relation} || {}; |
... | ... |
@@ -1538,19 +1539,22 @@ This is same as L<DBI>'s C<rollback>. |
1538 | 1539 |
|
1539 | 1540 |
=head2 C<select> |
1540 | 1541 |
|
1541 |
- my $result = $dbi->select(table => $table, |
|
1542 |
- column => [@column], |
|
1543 |
- where => \%where, |
|
1544 |
- append => $append, |
|
1545 |
- relation => \%relation, |
|
1546 |
- filter => \%filter, |
|
1547 |
- query => 1, |
|
1548 |
- selection => $selection); |
|
1542 |
+ my $result = $dbi->select( |
|
1543 |
+ table => $table, |
|
1544 |
+ column => [@column], |
|
1545 |
+ where => \%where, |
|
1546 |
+ append => $append, |
|
1547 |
+ relation => \%relation, |
|
1548 |
+ filter => \%filter, |
|
1549 |
+ query => 1, |
|
1550 |
+ selection => $selection |
|
1551 |
+ ); |
|
1549 | 1552 |
|
1550 | 1553 |
Execute select statement. |
1551 | 1554 |
C<select> method have C<table>, C<column>, C<where>, C<append>, |
1552 | 1555 |
C<relation> and C<filter> arguments. |
1553 | 1556 |
C<table> is a table name. |
1557 |
+C<column> is column names. this is array reference or string. |
|
1554 | 1558 |
C<where> is where clause. this is normally hash reference. |
1555 | 1559 |
C<append> is a string added at the end of the SQL statement. |
1556 | 1560 |
C<filter> is filters when parameter binding is executed. |
... | ... |
@@ -41,39 +41,65 @@ sub AUTOLOAD { |
41 | 41 |
} |
42 | 42 |
} |
43 | 43 |
|
44 |
-sub method { |
|
44 |
+sub column_clause { |
|
45 | 45 |
my $self = shift; |
46 | 46 |
|
47 |
- # Merge |
|
48 |
- my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
49 |
- $self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
47 |
+ my $args = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
50 | 48 |
|
51 |
- return $self; |
|
49 |
+ my $table = $self->table; |
|
50 |
+ my $columns = $self->columns; |
|
51 |
+ my $add = $args->{add} || []; |
|
52 |
+ my $remove = $args->{remove} || []; |
|
53 |
+ my %remove = map {$_ => 1} @$remove; |
|
54 |
+ |
|
55 |
+ my @column; |
|
56 |
+ foreach my $column (@$columns) { |
|
57 |
+ push @column, "$table.$column as $column" |
|
58 |
+ unless $remove{$column}; |
|
59 |
+ } |
|
60 |
+ |
|
61 |
+ foreach my $column (@$add) { |
|
62 |
+ push @column, $column; |
|
63 |
+ } |
|
64 |
+ |
|
65 |
+ return join (', ', @column); |
|
52 | 66 |
} |
53 | 67 |
|
54 |
-sub insert { |
|
68 |
+sub delete { |
|
55 | 69 |
my $self = shift; |
56 |
- $self->dbi->insert(table => $self->table, @_); |
|
70 |
+ $self->dbi->delete(table => $self->table, @_); |
|
57 | 71 |
} |
58 | 72 |
|
59 |
-sub update { |
|
73 |
+sub delete_all { |
|
60 | 74 |
my $self = shift; |
61 |
- $self->dbi->update(table => $self->table, @_) |
|
75 |
+ $self->dbi->delete_all(table => $self->table, @_); |
|
62 | 76 |
} |
63 | 77 |
|
64 |
-sub update_all { |
|
78 |
+sub delete_at { |
|
65 | 79 |
my $self = shift; |
66 |
- $self->dbi->update_all(table => $self->table, @_); |
|
80 |
+ |
|
81 |
+ return $self->dbi->delete_at( |
|
82 |
+ table => $self->table, |
|
83 |
+ primary_key => $self->primary_key, |
|
84 |
+ @_ |
|
85 |
+ ); |
|
67 | 86 |
} |
68 | 87 |
|
69 |
-sub delete { |
|
88 |
+sub DESTROY { } |
|
89 |
+ |
|
90 |
+sub insert { |
|
70 | 91 |
my $self = shift; |
71 |
- $self->dbi->delete(table => $self->table, @_); |
|
92 |
+ $self->dbi->insert(table => $self->table, @_); |
|
72 | 93 |
} |
73 | 94 |
|
74 |
-sub delete_all { |
|
95 |
+sub method { |
|
75 | 96 |
my $self = shift; |
76 |
- $self->dbi->delete_all(table => $self->table, @_); |
|
97 |
+ |
|
98 |
+ # Merge |
|
99 |
+ my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
100 |
+ $self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
101 |
+ |
|
102 |
+ return $self; |
|
77 | 103 |
} |
78 | 104 |
|
79 | 105 |
sub select { |
... | ... |
@@ -85,39 +111,38 @@ sub select { |
85 | 111 |
); |
86 | 112 |
} |
87 | 113 |
|
88 |
-sub update_at { |
|
114 |
+sub select_at { |
|
89 | 115 |
my $self = shift; |
90 | 116 |
|
91 |
- return $self->dbi->update_at( |
|
117 |
+ return $self->dbi->select_at( |
|
92 | 118 |
table => $self->table, |
93 | 119 |
primary_key => $self->primary_key, |
120 |
+ relation => $self->relation, |
|
94 | 121 |
@_ |
95 | 122 |
); |
96 | 123 |
} |
97 | 124 |
|
98 |
-sub delete_at { |
|
125 |
+sub update { |
|
99 | 126 |
my $self = shift; |
100 |
- |
|
101 |
- return $self->dbi->delete_at( |
|
102 |
- table => $self->table, |
|
103 |
- primary_key => $self->primary_key, |
|
104 |
- @_ |
|
105 |
- ); |
|
127 |
+ $self->dbi->update(table => $self->table, @_) |
|
106 | 128 |
} |
107 | 129 |
|
108 |
-sub select_at { |
|
130 |
+sub update_all { |
|
131 |
+ my $self = shift; |
|
132 |
+ $self->dbi->update_all(table => $self->table, @_); |
|
133 |
+} |
|
134 |
+ |
|
135 |
+ |
|
136 |
+sub update_at { |
|
109 | 137 |
my $self = shift; |
110 | 138 |
|
111 |
- return $self->dbi->select_at( |
|
139 |
+ return $self->dbi->update_at( |
|
112 | 140 |
table => $self->table, |
113 | 141 |
primary_key => $self->primary_key, |
114 |
- relation => $self->relation, |
|
115 | 142 |
@_ |
116 | 143 |
); |
117 | 144 |
} |
118 | 145 |
|
119 |
-sub DESTROY { } |
|
120 |
- |
|
121 | 146 |
1; |
122 | 147 |
|
123 | 148 |
=head1 NAME |
... | ... |
@@ -34,73 +34,3 @@ sub connect { |
34 | 34 |
|
35 | 35 |
DBIx::Custom::MySQL - DEPRECATED! |
36 | 36 |
|
37 |
-=head1 CAUTION |
|
38 |
- |
|
39 |
-B<This module is deprecated now> because This module is less useful |
|
40 |
-than I expected. Please use DBIx::Custom instead.> |
|
41 |
- |
|
42 |
-=head1 SYNOPSYS |
|
43 |
- |
|
44 |
- # Connect to the database |
|
45 |
- my $dbi = DBIx::Custom::MySQL->connect( |
|
46 |
- user => 'taro', |
|
47 |
- password => 'kliej&@K', |
|
48 |
- database => 'dbname' |
|
49 |
- ); |
|
50 |
- |
|
51 |
- # Get last insert id |
|
52 |
- my $last_insert_id = $dbi->last_insert_id; |
|
53 |
- |
|
54 |
-=head1 ATTRIBUTES |
|
55 |
- |
|
56 |
-L<DBIx::Custom::MySQL> inherits all attributes from L<DBIx::Custom> |
|
57 |
-and implements the following new ones. |
|
58 |
- |
|
59 |
-=head2 C<database> |
|
60 |
- |
|
61 |
- my $database = $dbi->database; |
|
62 |
- $dbi = $dbi->database('dbname'); |
|
63 |
- |
|
64 |
-Database name. |
|
65 |
-C<connect()> method use this value to connect the database |
|
66 |
-if C<data_source> is not specified. |
|
67 |
- |
|
68 |
-=head2 C<host> |
|
69 |
- |
|
70 |
- my $host = $dbi->host; |
|
71 |
- $dbi = $dbi->host('somehost'); |
|
72 |
- |
|
73 |
-Host name or IP address. |
|
74 |
-C<connect()> method use this value to connect the database |
|
75 |
-if C<data_source> is not specified. |
|
76 |
- |
|
77 |
-=head2 C<port> |
|
78 |
- |
|
79 |
- my $port = $dbi->port; |
|
80 |
- $dbi = $dbi->port(1198); |
|
81 |
- |
|
82 |
-Port number. |
|
83 |
-C<connect()> method use this value to connect the database |
|
84 |
-if C<data_source> is not specified. |
|
85 |
- |
|
86 |
-=head1 METHODS |
|
87 |
- |
|
88 |
-L<DBIx::Custom::MySQL> inherits all methods from L<DBIx::Custom> |
|
89 |
-and implements the following new ones. |
|
90 |
- |
|
91 |
-=head2 C<connect> |
|
92 |
- |
|
93 |
- my $dbi = DBIx::Custom::MySQL->connect( |
|
94 |
- user => 'taro', |
|
95 |
- password => 'kliej&@K', |
|
96 |
- database => 'dbname', |
|
97 |
- host => 'somehost', |
|
98 |
- port => 2000 |
|
99 |
- ); |
|
100 |
- |
|
101 |
-Create a new L<DBIx::Custom::MySQL> object and connect to the database. |
|
102 |
-This method overrides C<DBIx::Custom::connect()> method. |
|
103 |
-You can specify all attributes of L<DBIx::Custom> |
|
104 |
-and L<DBIx::Custom::MySQL>, such as C<database>, C<host>, C<port>. |
|
105 |
- |
|
106 |
-=cut |
... | ... |
@@ -40,56 +40,3 @@ sub connect_memory { |
40 | 40 |
|
41 | 41 |
DBIx::Custom::SQLite - DEPRECATED! |
42 | 42 |
|
43 |
-=head1 CAUTION |
|
44 |
- |
|
45 |
-B<This module is deprecated now> because This module is less useful |
|
46 |
-than I expected. Please use DBIx::Custom instead.> |
|
47 |
- |
|
48 |
-=head1 SYNOPSYS |
|
49 |
- |
|
50 |
- use DBIx::Custom::SQLite; |
|
51 |
- |
|
52 |
- # Connect to the database |
|
53 |
- my $dbi = DBIx::Custom::SQLite->connect(database => 'dbname'); |
|
54 |
- |
|
55 |
- # Connect to the memory database |
|
56 |
- my $dbi = DBIx::Custom::SQLite->connect_memory; |
|
57 |
- |
|
58 |
- # Get last insert row id |
|
59 |
- my $id = $dbi->last_insert_rowid; |
|
60 |
- |
|
61 |
-=head1 ATTRIBUTES |
|
62 |
- |
|
63 |
-L<DBIx::Custom::SQLite> inherits all attributes from L<DBIx::Custom> |
|
64 |
-and implements the following new ones. |
|
65 |
- |
|
66 |
-=head2 C<database> |
|
67 |
- |
|
68 |
- my $database = $dbi->database; |
|
69 |
- $dbi = $dbi->database('dbname'); |
|
70 |
- |
|
71 |
-Database name. |
|
72 |
-C<connect()> method use this value to connect the database |
|
73 |
-if C<data_source> is not specified. |
|
74 |
- |
|
75 |
-=head1 METHODS |
|
76 |
- |
|
77 |
-L<DBIx::Custom::SQLite> inherits all methods from L<DBIx::Custom> |
|
78 |
-and implements the following new ones. |
|
79 |
- |
|
80 |
-=head2 C<connect> |
|
81 |
- |
|
82 |
- my $dbi = DBIx::Custom::SQLite->connect(database => 'dbname'); |
|
83 |
- |
|
84 |
-Create a new L<DBIx::Custom::SQLite> object and connect to the database. |
|
85 |
-This method overrides C<DBIx::Custom::connect()> method. |
|
86 |
-You can specify all attributes of L<DBIx::Custom> |
|
87 |
-and L<DBIx::Custom::SQLite>, such as C<database>. |
|
88 |
- |
|
89 |
-=head2 C<connect_memory> |
|
90 |
- |
|
91 |
- my $dbi = DBIx::Custom::SQLite->connect_memory; |
|
92 |
- |
|
93 |
-Create a new L<DBIx::Custom::SQLite> object and connect to the memory database. |
|
94 |
- |
|
95 |
-=cut |
... | ... |
@@ -418,7 +418,7 @@ $dbi->execute($CREATE_TABLE->{2}); |
418 | 418 |
$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 5}); |
419 | 419 |
$rows = $dbi->select( |
420 | 420 |
table => [qw/table1 table2/], |
421 |
- column => ['table1.key1 as table1_key1', 'table2.key1 as table2_key1', 'key2', 'key3'], |
|
421 |
+ column => 'table1.key1 as table1_key1, table2.key1 as table2_key1, key2, key3', |
|
422 | 422 |
where => {'table1.key2' => 2}, |
423 | 423 |
relation => {'table1.key1' => 'table2.key1'} |
424 | 424 |
)->fetch_hash_all; |