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

            
add models() attribute
Yuki Kimoto authored on 2011-02-21
3
our $VERSION = '0.1648';
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} || [];
553
    my $selection = $args{selection} || '';
554
    my $where     = $args{where} || {};
555
    my $relation  = $args{relation};
556
    my $append    = $args{append};
557
    my $filter    = $args{filter};
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
558

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

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

            
661
sub select_at {
662
    my ($self, %args) = @_;
663
    
664
    # Check arguments
665
    foreach my $name (keys %args) {
666
        croak qq{"$name" is invalid argument}
667
          unless $VALID_SELECT_AT_ARGS{$name};
668
    }
669
    
670
    # Primary key
671
    my $primary_keys = delete $args{primary_key};
672
    $primary_keys = [$primary_keys] unless ref $primary_keys;
673
    
674
    # Where clause
675
    my $where = {};
676
    if (exists $args{where}) {
677
        my $where_columns = delete $args{where};
678
        $where_columns = [$where_columns] unless ref $where_columns;
679
        
680
        for(my $i = 0; $i < @$primary_keys; $i ++) {
681
           $where->{$primary_keys->[$i]} = $where_columns->[$i];
682
        }
683
    }
684
    elsif (exists $args{param}) {
685
        my $param = delete $args{param};
686
        for(my $i = 0; $i < @$primary_keys; $i ++) {
687
           $where->{$primary_keys->[$i]}
688
             = delete $param->{$primary_keys->[$i]};
689
        }
690
    }
691
    
692
    return $self->select(where => $where, %args);
693
}
694

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

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

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
767
sub setup_model {
768
    my $self = shift;
769
    
770
    $self->each_column(
771
        sub {
772
            my ($self, $table, $column, $column_info) = @_;
773
            
774
            if (my $model = $self->models->{$table}) {
775
                push @{$model->columns}, $column;
776
            }
777
        }
778
    );
779
}
780

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

            
785
sub update {
786
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
787
    
cleanup
yuki-kimoto authored on 2010-10-17
788
    # Check arguments
789
    foreach my $name (keys %args) {
790
        croak qq{"$name" is invalid argument}
791
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
792
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
793
    
cleanup
yuki-kimoto authored on 2010-10-17
794
    # Arguments
795
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
796
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
797
    my $param            = $args{param} || {};
798
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
799
    my $append           = $args{append} || '';
cleanup
yuki-kimoto authored on 2010-10-17
800
    my $filter           = $args{filter};
801
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
802
    
cleanup
yuki-kimoto authored on 2010-10-17
803
    # Update keys
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
804
    my @clumns = keys %$param;
805

            
806
    # Columns
807
    my @columns;
808
    my $safety = $self->safety_column_name;
809
    foreach my $column (keys %$param) {
810
        croak qq{"$column" is not safety column name}
811
          unless $column =~ /$safety/;
812
        push @columns, $column;
813
    }
814
        
cleanup
yuki-kimoto authored on 2010-10-17
815
    # Update clause
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
816
    my $update_clause = '{update_param ' . join(' ', @clumns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
817

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

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

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
879
our %VALID_UPDATE_AT_ARGS
880
  = map { $_ => 1 } qw/table param
881
                       where append filter query
882
                       primary_key param/;
883

            
884
sub update_at {
885
    my ($self, %args) = @_;
886
    
887
    # Check arguments
888
    foreach my $name (keys %args) {
889
        croak qq{"$name" is invalid argument}
890
          unless $VALID_UPDATE_AT_ARGS{$name};
891
    }
892
    
893
    # Primary key
894
    my $primary_keys = delete $args{primary_key};
895
    $primary_keys = [$primary_keys] unless ref $primary_keys;
896
    
897
    # Where clause
898
    my $where = {};
899
    my $param = {};
900
    
901
    if (exists $args{where}) {
902
        my $where_columns = delete $args{where};
903
        $where_columns = [$where_columns] unless ref $where_columns;
904
        
905
        for(my $i = 0; $i < @$primary_keys; $i ++) {
906
           $where->{$primary_keys->[$i]} = $where_columns->[$i];
907
        }
908
    }
909
    elsif (exists $args{param}) {
910
        $param = delete $args{param};
911
        for(my $i = 0; $i < @$primary_keys; $i ++) {
912
           $where->{$primary_keys->[$i]}
913
             = delete $param->{$primary_keys->[$i]};
914
        }
915
    }
916
    
917
    return $self->update(where => $where, param => $param, %args);
918
}
919

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

            
923
    return DBIx::Custom::Where->new(
924
        query_builder => $self->query_builder,
925
        safety_column_name => $self->safety_column_name
926
    );
cleanup
Yuki Kimoto authored on 2011-01-25
927
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
928

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
929
sub _bind {
cleanup
Yuki Kimoto authored on 2011-01-12
930
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
931
    
cleanup
Yuki Kimoto authored on 2011-01-12
932
    # bind values
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
933
    my @bind;
add tests
yuki-kimoto authored on 2010-08-08
934
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
935
    # Build bind values
936
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
937
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
938
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
939
        
940
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
941
        my $value;
942
        if(ref $params->{$column} eq 'ARRAY') {
943
            my $i = $count->{$column} || 0;
944
            $i += $not_exists->{$column} || 0;
945
            my $found;
946
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
947
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
948
                    $not_exists->{$column}++;
949
                }
950
                else  {
951
                    $value = $params->{$column}->[$k];
952
                    $found = 1;
953
                    last
954
                }
955
            }
956
            next unless $found;
957
        }
958
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
959
        
cleanup
Yuki Kimoto authored on 2011-01-12
960
        # Filter
961
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
962
        
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
963
        push @bind, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
964
        
965
        # Count up 
966
        $count->{$column}++;
967
    }
968
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
969
    return \@bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
970
}
971

            
cleanup
yuki-kimoto authored on 2010-10-17
972
sub _croak {
973
    my ($self, $error, $append) = @_;
974
    $append ||= "";
975
    
976
    # Verbose
977
    if ($Carp::Verbose) { croak $error }
978
    
979
    # Not verbose
980
    else {
981
        
982
        # Remove line and module infromation
983
        my $at_pos = rindex($error, ' at ');
984
        $error = substr($error, 0, $at_pos);
985
        $error =~ s/\s+$//;
986
        
987
        croak "$error$append";
988
    }
989
}
990

            
cleanup
Yuki Kimoto authored on 2011-01-25
991
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
992
__PACKAGE__->attr(
993
    dbi_options => sub { {} },
994
    filter_check  => 1
995
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
996

            
cleanup
Yuki Kimoto authored on 2011-01-25
997
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
998
sub default_bind_filter {
999
    my $self = shift;
1000
    
1001
    if (@_) {
1002
        my $fname = $_[0];
1003
        
1004
        if (@_ && !$fname) {
1005
            $self->{default_out_filter} = undef;
1006
        }
1007
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1008
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1009
              unless exists $self->filters->{$fname};
1010
        
1011
            $self->{default_out_filter} = $self->filters->{$fname};
1012
        }
1013
        return $self;
1014
    }
1015
    
1016
    return $self->{default_out_filter};
1017
}
1018

            
cleanup
Yuki Kimoto authored on 2011-01-25
1019
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1020
sub default_fetch_filter {
1021
    my $self = shift;
1022
    
1023
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1024
        my $fname = $_[0];
1025

            
cleanup
Yuki Kimoto authored on 2011-01-12
1026
        if (@_ && !$fname) {
1027
            $self->{default_in_filter} = undef;
1028
        }
1029
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1030
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1031
              unless exists $self->filters->{$fname};
1032
        
1033
            $self->{default_in_filter} = $self->filters->{$fname};
1034
        }
1035
        
1036
        return $self;
1037
    }
1038
    
many changed
Yuki Kimoto authored on 2011-01-23
1039
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1040
}
1041

            
cleanup
Yuki Kimoto authored on 2011-01-25
1042
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1043
sub register_tag_processor {
1044
    return shift->query_builder->register_tag_processor(@_);
1045
}
1046

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1049
=head1 NAME
1050

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

            
1053
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1054

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1060
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1061
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1062
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1063
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1064
    
1065
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1066
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1067
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
1068
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1069
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1070
    
1071
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1072
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1073
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1074
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1075
    
1076
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1077
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
1078
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1079
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
1080
    
1081
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1082
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
1083

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1084
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
1085
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1086
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
1087
        column => [qw/author title/],
1088
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1089
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
1090
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1091
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
1092
    );
cleanup
yuki-kimoto authored on 2010-08-05
1093

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

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

            
1108
    # Get DBI object
1109
    my $dbh = $dbi->dbh;
1110

            
removed register_format()
yuki-kimoto authored on 2010-05-26
1111
    # Fetch
1112
    while (my $row = $result->fetch) {
1113
        # ...
1114
    }
1115
    
1116
    # Fetch hash
1117
    while (my $row = $result->fetch_hash) {
1118
        
1119
    }
1120
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1121
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1122

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

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

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

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

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

            
1145
=head1 GUIDE
1146

            
1147
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
1148

            
1149
=head1 EXAMPLES
1150

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1183
DBI options.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1184

            
1185
Each option specified can ovewrite C<default_dbi_option>.
1186

            
1187
C<connect()> method use this value to connect the database.
1188

            
1189

            
1190
=head2 C<default_dbi_option>
1191

            
1192
    my $default_dbi_option = $dbi->default_dbi_option;
1193
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1194

            
1195
DBI default options.
1196

            
1197
    RaiseError => 1,
1198
    PrintError => 0,
1199
    AutoCommit => 1,
1200

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

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

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

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

            
add models() attribute
Yuki Kimoto authored on 2011-02-21
1210
Filters
1211

            
1212
=head2 C<(experimental) models>
1213

            
1214
    my $models = $dbi->models;
1215
    $dbi       = $dbi->models(\%models);
1216

            
1217
Models
1218

            
cleanup
yuki-kimoto authored on 2010-10-17
1219
=head2 C<password>
1220

            
1221
    my $password = $dbi->password;
1222
    $dbi         = $dbi->password('lkj&le`@s');
1223

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

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

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

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

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

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

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

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

            
1246
    my $safety_column_name = $self->safety_column_name;
1247
    $dbi                   = $self->safety_column_name($name);
1248

            
1249
Safety column name regex.
1250
Default is qr/^[\w\.]*$/
1251

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1254
    my $user = $dbi->user;
1255
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1256

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1268
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1269
        $table,
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1270
        $column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1}
1271
        $column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2}
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1272
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1273
    );
1274

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

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

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

            
1288
You can use three name as column name.
1289

            
1290
    1. column        : author
1291
    2. table.column  : book.author
1292
    3. table__column : book__author
1293

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1329
    $dbi->delete(table  => $table,
1330
                 where  => \%where,
1331
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1332
                 filter => \%filter,
1333
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1334

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

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

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

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

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

            
1356
To delete row by using primary key, use C<delete_at()>
1357

            
1358
    $dbi->delete_at(
1359
        table => 'book',
1360
        primary_key => ['id'],
1361
        where => ['123']
1362
    );
1363

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

            
1367
You can also write arguments like this.
1368

            
1369
    $dbi->delete_at(
1370
        table => 'book',
1371
        primary_key => ['id'],
1372
        param => {id => '123'}
1373
    );
1374

            
cleanup
yuki-kimoto authored on 2010-10-17
1375
=head2 C<insert>
1376

            
1377
    $dbi->insert(table  => $table, 
1378
                 param  => \%param,
1379
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1380
                 filter => \%filter,
1381
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1382

            
1383
Execute insert statement.
1384
C<insert> method have C<table>, C<param>, C<append>
1385
and C<filter> arguments.
1386
C<table> is a table name.
1387
C<param> is the pairs of column name value. this must be hash reference.
1388
C<append> is a string added at the end of the SQL statement.
1389
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1390
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1391
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1392
This is overwrites C<default_bind_filter>.
1393
Return value of C<insert()> is the count of affected rows.
1394

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
1397
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1398
        sub {
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1399
            my ($self, $table, $column, $column_info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1400
            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1401
            my $type = $column_info->{TYPE_NAME};
pod fix
Yuki Kimoto authored on 2011-01-21
1402
            
1403
            if ($type eq 'DATE') {
1404
                # ...
1405
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1406
        }
1407
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1408
Get column informations from database.
1409
Argument is callback.
1410
You can do anything in callback.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1411
Callback receive four arguments, dbi object, table name,
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1412
column name and column information.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1413

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

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1416
    $dbi->include_model(
1417
        'MyModel' => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1418
            'book', 'person', 'company'
1419
        ]
1420
    );
1421

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

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

            
1428
    $dbi->include_model('MyModel');
1429

            
1430
Note that in this case name spece module is needed.
1431

            
1432
    # MyModel.pm
1433
    package MyModel;
1434
    
1435
    use base 'DBIx::Custom::Model';
1436

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

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1439
    MyModel::book
1440
    MyModel::person
1441
    MyModel::company
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1442

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

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

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

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1450
    $dbi->include_model(
1451
        'MyModel' => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1452
            {'book' => 'Book'},
1453
            {'person' => 'Person'}
1454
        ]
1455
    );
1456

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

            
1459
    $dbi->method(
1460
        update_or_insert => sub {
1461
            my $self = shift;
1462
            # do something
1463
        },
1464
        find_or_create   => sub {
1465
            my $self = shift;
1466
            # do something
1467
        }
1468
    );
1469

            
1470
Register method. These method is called from L<DBIx::Custom> object directory.
1471

            
1472
    $dbi->update_or_insert;
1473
    $dbi->find_or_create;
1474

            
1475
=head2 C<new>
1476

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

            
1480
Create a new L<DBIx::Custom> object.
1481

            
1482
=head2 C<(experimental) not_exists>
1483

            
1484
    my $not_exists = $dbi->not_exists;
1485

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1488
=head2 C<register_filter>
1489

            
1490
    $dbi->register_filter(%filters);
1491
    $dbi->register_filter(\%filters);
1492
    
1493
Register filter. Registered filters is available in the following attributes
1494
or arguments.
1495

            
1496
=over 4
1497

            
1498
=item *
1499

            
1500
C<filter> argument of C<insert()>, C<update()>,
1501
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1502
methods
1503

            
1504
=item *
1505

            
1506
C<execute()> method
1507

            
1508
=item *
1509

            
1510
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1511

            
1512
=item *
1513

            
1514
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1515

            
1516
=back
1517

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1520
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1521
        limit => sub {
1522
            ...;
1523
        }
1524
    );
1525

            
cleanup
Yuki Kimoto authored on 2011-01-25
1526
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1527

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

            
1530
    $dbi->rollback;
1531

            
1532
Rollback transaction.
1533
This is same as L<DBI>'s C<rollback>.
1534

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1535
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1536
    
cleanup
yuki-kimoto authored on 2010-08-05
1537
    my $result = $dbi->select(table    => $table,
1538
                              column   => [@column],
1539
                              where    => \%where,
1540
                              append   => $append,
1541
                              relation => \%relation,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1542
                              filter   => \%filter,
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1543
                              query    => 1,
1544
                              selection => $selection);
update document
yuki-kimoto authored on 2009-11-19
1545

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1546
Execute select statement.
cleanup
yuki-kimoto authored on 2010-08-09
1547
C<select> method have C<table>, C<column>, C<where>, C<append>,
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1548
C<relation> and C<filter> arguments.
1549
C<table> is a table name.
cleanup
yuki-kimoto authored on 2010-08-09
1550
C<where> is where clause. this is normally hash reference.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1551
C<append> is a string added at the end of the SQL statement.
1552
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1553
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1554
default to 0. This is experimental.
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1555
C<selection> is string of column name and tables. This is experimental
1556

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

            
cleanup
yuki-kimoto authored on 2010-08-09
1560
First element is a string. it contains tags,
1561
such as "{= title} or {like author}".
1562
Second element is paramters.
1563

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1575
    $dbi->update(table  => $table, 
1576
                 param  => \%params,
1577
                 where  => \%where,
1578
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1579
                 filter => \%filter,
1580
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1581

            
cleanup
yuki-kimoto authored on 2010-10-17
1582
Execute update statement.
1583
C<update> method have C<table>, C<param>, C<where>, C<append>
1584
and C<filter> arguments.
1585
C<table> is a table name.
1586
C<param> is column-value pairs. this must be hash reference.
1587
C<where> is where clause. this must be hash reference.
1588
C<append> is a string added at the end of the SQL statement.
1589
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1590
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1591
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1592
This is overwrites C<default_bind_filter>.
1593
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1594

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

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1597
    $dbi->model('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1598
        insert => sub { ... },
1599
        update => sub { ... }
1600
    );
1601
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1602
    my $model = $dbi->model('book');
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1603

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

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

            
1608
    $dbi->setup_model;
1609

            
1610
Setup all model objects.
1611
C<columns> and C<primary_key> is automatically set.
1612

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1615
    $dbi->update_all(table  => $table, 
1616
                     param  => \%params,
1617
                     filter => \%filter,
1618
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1619

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

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

            
1627
To update row by using primary key, use C<update_at()>
1628

            
1629
    $dbi->update_at(
1630
        table => 'book',
1631
        primary_key => ['id'],
1632
        where => ['123'],
1633
        param => {name => 'Ken'}
1634
    );
1635

            
1636
In this example, row which id column is 123 is updated.
1637
NOTE that you must pass array reference as C<where>.
1638
If C<param> contains primary key,
1639
the key and value is delete from C<param>.
1640

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

            
1643
    my $where = $dbi->where;
1644

            
1645
Create a new L<DBIx::Custom::Where> object.
1646

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

            
1649
    $dbi          = $dbi->cache_method(\&cache_method);
1650
    $cache_method = $dbi->cache_method
1651

            
1652
Method to set and get caches.
1653

            
cleanup
Yuki Kimoto authored on 2011-01-25
1654
=head1 Tags
1655

            
1656
The following tags is available.
1657

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

            
1660
Table tag
1661

            
1662
    {table TABLE}    ->    TABLE
1663

            
1664
This is used to teach what is applied table to C<execute()>.
1665

            
cleanup
Yuki Kimoto authored on 2011-01-25
1666
=head2 C<?>
1667

            
1668
Placeholder tag.
1669

            
1670
    {? NAME}    ->   ?
1671

            
1672
=head2 C<=>
1673

            
1674
Equal tag.
1675

            
1676
    {= NAME}    ->   NAME = ?
1677

            
1678
=head2 C<E<lt>E<gt>>
1679

            
1680
Not equal tag.
1681

            
1682
    {<> NAME}   ->   NAME <> ?
1683

            
1684
=head2 C<E<lt>>
1685

            
1686
Lower than tag
1687

            
1688
    {< NAME}    ->   NAME < ?
1689

            
1690
=head2 C<E<gt>>
1691

            
1692
Greater than tag
1693

            
1694
    {> NAME}    ->   NAME > ?
1695

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

            
1698
Greater than or equal tag
1699

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

            
1702
=head2 C<E<lt>=>
1703

            
1704
Lower than or equal tag
1705

            
1706
    {<= NAME}   ->   NAME <= ?
1707

            
1708
=head2 C<like>
1709

            
1710
Like tag
1711

            
1712
    {like NAME}   ->   NAME like ?
1713

            
1714
=head2 C<in>
1715

            
1716
In tag.
1717

            
1718
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1719

            
1720
=head2 C<insert_param>
1721

            
1722
Insert parameter tag.
1723

            
1724
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1725

            
1726
=head2 C<update_param>
1727

            
1728
Updata parameter tag.
1729

            
1730
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1731

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

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

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

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

            
1741
C<< <kimoto.yuki at gmail.com> >>
1742

            
1743
L<http://github.com/yuki-kimoto/DBIx-Custom>
1744

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1745
=head1 AUTHOR
1746

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

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

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

            
1753
This program is free software; you can redistribute it and/or modify it
1754
under the same terms as Perl itself.
1755

            
1756
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1757

            
1758