DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
1776 lines | 45.85kb
cleanup
yuki-kimoto authored on 2009-12-22
1
package DBIx::Custom;
2

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
3
our $VERSION = '0.1651';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4

            
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6
use strict;
7
use warnings;
8

            
remove run_transaction().
yuki-kimoto authored on 2010-01-30
9
use base 'Object::Simple';
many change
yuki-kimoto authored on 2010-02-11
10

            
packaging one directory
yuki-kimoto authored on 2009-11-16
11
use Carp 'croak';
12
use DBI;
13
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
14
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
15
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
16
use DBIx::Custom::Where;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
17
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
18
use DBIx::Custom::Tag;
update document
yuki-kimoto authored on 2010-05-27
19
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
20

            
fix tests
Yuki Kimoto authored on 2011-01-13
21
__PACKAGE__->attr(
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
22
    [qw/data_source dbh password user/],
fix tests
Yuki Kimoto authored on 2011-01-13
23
    cache => 1,
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
24
    dbi_option => sub { {} },
25
    default_dbi_option => sub {{
26
        RaiseError => 1,
27
        PrintError => 0,
28
        AutoCommit => 1
29
    }},
add models() attribute
Yuki Kimoto authored on 2011-02-21
30
    models => sub { {} },
cleanup
Yuki Kimoto authored on 2011-01-23
31
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
many changed
Yuki Kimoto authored on 2011-01-23
32
    result_class  => 'DBIx::Custom::Result',
update pod
Yuki Kimoto authored on 2011-02-07
33
    safety_column_name => sub { qr/^[\w\.]*$/ },
34
    stash => sub { {} }
many changed
Yuki Kimoto authored on 2011-01-23
35
);
36

            
37
__PACKAGE__->attr(
38
    cache_method => sub {
39
        sub {
40
            my $self = shift;
41
            
42
            $self->{_cached} ||= {};
43
            
44
            if (@_ > 1) {
45
                $self->{_cached}{$_[0]} = $_[1] 
46
            }
47
            else {
48
                return $self->{_cached}{$_[0]}
49
            }
50
        }
51
    }
52
);
53

            
54
__PACKAGE__->attr(
fix tests
Yuki Kimoto authored on 2011-01-13
55
    filters => sub {
56
        {
57
            encode_utf8 => sub { encode_utf8($_[0]) },
58
            decode_utf8 => sub { decode_utf8($_[0]) }
59
        }
many changed
Yuki Kimoto authored on 2011-01-23
60
    }
fix tests
Yuki Kimoto authored on 2011-01-13
61
);
cleanup
yuki-kimoto authored on 2010-10-17
62

            
added helper method
yuki-kimoto authored on 2010-10-17
63
our $AUTOLOAD;
64
sub AUTOLOAD {
65
    my $self = shift;
66

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
67
    # Method name
68
    my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
added helper method
yuki-kimoto authored on 2010-10-17
69

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
70
    # Method
71
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
72
    if (my $method = $self->{_methods}->{$mname}) {
73
        return $self->$method(@_)
74
    }
75
    elsif ($self->dbh->can($mname)) {
76
        $self->dbh->$mname(@_);
77
    }
78
    else {
79
        croak qq/Can't locate object method "$mname" via "$package"/
80
    }
added helper method
yuki-kimoto authored on 2010-10-17
81
}
82

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
83
sub apply_filter {
many changed
Yuki Kimoto authored on 2011-01-23
84
    my ($self, $table, @cinfos) = @_;
85

            
86
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
87
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
88
    $self->{filter}{out} ||= {};
89
    $self->{filter}{in} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
90
    
many changed
Yuki Kimoto authored on 2011-01-23
91
    # Create filters
92
    my $usage = "Usage: \$dbi->apply_filter(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
93
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
94
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
many changed
Yuki Kimoto authored on 2011-01-23
95

            
96
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
97
        
many changed
Yuki Kimoto authored on 2011-01-23
98
        # Column
99
        my $column = $cinfos[$i];
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
100
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
101
        # Filter info
102
        my $finfo = $cinfos[$i + 1] || {};
103
        croak $usage unless  ref $finfo eq 'HASH';
104
        foreach my $ftype (keys %$finfo) {
105
            croak $usage unless $ftype eq 'in' || $ftype eq 'out'
106
                             || $ftype eq 'end'; 
many changed
Yuki Kimoto authored on 2011-01-23
107
        }
108
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
109
        foreach my $way (qw/in out end/) {
110
            my $filter = $finfo->{$way};
cleanup
Yuki Kimoto authored on 2010-12-22
111
            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
112
            # State
113
            my $state = !exists $finfo->{$way} ? 'not_exists'
114
                      : !defined $filter        ? 'not_defined'
115
                      : ref $filter eq 'CODE'   ? 'code'
116
                      : 'name';
117
            
118
            next if $state eq 'not_exists';
119
            
120
            # Check filter
121
            croak qq{Filter "$filter" is not registered}
122
              if  $state eq 'name'
123
               && ! exists $self->filters->{$filter};
124
            
125
            # Filter
126
            my $f = $state eq 'not_defined' ? undef
127
                  : $state eq 'code'        ? $filter
128
                  : $self->filters->{$filter};
129
            $self->{filter}{$way}{$table}{$column} = $f;
130
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
131
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
many changed
Yuki Kimoto authored on 2011-01-23
132
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
133
    }
134
    
many changed
Yuki Kimoto authored on 2011-01-23
135
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
136
}
137

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
138
sub method {
added helper method
yuki-kimoto authored on 2010-10-17
139
    my $self = shift;
140
    
141
    # Merge
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
142
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
143
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
added helper method
yuki-kimoto authored on 2010-10-17
144
    
145
    return $self;
146
}
147

            
packaging one directory
yuki-kimoto authored on 2009-11-16
148
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
149
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
150
    
many changed
Yuki Kimoto authored on 2011-01-23
151
    # Attributes
packaging one directory
yuki-kimoto authored on 2009-11-16
152
    my $data_source = $self->data_source;
many changed
Yuki Kimoto authored on 2011-01-23
153
    croak qq{"data_source" must be specified to connect()"}
check arguments of connect m...
Yuki Kimoto authored on 2010-12-20
154
      unless $data_source;
packaging one directory
yuki-kimoto authored on 2009-11-16
155
    my $user        = $self->user;
156
    my $password    = $self->password;
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
157
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added dbi_options attribute
kimoto authored on 2010-12-20
158
    
update document
yuki-kimoto authored on 2010-01-30
159
    # Connect
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
160
    my $dbh = eval {DBI->connect(
packaging one directory
yuki-kimoto authored on 2009-11-16
161
        $data_source,
162
        $user,
163
        $password,
164
        {
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
165
            %{$self->default_dbi_option},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
166
            %$dbi_option
packaging one directory
yuki-kimoto authored on 2009-11-16
167
        }
168
    )};
169
    
update document
yuki-kimoto authored on 2010-01-30
170
    # Connect error
packaging one directory
yuki-kimoto authored on 2009-11-16
171
    croak $@ if $@;
172
    
update document
yuki-kimoto authored on 2010-01-30
173
    # Database handle
packaging one directory
yuki-kimoto authored on 2009-11-16
174
    $self->dbh($dbh);
update document
yuki-kimoto authored on 2010-01-30
175
    
packaging one directory
yuki-kimoto authored on 2009-11-16
176
    return $self;
177
}
178

            
cleanup
yuki-kimoto authored on 2010-10-17
179
sub create_query {
180
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
181
    
cleanup
yuki-kimoto authored on 2010-10-17
182
    # Cache
183
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
184
    
cleanup
yuki-kimoto authored on 2010-10-17
185
    # Create query
186
    my $query;
187
    if ($cache) {
188
        
189
        # Get query
190
        my $q = $self->cache_method->($self, $source);
191
        
192
        # Create query
add table tag
Yuki Kimoto authored on 2011-02-09
193
        if ($q) {
194
            $query = DBIx::Custom::Query->new($q);
195
            $query->filters($self->filters);
196
        }
cleanup
yuki-kimoto authored on 2010-10-17
197
    }
198
    
199
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
200

            
cleanup
yuki-kimoto authored on 2010-10-17
201
        # Create SQL object
202
        my $builder = $self->query_builder;
203
        
204
        # Create query
205
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
206

            
cleanup
yuki-kimoto authored on 2010-10-17
207
        # Cache query
208
        $self->cache_method->($self, $source,
209
                             {sql     => $query->sql, 
add table tag
Yuki Kimoto authored on 2011-02-09
210
                              columns => $query->columns,
211
                              tables  => $query->tables})
cleanup
yuki-kimoto authored on 2010-10-17
212
          if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
213
    }
214
    
cleanup
yuki-kimoto authored on 2010-10-17
215
    # Prepare statement handle
216
    my $sth;
217
    eval { $sth = $self->dbh->prepare($query->{sql})};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
218
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
packaging one directory
yuki-kimoto authored on 2009-11-16
219
    
cleanup
yuki-kimoto authored on 2010-10-17
220
    # Set statement handle
221
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
222
    
cleanup
Yuki Kimoto authored on 2011-02-09
223
    # Set filters
224
    $query->filters($self->filters);
225
    
cleanup
yuki-kimoto authored on 2010-10-17
226
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
227
}
228

            
cleanup
yuki-kimoto authored on 2010-10-17
229
our %VALID_DELETE_ARGS
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
230
  = map { $_ => 1 } qw/table where append filter allow_delete_all query/;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
231

            
cleanup
yuki-kimoto authored on 2010-10-17
232
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
233
    my ($self, %args) = @_;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
234
    
235
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
236
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
237
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
238
          unless $VALID_DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
239
    }
240
    
241
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
242
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
243
    croak qq{"table" option must be specified} unless $table;
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
244
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
245
    my $append           = $args{append};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
246
    my $filter           = $args{filter};
cleanup
yuki-kimoto authored on 2010-10-17
247
    my $allow_delete_all = $args{allow_delete_all};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
248

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
249
    # Where
250
    my $w;
251
    if (ref $where eq 'HASH') {
252
        my $clause = ['and'];
253
        push @$clause, "{= $_}" for keys %$where;
254
        $w = $self->where;
255
        $w->clause($clause);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
256
        $w->param($where);
packaging one directory
yuki-kimoto authored on 2009-11-16
257
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
258
    elsif (ref $where eq 'DBIx::Custom::Where') {
259
        $w = $where;
260
        $where = $w->param;
261
    }    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
262
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
263
      unless ref $w eq 'DBIx::Custom::Where';
264
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
265
    # String where
266
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
267
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
268
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
269
      if $swhere eq '' && !$allow_delete_all;
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
270

            
cleanup
Yuki Kimoto authored on 2011-01-27
271
    # SQL stack
272
    my @sql;
273

            
274
    # Delete
275
    push @sql, "delete from $table $swhere";
276
    push @sql, $append if $append;
277
    
278
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
279
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
280
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
281
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
282
    return $query if $args{query};
283
    
packaging one directory
yuki-kimoto authored on 2009-11-16
284
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
285
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
286
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
287
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
288
    
289
    return $ret_val;
290
}
291

            
cleanup
yuki-kimoto authored on 2010-10-17
292
sub delete_all { shift->delete(allow_delete_all => 1, @_) }
packaging one directory
yuki-kimoto authored on 2009-11-16
293

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
294
our %VALID_DELETE_AT_ARGS
295
  = map { $_ => 1 } qw/table where append filter query
296
                       primary_key param/;
297

            
298
sub delete_at {
299
    my ($self, %args) = @_;
300
    
301
    # Check arguments
302
    foreach my $name (keys %args) {
303
        croak qq{"$name" is invalid argument}
304
          unless $VALID_DELETE_AT_ARGS{$name};
305
    }
306
    
307
    # Primary key
308
    my $primary_keys = delete $args{primary_key};
309
    $primary_keys = [$primary_keys] unless ref $primary_keys;
310
    
311
    # Where clause
312
    my $where = {};
313
    if (exists $args{where}) {
314
        my $where_columns = delete $args{where};
315
        $where_columns = [$where_columns] unless ref $where_columns;
316
        
317
        for(my $i = 0; $i < @$primary_keys; $i ++) {
318
           $where->{$primary_keys->[$i]} = $where_columns->[$i];
319
        }
320
    }
321
    elsif (exists $args{param}) {
322
        my $param = delete $args{param};
323
        
324
        for(my $i = 0; $i < @$primary_keys; $i ++) {
325
           $where->{$primary_keys->[$i]}
326
             = delete $param->{$primary_keys->[$i]};
327
        }
328
    }
329
    
330
    return $self->delete(where => $where, %args);
331
}
332

            
added helper method
yuki-kimoto authored on 2010-10-17
333
sub DESTROY { }
334

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
335
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter table/;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
336

            
cleanup
yuki-kimoto authored on 2010-10-17
337
sub execute{
338
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
339
    
340
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
341
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
342
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
343
          unless $VALID_EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
344
    }
345
    
cleanup
yuki-kimoto authored on 2010-10-17
346
    my $params = $args{param} || {};
packaging one directory
yuki-kimoto authored on 2009-11-16
347
    
cleanup
yuki-kimoto authored on 2010-10-17
348
    # First argument is the soruce of SQL
349
    $query = $self->create_query($query)
350
      unless ref $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
351
    
add table tag
Yuki Kimoto authored on 2011-02-09
352
    # Applied filter
cleanup
Yuki Kimoto authored on 2011-01-12
353
    my $filter = {};
add table tag
Yuki Kimoto authored on 2011-02-09
354
    my $tables = $query->tables;
355
    my $arg_tables = $args{table} || [];
356
    $arg_tables = [$arg_tables]
357
      unless ref $arg_tables eq 'ARRAY';
358
    push @$tables, @$arg_tables;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
359
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-01-12
360
        $filter = {
361
            %$filter,
362
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
363
        }
364
    }
365
    
cleanup
Yuki Kimoto authored on 2011-01-12
366
    # Filter argument
367
    my $f = $args{filter} || $query->filter || {};
368
    foreach my $column (keys %$f) {
369
        my $fname = $f->{$column};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
370
        if (!defined $fname) {
cleanup
Yuki Kimoto authored on 2011-01-12
371
            $f->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
372
        }
373
        elsif (ref $fname ne 'CODE') {
many changed
Yuki Kimoto authored on 2011-01-23
374
          croak qq{Filter "$fname" is not registered"}
cleanup
Yuki Kimoto authored on 2010-12-21
375
            unless exists $self->filters->{$fname};
376
          
cleanup
Yuki Kimoto authored on 2011-01-12
377
          $f->{$column} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2010-12-21
378
        }
379
    }
cleanup
Yuki Kimoto authored on 2011-01-12
380
    $filter = {%$filter, %$f};
packaging one directory
yuki-kimoto authored on 2009-11-16
381
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
382
    # Bind
383
    my $bind = $self->_bind($params, $query->columns, $filter);
cleanup
yuki-kimoto authored on 2010-10-17
384
    
385
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
386
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
387
    my $affected;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
388
    eval {$affected = $sth->execute(@$bind)};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
389
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
390
    
391
    # Return resultset if select statement is executed
392
    if ($sth->{NUM_OF_FIELDS}) {
393
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
394
        # Result in and end filter
395
        my $in_filter  = {};
396
        my $end_filter = {};
cleanup
Yuki Kimoto authored on 2011-01-12
397
        foreach my $table (@$tables) {
398
            $in_filter = {
399
                %$in_filter,
400
                %{$self->{filter}{in}{$table} || {}}
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
401
            };
402
            $end_filter = {
403
                %$end_filter,
404
                %{$self->{filter}{end}{$table} || {}}
405
            };
cleanup
Yuki Kimoto authored on 2011-01-12
406
        }
407
        
408
        # Result
409
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
410
            sth            => $sth,
411
            filters        => $self->filters,
412
            filter_check   => $self->filter_check,
cleanup
Yuki Kimoto authored on 2011-01-12
413
            default_filter => $self->{default_in_filter},
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
414
            filter         => $in_filter || {},
415
            end_filter     => $end_filter || {}
cleanup
yuki-kimoto authored on 2010-10-17
416
        );
417

            
418
        return $result;
419
    }
420
    return $affected;
421
}
422

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
423
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
424
                                            filter query/;
cleanup
yuki-kimoto authored on 2010-10-17
425
sub insert {
426
    my ($self, %args) = @_;
427

            
428
    # Check arguments
429
    foreach my $name (keys %args) {
430
        croak qq{"$name" is invalid argument}
431
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
432
    }
433
    
cleanup
yuki-kimoto authored on 2010-10-17
434
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
435
    my $table  = $args{table};
436
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
437
    my $param  = $args{param} || {};
438
    my $append = $args{append} || '';
439
    my $filter = $args{filter};
440
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
441
    # Columns
442
    my @columns;
443
    my $safety = $self->safety_column_name;
444
    foreach my $column (keys %$param) {
445
        croak qq{"$column" is not safety column name}
446
          unless $column =~ /$safety/;
447
        push @columns, $column;
448
    }
cleanup
yuki-kimoto authored on 2010-10-17
449
    
cleanup
Yuki Kimoto authored on 2011-01-27
450
    # SQL stack
451
    my @sql;
452
    
453
    # Insert
454
    push @sql, "insert into $table {insert_param ". join(' ', @columns) . '}';
455
    push @sql, $append if $append;
456
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
457
    # SQL
cleanup
Yuki Kimoto authored on 2011-01-27
458
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
459
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
460
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
461
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
462
    return $query if $args{query};
463
    
packaging one directory
yuki-kimoto authored on 2009-11-16
464
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
465
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
466
        $query,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
467
        param  => $param,
468
        filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
469
        table => $table
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
470
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
471
    
472
    return $ret_val;
473
}
474

            
pod fix
Yuki Kimoto authored on 2011-01-21
475
sub each_column {
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
476
    my ($self, $cb) = @_;
477
    
478
    # Iterate all tables
479
    my $sth_tables = $self->dbh->table_info;
480
    while (my $table_info = $sth_tables->fetchrow_hashref) {
481
        
482
        # Table
483
        my $table = $table_info->{TABLE_NAME};
484
        
485
        # Iterate all columns
486
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
487
        while (my $column_info = $sth_columns->fetchrow_hashref) {
488
            my $column = $column_info->{COLUMN_NAME};
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
489
            $self->$cb($table, $column, $column_info);
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
490
        }
491
    }
492
}
493

            
added dbi_options attribute
kimoto authored on 2010-12-20
494
sub new {
495
    my $self = shift->SUPER::new(@_);
496
    
497
    # Check attribute names
498
    my @attrs = keys %$self;
499
    foreach my $attr (@attrs) {
500
        croak qq{"$attr" is invalid attribute name}
501
          unless $self->can($attr);
502
    }
cleanup
Yuki Kimoto authored on 2011-01-25
503

            
504
    $self->register_tag(
505
        '?'     => \&DBIx::Custom::Tag::placeholder,
506
        '='     => \&DBIx::Custom::Tag::equal,
507
        '<>'    => \&DBIx::Custom::Tag::not_equal,
508
        '>'     => \&DBIx::Custom::Tag::greater_than,
509
        '<'     => \&DBIx::Custom::Tag::lower_than,
510
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
511
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
512
        'like'  => \&DBIx::Custom::Tag::like,
513
        'in'    => \&DBIx::Custom::Tag::in,
514
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
515
        'update_param' => \&DBIx::Custom::Tag::update_param
516
    );
added dbi_options attribute
kimoto authored on 2010-12-20
517
    
518
    return $self;
519
}
520

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
521
sub not_exists { bless {}, 'DBIx::Custom::NotExists' }
522

            
cleanup
yuki-kimoto authored on 2010-10-17
523
sub register_filter {
524
    my $invocant = shift;
525
    
526
    # Register filter
527
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
528
    $invocant->filters({%{$invocant->filters}, %$filters});
529
    
530
    return $invocant;
531
}
packaging one directory
yuki-kimoto authored on 2009-11-16
532

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
533
sub register_tag { shift->query_builder->register_tag(@_) }
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
534

            
refactoring select
yuki-kimoto authored on 2010-04-28
535
our %VALID_SELECT_ARGS
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
536
  = map { $_ => 1 } qw/table column where append relation filter query selection/;
refactoring select
yuki-kimoto authored on 2010-04-28
537

            
packaging one directory
yuki-kimoto authored on 2009-11-16
538
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
539
    my ($self, %args) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
540
    
refactoring select
yuki-kimoto authored on 2010-04-28
541
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
542
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
543
        croak qq{"$name" is invalid argument}
refactoring select
yuki-kimoto authored on 2010-04-28
544
          unless $VALID_SELECT_ARGS{$name};
545
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
546
    
refactoring select
yuki-kimoto authored on 2010-04-28
547
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
548
    my $table = $args{table};
549
    my $tables = ref $table eq 'ARRAY' ? $table
550
               : defined $table ? [$table]
551
               : [];
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
552
    my $columns   = $args{column} || [];
select method column option ...
Yuki Kimoto authored on 2011-02-22
553
    $columns = [$columns] unless ref $columns;
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
554
    my $selection = $args{selection} || '';
555
    my $where     = $args{where} || {};
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
556
    my $relation  = $args{relation} || {};
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
557
    my $append    = $args{append};
558
    my $filter    = $args{filter};
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
559

            
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
560
    # Relation
561
    if (!$selection && keys %$relation) {
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
562
        foreach my $rcolumn (keys %$relation) {
563
            my $table1 = (split (/\./, $rcolumn))[0];
564
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
565
            
566
            my $table1_exists;
567
            my $table2_exists;
568
            foreach my $table (@$tables) {
569
                $table1_exists = 1 if $table eq $table1;
570
                $table2_exists = 1 if $table eq $table2;
571
            }
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
572
            unshift @$tables, $table1 unless $table1_exists;
573
            unshift @$tables, $table2 unless $table2_exists;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
574
        }
575
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
576
    
cleanup
Yuki Kimoto authored on 2011-01-27
577
    # SQL stack
578
    my @sql;
579
    
580
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
581
    
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
582
    if ($selection) {
583
        croak qq{Can't contain "where" clause in selection}
584
          if $selection =~ /\swhere\s/;
585
        push @sql, $selection;
586
    }
587
    else {
588
        # Column clause
589
        if (@$columns) {
590
            foreach my $column (@$columns) {
591
                push @sql, ($column, ',');
592
            }
593
            pop @sql if $sql[-1] eq ',';
594
        }
595
        else { push @sql, '*' }
596
        
597
        # Table
598
        croak qq{"table" option must be specified} unless @$tables;
599
        push @sql, 'from';
600
        foreach my $table (@$tables) {
601
            push @sql, ($table, ',');
packaging one directory
yuki-kimoto authored on 2009-11-16
602
        }
cleanup
Yuki Kimoto authored on 2011-01-27
603
        pop @sql if $sql[-1] eq ',';
packaging one directory
yuki-kimoto authored on 2009-11-16
604
    }
605
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
606
    # Where
607
    my $w;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
608
    if (ref $where eq 'HASH') {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
609
        my $clause = ['and'];
610
        push @$clause, "{= $_}" for keys %$where;
611
        $w = $self->where;
612
        $w->clause($clause);
613
        $w->param($where);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
614
    }
615
    elsif (ref $where eq 'DBIx::Custom::Where') {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
616
        $w = $where;
617
        $where = $w->param;
packaging one directory
yuki-kimoto authored on 2009-11-16
618
    }
619
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
620
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
621
      unless ref $w eq 'DBIx::Custom::Where';
622
    
623
    # String where
624
    my $swhere = "$w";
cleanup
Yuki Kimoto authored on 2011-01-27
625
    push @sql, $swhere;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
626
    
added commit method
yuki-kimoto authored on 2010-05-27
627
    # Relation
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
628
    if (!$selection && keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-01-27
629
        push @sql, $swhere eq '' ? 'where' : 'and';
630
        foreach my $rcolumn (keys %$relation) {
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
631
            my $table1 = (split (/\./, $rcolumn))[0];
632
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
633
            push @$tables, ($table1, $table2);
634
            
cleanup
Yuki Kimoto authored on 2011-01-27
635
            push @sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
packaging one directory
yuki-kimoto authored on 2009-11-16
636
        }
637
    }
cleanup
Yuki Kimoto authored on 2011-01-27
638
    pop @sql if $sql[-1] eq 'and';
added commit method
yuki-kimoto authored on 2010-05-27
639
    
cleanup
Yuki Kimoto authored on 2011-01-27
640
    # Append statement
641
    push @sql, $append if $append;
642
    
643
    # SQL
644
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
645
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
646
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
647
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
648
    return $query if $args{query};
649
    
packaging one directory
yuki-kimoto authored on 2009-11-16
650
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
651
    my $result = $self->execute(
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
652
        $query, param  => $where, filter => $filter,
653
        table => $tables);
packaging one directory
yuki-kimoto authored on 2009-11-16
654
    
655
    return $result;
656
}
657

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
658
our %VALID_SELECT_AT_ARGS
659
  = map { $_ => 1 } qw/table column where append relation filter query selection
660
                       param primary_key/;
661

            
662
sub select_at {
663
    my ($self, %args) = @_;
664
    
665
    # Check arguments
666
    foreach my $name (keys %args) {
667
        croak qq{"$name" is invalid argument}
668
          unless $VALID_SELECT_AT_ARGS{$name};
669
    }
670
    
671
    # Primary key
672
    my $primary_keys = delete $args{primary_key};
673
    $primary_keys = [$primary_keys] unless ref $primary_keys;
674
    
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
675
    # Table
676
    croak qq{"table" option must be specified} unless $args{table};
677
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
678
    
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
679
    # Where clause
680
    my $where = {};
681
    if (exists $args{where}) {
682
        my $where_columns = delete $args{where};
683
        $where_columns = [$where_columns] unless ref $where_columns;
684
        
685
        for(my $i = 0; $i < @$primary_keys; $i ++) {
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
686
           $where->{$table . '.' . $primary_keys->[$i]} = $where_columns->[$i];
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
687
        }
688
    }
689
    elsif (exists $args{param}) {
690
        my $param = delete $args{param};
691
        for(my $i = 0; $i < @$primary_keys; $i ++) {
692
           $where->{$primary_keys->[$i]}
693
             = delete $param->{$primary_keys->[$i]};
694
        }
695
    }
696
    
697
    return $self->select(where => $where, %args);
698
}
699

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
700
sub model {
701
    my ($self, $name, $model) = @_;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
702
    
703
    # Set
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
704
    if ($model) {
add models() attribute
Yuki Kimoto authored on 2011-02-21
705
        $self->models->{$name} = $model;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
706
        return $self;
707
    }
708
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
709
    # Check model existance
710
    croak qq{Model "$name" is not included}
add models() attribute
Yuki Kimoto authored on 2011-02-21
711
      unless $self->models->{$name};
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
712
    
713
    # Get
add models() attribute
Yuki Kimoto authored on 2011-02-21
714
    return $self->models->{$name};
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
715
}
716

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
717
sub include_model {
718
    my ($self, $name_space, $model_infos) = @_;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
719
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
720
    $name_space ||= '';
721
    unless ($model_infos) {
722
        # Load name space module
723
        croak qq{"$name_space" is invalid class name}
724
          if $name_space =~ /[^\w:]/;
725
        eval "use $name_space";
726
        croak qq{Name space module "$name_space.pm" is needed. $@} if $@;
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
727
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
728
        # Search model modules
729
        my $path = $INC{"$name_space.pm"};
730
        $path =~ s/\.pm$//;
731
        opendir my $dh, $path
732
          or croak qq{Can't open directory "$path": $!};
733
        $model_infos = [];
734
        while (my $module = readdir $dh) {
735
            push @$model_infos, $module
736
              if $module =~ s/\.pm$//;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
737
        }
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
738
        
739
        close $dh;
740
    }
741
    
742
    foreach my $model_info (@$model_infos) {
743
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
744
        # Model class, name, table
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
745
        my $model_class;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
746
        my $model_name;
747
        my $model_table;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
748
        if (ref $model_info eq 'HASH') {
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
749
            $model_class = $model_info->{class};
750
            $model_name  = $model_info->{name};
751
            $model_table = $model_info->{table};
752
            
753
            $model_name  ||= $model_class;
754
            $model_table ||= $model_name;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
755
        }
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
756
        else { $model_class =$model_name = $model_table = $model_info }
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
757
        my $mclass = "${name_space}::$model_class";
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
758
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
759
        # Load
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
760
        croak qq{"$mclass" is invalid class name}
761
          if $mclass =~ /[^\w:]/;
762
        unless ($mclass->can('isa')) {
763
            eval "use $mclass";
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
764
            croak $@ if $@;
765
        }
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
766
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
767
        # Instantiate
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
768
        my $model = $mclass->new(dbi => $self);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
769
        $model->name($model_name) unless $model->name;
770
        $model->table($model_table) unless $model->table;
removed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-28
771
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
772
        # Set
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
773
        $self->model($model->name, $model);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
774
        
775
        # Apply filter
776
        $self->apply_filter($model->table, %{$model->filter});
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
777
    }
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
778
    return $self;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
779
}
780

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
781
sub setup_model {
782
    my $self = shift;
783
    
784
    $self->each_column(
785
        sub {
786
            my ($self, $table, $column, $column_info) = @_;
787
            
788
            if (my $model = $self->models->{$table}) {
789
                push @{$model->columns}, $column;
790
            }
791
        }
792
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
793
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
794
}
795

            
cleanup
yuki-kimoto authored on 2010-10-17
796
our %VALID_UPDATE_ARGS
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
797
  = map { $_ => 1 } qw/table param
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
798
                       where append filter allow_update_all query/;
cleanup
yuki-kimoto authored on 2010-10-17
799

            
800
sub update {
801
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
802
    
cleanup
yuki-kimoto authored on 2010-10-17
803
    # Check arguments
804
    foreach my $name (keys %args) {
805
        croak qq{"$name" is invalid argument}
806
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
807
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
808
    
cleanup
yuki-kimoto authored on 2010-10-17
809
    # Arguments
810
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
811
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
812
    my $param            = $args{param} || {};
813
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
814
    my $append           = $args{append} || '';
cleanup
yuki-kimoto authored on 2010-10-17
815
    my $filter           = $args{filter};
816
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
817
    
cleanup
yuki-kimoto authored on 2010-10-17
818
    # Update keys
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
819
    my @clumns = keys %$param;
820

            
821
    # Columns
822
    my @columns;
823
    my $safety = $self->safety_column_name;
824
    foreach my $column (keys %$param) {
825
        croak qq{"$column" is not safety column name}
826
          unless $column =~ /$safety/;
827
        push @columns, $column;
828
    }
829
        
cleanup
yuki-kimoto authored on 2010-10-17
830
    # Update clause
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
831
    my $update_clause = '{update_param ' . join(' ', @clumns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
832

            
833
    # Where
834
    my $w;
835
    if (ref $where eq 'HASH') {
836
        my $clause = ['and'];
837
        push @$clause, "{= $_}" for keys %$where;
838
        $w = $self->where;
839
        $w->clause($clause);
840
        $w->param($where);
841
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
842
    elsif (ref $where eq 'DBIx::Custom::Where') {
843
        $w = $where;
844
        $where = $w->param;
845
    }  
removed experimental registe...
yuki-kimoto authored on 2010-08-24
846
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
847
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
848
      unless ref $w eq 'DBIx::Custom::Where';
removed reconnect method
yuki-kimoto authored on 2010-05-28
849
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
850
    # String where
851
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
852
    
853
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
854
      if "$swhere" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
855
    
cleanup
Yuki Kimoto authored on 2011-01-27
856
    # SQL stack
857
    my @sql;
858
    
859
    # Update
860
    push @sql, "update $table $update_clause $swhere";
861
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
862
    
cleanup
yuki-kimoto authored on 2010-10-17
863
    # Rearrange parameters
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
864
    foreach my $wkey (keys %$where) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
865
        
cleanup
yuki-kimoto authored on 2010-10-17
866
        if (exists $param->{$wkey}) {
867
            $param->{$wkey} = [$param->{$wkey}]
868
              unless ref $param->{$wkey} eq 'ARRAY';
869
            
870
            push @{$param->{$wkey}}, $where->{$wkey};
871
        }
872
        else {
873
            $param->{$wkey} = $where->{$wkey};
874
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
875
    }
cleanup
yuki-kimoto authored on 2010-10-17
876
    
cleanup
Yuki Kimoto authored on 2011-01-27
877
    # SQL
878
    my $sql = join(' ', @sql);
879
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
880
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
881
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
882
    return $query if $args{query};
883
    
cleanup
yuki-kimoto authored on 2010-10-17
884
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
885
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
886
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
887
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
888
    
889
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
890
}
891

            
cleanup
yuki-kimoto authored on 2010-10-17
892
sub update_all { shift->update(allow_update_all => 1, @_) };
893

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
894
our %VALID_UPDATE_AT_ARGS
895
  = map { $_ => 1 } qw/table param
896
                       where append filter query
897
                       primary_key param/;
898

            
899
sub update_at {
900
    my ($self, %args) = @_;
901
    
902
    # Check arguments
903
    foreach my $name (keys %args) {
904
        croak qq{"$name" is invalid argument}
905
          unless $VALID_UPDATE_AT_ARGS{$name};
906
    }
907
    
908
    # Primary key
909
    my $primary_keys = delete $args{primary_key};
910
    $primary_keys = [$primary_keys] unless ref $primary_keys;
911
    
912
    # Where clause
913
    my $where = {};
914
    my $param = {};
915
    
916
    if (exists $args{where}) {
917
        my $where_columns = delete $args{where};
918
        $where_columns = [$where_columns] unless ref $where_columns;
919
        
920
        for(my $i = 0; $i < @$primary_keys; $i ++) {
921
           $where->{$primary_keys->[$i]} = $where_columns->[$i];
922
        }
923
    }
924
    elsif (exists $args{param}) {
925
        $param = delete $args{param};
926
        for(my $i = 0; $i < @$primary_keys; $i ++) {
927
           $where->{$primary_keys->[$i]}
928
             = delete $param->{$primary_keys->[$i]};
929
        }
930
    }
931
    
932
    return $self->update(where => $where, param => $param, %args);
933
}
934

            
cleanup
Yuki Kimoto authored on 2011-01-25
935
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
936
    my $self = shift;
937

            
938
    return DBIx::Custom::Where->new(
939
        query_builder => $self->query_builder,
940
        safety_column_name => $self->safety_column_name
941
    );
cleanup
Yuki Kimoto authored on 2011-01-25
942
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
943

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
944
sub _bind {
cleanup
Yuki Kimoto authored on 2011-01-12
945
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
946
    
cleanup
Yuki Kimoto authored on 2011-01-12
947
    # bind values
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
948
    my @bind;
add tests
yuki-kimoto authored on 2010-08-08
949
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
950
    # Build bind values
951
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
952
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
953
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
954
        
955
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
956
        my $value;
957
        if(ref $params->{$column} eq 'ARRAY') {
958
            my $i = $count->{$column} || 0;
959
            $i += $not_exists->{$column} || 0;
960
            my $found;
961
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
962
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
963
                    $not_exists->{$column}++;
964
                }
965
                else  {
966
                    $value = $params->{$column}->[$k];
967
                    $found = 1;
968
                    last
969
                }
970
            }
971
            next unless $found;
972
        }
973
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
974
        
cleanup
Yuki Kimoto authored on 2011-01-12
975
        # Filter
976
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
977
        
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
978
        push @bind, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
979
        
980
        # Count up 
981
        $count->{$column}++;
982
    }
983
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
984
    return \@bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
985
}
986

            
cleanup
yuki-kimoto authored on 2010-10-17
987
sub _croak {
988
    my ($self, $error, $append) = @_;
989
    $append ||= "";
990
    
991
    # Verbose
992
    if ($Carp::Verbose) { croak $error }
993
    
994
    # Not verbose
995
    else {
996
        
997
        # Remove line and module infromation
998
        my $at_pos = rindex($error, ' at ');
999
        $error = substr($error, 0, $at_pos);
1000
        $error =~ s/\s+$//;
1001
        
1002
        croak "$error$append";
1003
    }
1004
}
1005

            
cleanup
Yuki Kimoto authored on 2011-01-25
1006
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1007
__PACKAGE__->attr(
1008
    dbi_options => sub { {} },
1009
    filter_check  => 1
1010
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1011

            
cleanup
Yuki Kimoto authored on 2011-01-25
1012
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1013
sub default_bind_filter {
1014
    my $self = shift;
1015
    
1016
    if (@_) {
1017
        my $fname = $_[0];
1018
        
1019
        if (@_ && !$fname) {
1020
            $self->{default_out_filter} = undef;
1021
        }
1022
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1023
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1024
              unless exists $self->filters->{$fname};
1025
        
1026
            $self->{default_out_filter} = $self->filters->{$fname};
1027
        }
1028
        return $self;
1029
    }
1030
    
1031
    return $self->{default_out_filter};
1032
}
1033

            
cleanup
Yuki Kimoto authored on 2011-01-25
1034
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1035
sub default_fetch_filter {
1036
    my $self = shift;
1037
    
1038
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1039
        my $fname = $_[0];
1040

            
cleanup
Yuki Kimoto authored on 2011-01-12
1041
        if (@_ && !$fname) {
1042
            $self->{default_in_filter} = undef;
1043
        }
1044
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1045
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1046
              unless exists $self->filters->{$fname};
1047
        
1048
            $self->{default_in_filter} = $self->filters->{$fname};
1049
        }
1050
        
1051
        return $self;
1052
    }
1053
    
many changed
Yuki Kimoto authored on 2011-01-23
1054
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1055
}
1056

            
cleanup
Yuki Kimoto authored on 2011-01-25
1057
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1058
sub register_tag_processor {
1059
    return shift->query_builder->register_tag_processor(@_);
1060
}
1061

            
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
1062
1;
1063

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1064
=head1 NAME
1065

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1066
DBIx::Custom - DBI interface, having hash parameter binding and filtering system
removed reconnect method
yuki-kimoto authored on 2010-05-28
1067

            
1068
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1069

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1070
    use DBIx::Custom;
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1071
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1072
                                    user => 'ken', password => '!LFKD%$&',
1073
                                    dbi_option => {mysql_enable_utf8 => 1});
cleanup
yuki-kimoto authored on 2010-08-05
1074

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1075
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1076
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1077
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1078
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1079
    
1080
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1081
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1082
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
1083
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1084
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1085
    
1086
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1087
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1088
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1089
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1090
    
1091
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1092
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
1093
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1094
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1095
    
1096
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1097
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
1098

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1099
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
1100
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1101
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
1102
        column => [qw/author title/],
1103
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1104
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
1105
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1106
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
1107
    );
cleanup
yuki-kimoto authored on 2010-08-05
1108

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1109
    # Execute SQL
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1110
    $dbi->execute("select title from book");
removed register_format()
yuki-kimoto authored on 2010-05-26
1111
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1112
    # Execute SQL with hash binding and filtering
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1113
    $dbi->execute("select id from book where {= author} and {like title}",
removed register_format()
yuki-kimoto authored on 2010-05-26
1114
                  param  => {author => 'ken', title => '%Perl%'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1115
                  filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1116

            
1117
    # Create query and execute it
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1118
    my $query = $dbi->create_query(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1119
        "select id from book where {= author} and {like title}"
removed reconnect method
yuki-kimoto authored on 2010-05-28
1120
    );
updated document
yuki-kimoto authored on 2010-08-08
1121
    $dbi->execute($query, param => {author => 'Ken', title => '%Perl%'})
cleanup
yuki-kimoto authored on 2010-08-05
1122

            
1123
    # Get DBI object
1124
    my $dbh = $dbi->dbh;
1125

            
removed register_format()
yuki-kimoto authored on 2010-05-26
1126
    # Fetch
1127
    while (my $row = $result->fetch) {
1128
        # ...
1129
    }
1130
    
1131
    # Fetch hash
1132
    while (my $row = $result->fetch_hash) {
1133
        
1134
    }
1135
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1136
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1137

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1138
L<DBIx::Custom> is one of L<DBI> interface modules,
1139
such as L<DBIx::Class>, L<DBIx::Simple>.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1140

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1141
This module is not O/R mapper. O/R mapper is useful,
1142
but you must learn many syntax of the O/R mapper,
updated document
yuki-kimoto authored on 2010-08-08
1143
which is almost another language.
1144
Created SQL statement is offten not effcient and damage SQL performance.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1145
so you have to execute raw SQL in the end.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1146

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1147
L<DBIx::Custom> is middle area between L<DBI> and O/R mapper.
updated document
yuki-kimoto authored on 2010-08-08
1148
L<DBIx::Custom> provide flexible hash parameter binding and filtering system,
added experimental expand me...
yuki-kimoto authored on 2010-10-20
1149
and suger methods, such as C<insert()>, C<update()>, C<delete()>, C<select()>
updated document
yuki-kimoto authored on 2010-08-08
1150
to execute SQL easily.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1151

            
updated document
yuki-kimoto authored on 2010-08-08
1152
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful,
1153
but de-facto standard,
1154
so all people learing database know it.
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1155
If you already know SQL,
1156
you learn a little thing to use L<DBIx::Custom>.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1157

            
pod fix
Yuki Kimoto authored on 2011-01-21
1158
See L<DBIx::Custom::Guide> for more details.
1159

            
1160
=head1 GUIDE
1161

            
1162
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
1163

            
1164
=head1 EXAMPLES
1165

            
1166
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> - Many useful examples
updated document
yuki-kimoto authored on 2010-08-08
1167

            
update document
yuki-kimoto authored on 2010-01-30
1168
=head1 ATTRIBUTES
packaging one directory
yuki-kimoto authored on 2009-11-16
1169

            
cleanup
yuki-kimoto authored on 2010-10-17
1170
=head2 C<cache>
packaging one directory
yuki-kimoto authored on 2009-11-16
1171

            
cleanup
yuki-kimoto authored on 2010-10-17
1172
    my $cache = $dbi->cache;
1173
    $dbi      = $dbi->cache(1);
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1174

            
cleanup
yuki-kimoto authored on 2010-10-17
1175
Enable parsed L<DBIx::Custom::Query> object caching.
1176
Default to 1.
packaging one directory
yuki-kimoto authored on 2009-11-16
1177

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1178
=head2 C<data_source>
packaging one directory
yuki-kimoto authored on 2009-11-16
1179

            
cleanup
yuki-kimoto authored on 2010-08-03
1180
    my $data_source = $dbi->data_source;
cleanup
yuki-kimoto authored on 2010-08-05
1181
    $dbi            = $dbi->data_source("DBI:mysql:database=dbname");
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1182

            
cleanup
yuki-kimoto authored on 2010-08-05
1183
Data source.
1184
C<connect()> method use this value to connect the database.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1185

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1186
=head2 C<dbh>
packaging one directory
yuki-kimoto authored on 2009-11-16
1187

            
cleanup
yuki-kimoto authored on 2010-08-03
1188
    my $dbh = $dbi->dbh;
1189
    $dbi    = $dbi->dbh($dbh);
packaging one directory
yuki-kimoto authored on 2009-11-16
1190

            
cleanup
yuki-kimoto authored on 2010-08-05
1191
L<DBI> object. You can call all methods of L<DBI>.
packaging one directory
yuki-kimoto authored on 2009-11-16
1192

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1193
=head2 C<dbi_option>
added dbi_options attribute
kimoto authored on 2010-12-20
1194

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1195
    my $dbi_option = $dbi->dbi_option;
1196
    $dbi            = $dbi->dbi_option($dbi_option);
added dbi_options attribute
kimoto authored on 2010-12-20
1197

            
1198
DBI options.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1199

            
1200
Each option specified can ovewrite C<default_dbi_option>.
1201

            
1202
C<connect()> method use this value to connect the database.
1203

            
1204

            
1205
=head2 C<default_dbi_option>
1206

            
1207
    my $default_dbi_option = $dbi->default_dbi_option;
1208
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1209

            
1210
DBI default options.
1211

            
1212
    RaiseError => 1,
1213
    PrintError => 0,
1214
    AutoCommit => 1,
1215

            
added dbi_options attribute
kimoto authored on 2010-12-20
1216
C<connect()> method use this value to connect the database.
1217

            
cleanup
yuki-kimoto authored on 2010-08-05
1218
Default filter when row is fetched.
packaging one directory
yuki-kimoto authored on 2009-11-16
1219

            
cleanup
yuki-kimoto authored on 2010-10-17
1220
=head2 C<filters>
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1221

            
cleanup
yuki-kimoto authored on 2010-10-17
1222
    my $filters = $dbi->filters;
1223
    $dbi        = $dbi->filters(\%filters);
packaging one directory
yuki-kimoto authored on 2009-11-16
1224

            
add models() attribute
Yuki Kimoto authored on 2011-02-21
1225
Filters
1226

            
1227
=head2 C<(experimental) models>
1228

            
1229
    my $models = $dbi->models;
1230
    $dbi       = $dbi->models(\%models);
1231

            
1232
Models
1233

            
cleanup
yuki-kimoto authored on 2010-10-17
1234
=head2 C<password>
1235

            
1236
    my $password = $dbi->password;
1237
    $dbi         = $dbi->password('lkj&le`@s');
1238

            
1239
Password.
1240
C<connect()> method use this value to connect the database.
update document
yuki-kimoto authored on 2010-01-30
1241

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1242
=head2 C<query_builder>
added commit method
yuki-kimoto authored on 2010-05-27
1243

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1244
    my $sql_class = $dbi->query_builder;
1245
    $dbi          = $dbi->query_builder(DBIx::Custom::QueryBuilder->new);
added commit method
yuki-kimoto authored on 2010-05-27
1246

            
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1247
SQL builder. C<query_builder()> must be 
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1248
the instance of L<DBIx::Custom::QueryBuilder> subclass.
1249
Default to L<DBIx::Custom::QueryBuilder> object.
cleanup
yuki-kimoto authored on 2010-08-05
1250

            
cleanup
yuki-kimoto authored on 2010-10-17
1251
=head2 C<result_class>
cleanup
yuki-kimoto authored on 2010-08-05
1252

            
cleanup
yuki-kimoto authored on 2010-10-17
1253
    my $result_class = $dbi->result_class;
1254
    $dbi             = $dbi->result_class('DBIx::Custom::Result');
cleanup
yuki-kimoto authored on 2010-08-05
1255

            
cleanup
yuki-kimoto authored on 2010-10-17
1256
Result class for select statement.
1257
Default to L<DBIx::Custom::Result>.
cleanup
yuki-kimoto authored on 2010-08-05
1258

            
update pod
Yuki Kimoto authored on 2011-01-27
1259
=head2 C<(experimental) safety_column_name>
1260

            
1261
    my $safety_column_name = $self->safety_column_name;
1262
    $dbi                   = $self->safety_column_name($name);
1263

            
1264
Safety column name regex.
1265
Default is qr/^[\w\.]*$/
1266

            
cleanup
yuki-kimoto authored on 2010-10-17
1267
=head2 C<user>
cleanup
yuki-kimoto authored on 2010-08-05
1268

            
cleanup
yuki-kimoto authored on 2010-10-17
1269
    my $user = $dbi->user;
1270
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1271

            
cleanup
yuki-kimoto authored on 2010-10-17
1272
User name.
1273
C<connect()> method use this value to connect the database.
update pod
Yuki Kimoto authored on 2011-01-27
1274

            
cleanup
yuki-kimoto authored on 2010-10-17
1275
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
1276

            
cleanup
yuki-kimoto authored on 2010-10-17
1277
L<DBIx::Custom> inherits all methods from L<Object::Simple>
autoload DBI method
Yuki Kimoto authored on 2011-01-26
1278
and use all method of L<DBI>
cleanup
yuki-kimoto authored on 2010-10-17
1279
and implements the following new ones.
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1280

            
cleanup
Yuki Kimoto authored on 2011-01-25
1281
=head2 C<(experimental) apply_filter>
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1282

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1283
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1284
        $table,
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1285
        $column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1}
1286
        $column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2}
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1287
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1288
    );
1289

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1290
C<apply_filter> is automatically filter for columns of table.
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1291
This have effect C<insert>, C<update>, C<delete>. C<select>
cleanup
Yuki Kimoto authored on 2010-12-21
1292
and L<DBIx::Custom::Result> object. but this has'nt C<execute> method.
1293

            
cleanup
Yuki Kimoto authored on 2011-01-12
1294
If you want to have effect C<execute()> method, use C<table>
cleanup
Yuki Kimoto authored on 2010-12-21
1295
arguments.
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1296

            
cleanup
Yuki Kimoto authored on 2010-12-21
1297
    $result = $dbi->execute(
1298
        "select * from table1 where {= key1} and {= key2};",
1299
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1300
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
1301
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1302

            
1303
You can use three name as column name.
1304

            
1305
    1. column        : author
1306
    2. table.column  : book.author
1307
    3. table__column : book__author
1308

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1309
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1310

            
cleanup
yuki-kimoto authored on 2010-08-05
1311
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
update document
yuki-kimoto authored on 2010-05-27
1312
                                    user => 'ken', password => '!LFKD%$&');
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1313

            
cleanup
yuki-kimoto authored on 2010-08-05
1314
Create a new L<DBIx::Custom> object and connect to the database.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1315
L<DBIx::Custom> is a wrapper of L<DBI>.
cleanup
yuki-kimoto authored on 2010-08-09
1316
C<AutoCommit> and C<RaiseError> options are true, 
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1317
and C<PrintError> option is false by default. 
packaging one directory
yuki-kimoto authored on 2009-11-16
1318

            
cleanup
yuki-kimoto authored on 2010-10-17
1319
=head2 C<create_query>
1320
    
1321
    my $query = $dbi->create_query(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1322
        "select * from book where {= author} and {like title};"
cleanup
yuki-kimoto authored on 2010-10-17
1323
    );
update document
yuki-kimoto authored on 2009-11-19
1324

            
cleanup
yuki-kimoto authored on 2010-10-17
1325
Create the instance of L<DBIx::Custom::Query> from the source of SQL.
1326
If you want to get high performance,
1327
use C<create_query()> method and execute it by C<execute()> method
1328
instead of suger methods.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1329

            
cleanup
yuki-kimoto authored on 2010-10-17
1330
    $dbi->execute($query, {author => 'Ken', title => '%Perl%'});
version 0.0901
yuki-kimoto authored on 2009-12-17
1331

            
cleanup
yuki-kimoto authored on 2010-10-17
1332
=head2 C<execute>
packaging one directory
yuki-kimoto authored on 2009-11-16
1333

            
cleanup
yuki-kimoto authored on 2010-10-17
1334
    my $result = $dbi->execute($query,  param => $params, filter => \%filter);
1335
    my $result = $dbi->execute($source, param => $params, filter => \%filter);
update document
yuki-kimoto authored on 2009-11-19
1336

            
cleanup
yuki-kimoto authored on 2010-10-17
1337
Execute query or the source of SQL.
1338
Query is L<DBIx::Custom::Query> object.
1339
Return value is L<DBIx::Custom::Result> if select statement is executed,
1340
or the count of affected rows if insert, update, delete statement is executed.
version 0.0901
yuki-kimoto authored on 2009-12-17
1341

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1342
=head2 C<delete>
packaging one directory
yuki-kimoto authored on 2009-11-16
1343

            
cleanup
yuki-kimoto authored on 2010-08-05
1344
    $dbi->delete(table  => $table,
1345
                 where  => \%where,
1346
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1347
                 filter => \%filter,
1348
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1349

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1350
Execute delete statement.
1351
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments.
1352
C<table> is a table name.
1353
C<where> is where clause. this must be hash reference.
1354
C<append> is a string added at the end of the SQL statement.
1355
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1356
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1357
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-08-09
1358
Return value of C<delete()> is the count of affected rows.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1359

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1360
=head2 C<delete_all>
packaging one directory
yuki-kimoto authored on 2009-11-16
1361

            
cleanup
yuki-kimoto authored on 2010-08-05
1362
    $dbi->delete_all(table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
1363

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1364
Execute delete statement to delete all rows.
1365
Arguments is same as C<delete> method,
1366
except that C<delete_all> don't have C<where> argument.
cleanup
yuki-kimoto authored on 2010-08-09
1367
Return value of C<delete_all()> is the count of affected rows.
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1368

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1369
=head3 C<delete_at()>
1370

            
1371
To delete row by using primary key, use C<delete_at()>
1372

            
1373
    $dbi->delete_at(
1374
        table => 'book',
1375
        primary_key => ['id'],
1376
        where => ['123']
1377
    );
1378

            
1379
In this example, row which id column is 123 is deleted.
1380
NOTE that you must pass array reference as C<where>.
1381

            
1382
You can also write arguments like this.
1383

            
1384
    $dbi->delete_at(
1385
        table => 'book',
1386
        primary_key => ['id'],
1387
        param => {id => '123'}
1388
    );
1389

            
cleanup
yuki-kimoto authored on 2010-10-17
1390
=head2 C<insert>
1391

            
1392
    $dbi->insert(table  => $table, 
1393
                 param  => \%param,
1394
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1395
                 filter => \%filter,
1396
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1397

            
1398
Execute insert statement.
1399
C<insert> method have C<table>, C<param>, C<append>
1400
and C<filter> arguments.
1401
C<table> is a table name.
1402
C<param> is the pairs of column name value. this must be hash reference.
1403
C<append> is a string added at the end of the SQL statement.
1404
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1405
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1406
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1407
This is overwrites C<default_bind_filter>.
1408
Return value of C<insert()> is the count of affected rows.
1409

            
pod fix
Yuki Kimoto authored on 2011-01-21
1410
=head2 C<(experimental) each_column>
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1411

            
pod fix
Yuki Kimoto authored on 2011-01-21
1412
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1413
        sub {
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1414
            my ($self, $table, $column, $column_info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1415
            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1416
            my $type = $column_info->{TYPE_NAME};
pod fix
Yuki Kimoto authored on 2011-01-21
1417
            
1418
            if ($type eq 'DATE') {
1419
                # ...
1420
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1421
        }
1422
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1423
Get column informations from database.
1424
Argument is callback.
1425
You can do anything in callback.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1426
Callback receive four arguments, dbi object, table name,
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1427
column name and column information.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1428

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1429
=head2 C<(experimental) include_model>
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1430

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1431
    $dbi->include_model(
1432
        'MyModel' => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1433
            'book', 'person', 'company'
1434
        ]
1435
    );
1436

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1437
Include models. First argument is name space.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1438
Second argument is array reference of class base names.
1439

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1440
If you don't specify second argument, All models under name space is
1441
included.
1442

            
1443
    $dbi->include_model('MyModel');
1444

            
1445
Note that in this case name spece module is needed.
1446

            
1447
    # MyModel.pm
1448
    package MyModel;
1449
    
1450
    use base 'DBIx::Custom::Model';
1451

            
1452
The following model is instantiated and included.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1453

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1454
    MyModel::book
1455
    MyModel::person
1456
    MyModel::company
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1457

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1458
You can get these instance by C<model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1459

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1460
    my $book_model = $dbi->model('book');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1461

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1462
If you want to other name as model class,
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1463
you can do like this.
1464

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1465
    $dbi->include_model(
1466
        'MyModel' => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1467
            {'book' => 'Book'},
1468
            {'person' => 'Person'}
1469
        ]
1470
    );
1471

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1472
=head2 C<(experimental) method>
1473

            
1474
    $dbi->method(
1475
        update_or_insert => sub {
1476
            my $self = shift;
1477
            # do something
1478
        },
1479
        find_or_create   => sub {
1480
            my $self = shift;
1481
            # do something
1482
        }
1483
    );
1484

            
1485
Register method. These method is called from L<DBIx::Custom> object directory.
1486

            
1487
    $dbi->update_or_insert;
1488
    $dbi->find_or_create;
1489

            
1490
=head2 C<new>
1491

            
1492
    my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname",
1493
                                    user => 'ken', password => '!LFKD%$&');
1494

            
1495
Create a new L<DBIx::Custom> object.
1496

            
1497
=head2 C<(experimental) not_exists>
1498

            
1499
    my $not_exists = $dbi->not_exists;
1500

            
1501
Get DBIx::Custom::NotExists object.
experimental extended select...
Yuki Kimoto authored on 2011-01-17
1502

            
cleanup
yuki-kimoto authored on 2010-10-17
1503
=head2 C<register_filter>
1504

            
1505
    $dbi->register_filter(%filters);
1506
    $dbi->register_filter(\%filters);
1507
    
1508
Register filter. Registered filters is available in the following attributes
1509
or arguments.
1510

            
1511
=over 4
1512

            
1513
=item *
1514

            
1515
C<filter> argument of C<insert()>, C<update()>,
1516
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1517
methods
1518

            
1519
=item *
1520

            
1521
C<execute()> method
1522

            
1523
=item *
1524

            
1525
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1526

            
1527
=item *
1528

            
1529
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1530

            
1531
=back
1532

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1533
=head2 C<register_tag>
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1534

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1535
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1536
        limit => sub {
1537
            ...;
1538
        }
1539
    );
1540

            
cleanup
Yuki Kimoto authored on 2011-01-25
1541
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1542

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1543
=head2 C<rollback>
cleanup
yuki-kimoto authored on 2010-10-17
1544

            
1545
    $dbi->rollback;
1546

            
1547
Rollback transaction.
1548
This is same as L<DBI>'s C<rollback>.
1549

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1550
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1551
    
select method column option ...
Yuki Kimoto authored on 2011-02-22
1552
    my $result = $dbi->select(
1553
        table     => $table,
1554
        column    => [@column],
1555
        where     => \%where,
1556
        append    => $append,
1557
        relation  => \%relation,
1558
        filter    => \%filter,
1559
        query     => 1,
1560
        selection => $selection
1561
    );
update document
yuki-kimoto authored on 2009-11-19
1562

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1563
Execute select statement.
cleanup
yuki-kimoto authored on 2010-08-09
1564
C<select> method have C<table>, C<column>, C<where>, C<append>,
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1565
C<relation> and C<filter> arguments.
1566
C<table> is a table name.
select method column option ...
Yuki Kimoto authored on 2011-02-22
1567
C<column> is column names. this is array reference or string.
cleanup
yuki-kimoto authored on 2010-08-09
1568
C<where> is where clause. this is normally hash reference.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1569
C<append> is a string added at the end of the SQL statement.
1570
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1571
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1572
default to 0. This is experimental.
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1573
C<selection> is string of column name and tables. This is experimental
1574

            
1575
    selection => 'name, location.name as location_name ' .
1576
                 'from company inner join location'
update document
yuki-kimoto authored on 2009-11-19
1577

            
cleanup
yuki-kimoto authored on 2010-08-09
1578
First element is a string. it contains tags,
1579
such as "{= title} or {like author}".
1580
Second element is paramters.
1581

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1582
=head3 C<select_at()>
1583

            
1584
To select row by using primary key, use C<select_at()>.
1585

            
1586
    $dbi->select_at(table => 'book', primary_key => ['id'], where => ['123']);
1587

            
1588
In this example, row which id colunm is 123 is selected.
1589
NOTE that you must pass array reference as C<where>.
1590

            
cleanup
yuki-kimoto authored on 2010-10-17
1591
=head2 C<update>
removed reconnect method
yuki-kimoto authored on 2010-05-28
1592

            
cleanup
yuki-kimoto authored on 2010-10-17
1593
    $dbi->update(table  => $table, 
1594
                 param  => \%params,
1595
                 where  => \%where,
1596
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1597
                 filter => \%filter,
1598
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1599

            
cleanup
yuki-kimoto authored on 2010-10-17
1600
Execute update statement.
1601
C<update> method have C<table>, C<param>, C<where>, C<append>
1602
and C<filter> arguments.
1603
C<table> is a table name.
1604
C<param> is column-value pairs. this must be hash reference.
1605
C<where> is where clause. this must be hash reference.
1606
C<append> is a string added at the end of the SQL statement.
1607
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1608
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1609
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1610
This is overwrites C<default_bind_filter>.
1611
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1612

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1613
=head2 C<(experimental) model>
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1614

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1615
    $dbi->model('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1616
        insert => sub { ... },
1617
        update => sub { ... }
1618
    );
1619
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1620
    my $model = $dbi->model('book');
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1621

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1622
Set and get a L<DBIx::Custom::Model> object,
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1623

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1624
=head2 C<(experimental) setup_model>
1625

            
1626
    $dbi->setup_model;
1627

            
1628
Setup all model objects.
1629
C<columns> and C<primary_key> is automatically set.
1630

            
cleanup
yuki-kimoto authored on 2010-10-17
1631
=head2 C<update_all>
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1632

            
cleanup
yuki-kimoto authored on 2010-10-17
1633
    $dbi->update_all(table  => $table, 
1634
                     param  => \%params,
1635
                     filter => \%filter,
1636
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1637

            
cleanup
yuki-kimoto authored on 2010-10-17
1638
Execute update statement to update all rows.
1639
Arguments is same as C<update> method,
1640
except that C<update_all> don't have C<where> argument.
1641
Return value of C<update_all()> is the count of affected rows.
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1642

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1643
=head3 C<update_at()>
1644

            
1645
To update row by using primary key, use C<update_at()>
1646

            
1647
    $dbi->update_at(
1648
        table => 'book',
1649
        primary_key => ['id'],
1650
        where => ['123'],
1651
        param => {name => 'Ken'}
1652
    );
1653

            
1654
In this example, row which id column is 123 is updated.
1655
NOTE that you must pass array reference as C<where>.
1656
If C<param> contains primary key,
1657
the key and value is delete from C<param>.
1658

            
fix tests
Yuki Kimoto authored on 2011-01-18
1659
=head2 C<(experimental) where>
1660

            
1661
    my $where = $dbi->where;
1662

            
1663
Create a new L<DBIx::Custom::Where> object.
1664

            
cleanup
Yuki Kimoto authored on 2011-01-25
1665
=head2 C<cache_method>
cleanup
Yuki Kimoto authored on 2011-01-12
1666

            
1667
    $dbi          = $dbi->cache_method(\&cache_method);
1668
    $cache_method = $dbi->cache_method
1669

            
1670
Method to set and get caches.
1671

            
cleanup
Yuki Kimoto authored on 2011-01-25
1672
=head1 Tags
1673

            
1674
The following tags is available.
1675

            
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1676
=head2 C<(experimental) table>
add table tag
Yuki Kimoto authored on 2011-02-09
1677

            
1678
Table tag
1679

            
1680
    {table TABLE}    ->    TABLE
1681

            
1682
This is used to teach what is applied table to C<execute()>.
1683

            
cleanup
Yuki Kimoto authored on 2011-01-25
1684
=head2 C<?>
1685

            
1686
Placeholder tag.
1687

            
1688
    {? NAME}    ->   ?
1689

            
1690
=head2 C<=>
1691

            
1692
Equal tag.
1693

            
1694
    {= NAME}    ->   NAME = ?
1695

            
1696
=head2 C<E<lt>E<gt>>
1697

            
1698
Not equal tag.
1699

            
1700
    {<> NAME}   ->   NAME <> ?
1701

            
1702
=head2 C<E<lt>>
1703

            
1704
Lower than tag
1705

            
1706
    {< NAME}    ->   NAME < ?
1707

            
1708
=head2 C<E<gt>>
1709

            
1710
Greater than tag
1711

            
1712
    {> NAME}    ->   NAME > ?
1713

            
1714
=head2 C<E<gt>=>
1715

            
1716
Greater than or equal tag
1717

            
1718
    {>= NAME}   ->   NAME >= ?
1719

            
1720
=head2 C<E<lt>=>
1721

            
1722
Lower than or equal tag
1723

            
1724
    {<= NAME}   ->   NAME <= ?
1725

            
1726
=head2 C<like>
1727

            
1728
Like tag
1729

            
1730
    {like NAME}   ->   NAME like ?
1731

            
1732
=head2 C<in>
1733

            
1734
In tag.
1735

            
1736
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1737

            
1738
=head2 C<insert_param>
1739

            
1740
Insert parameter tag.
1741

            
1742
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1743

            
1744
=head2 C<update_param>
1745

            
1746
Updata parameter tag.
1747

            
1748
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1749

            
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
1750
=head1 STABILITY
1751

            
cleanup
Yuki Kimoto authored on 2011-01-25
1752
L<DBIx::Custom> is stable. APIs keep backword compatible
1753
except experimental one in the feature.
DBIx::Custom is now stable
yuki-kimoto authored on 2010-09-07
1754

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1755
=head1 BUGS
1756

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1757
Please tell me bugs if found.
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
1758

            
1759
C<< <kimoto.yuki at gmail.com> >>
1760

            
1761
L<http://github.com/yuki-kimoto/DBIx-Custom>
1762

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1763
=head1 AUTHOR
1764

            
1765
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
version 0.0901
yuki-kimoto authored on 2009-12-17
1766

            
packaging one directory
yuki-kimoto authored on 2009-11-16
1767
=head1 COPYRIGHT & LICENSE
1768

            
cleanup
Yuki Kimoto authored on 2011-01-25
1769
Copyright 2009-2011 Yuki Kimoto, all rights reserved.
packaging one directory
yuki-kimoto authored on 2009-11-16
1770

            
1771
This program is free software; you can redistribute it and/or modify it
1772
under the same terms as Perl itself.
1773

            
1774
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1775

            
1776