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

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
3
our $VERSION = '0.1638';
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;
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
17
use DBIx::Custom::Table;
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,
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
24
    dbi_option    => sub { {} },
cleanup
Yuki Kimoto authored on 2011-01-23
25
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
many changed
Yuki Kimoto authored on 2011-01-23
26
    result_class  => 'DBIx::Custom::Result',
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
27
    base_table    => sub { DBIx::Custom::Table->new(dbi => shift) }
many changed
Yuki Kimoto authored on 2011-01-23
28
);
29

            
30
__PACKAGE__->attr(
31
    cache_method => sub {
32
        sub {
33
            my $self = shift;
34
            
35
            $self->{_cached} ||= {};
36
            
37
            if (@_ > 1) {
38
                $self->{_cached}{$_[0]} = $_[1] 
39
            }
40
            else {
41
                return $self->{_cached}{$_[0]}
42
            }
43
        }
44
    }
45
);
46

            
47
__PACKAGE__->attr(
fix tests
Yuki Kimoto authored on 2011-01-13
48
    filters => sub {
49
        {
50
            encode_utf8 => sub { encode_utf8($_[0]) },
51
            decode_utf8 => sub { decode_utf8($_[0]) }
52
        }
many changed
Yuki Kimoto authored on 2011-01-23
53
    }
fix tests
Yuki Kimoto authored on 2011-01-13
54
);
cleanup
yuki-kimoto authored on 2010-10-17
55

            
56
# DBI methods
57
foreach my $method (qw/begin_work commit rollback/) {
58
    my $code = sub {
59
        my $self = shift;
60
        my $ret = eval {$self->dbh->$method};
61
        croak $@ if $@;
62
        return $ret;
63
    };
64
    no strict 'refs';
65
    my $pkg = __PACKAGE__;
66
    *{"${pkg}::$method"} = $code;
67
};
68

            
added helper method
yuki-kimoto authored on 2010-10-17
69
our $AUTOLOAD;
70

            
71
sub AUTOLOAD {
72
    my $self = shift;
73

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
77
    # Method
78
    $self->{_methods} ||= {};
79
    croak qq/Can't locate object method "$mname" via "$package"/
80
      unless my $method = $self->{_methods}->{$mname};
81
    
82
    return $self->$method(@_);
added helper method
yuki-kimoto authored on 2010-10-17
83
}
84

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

            
88
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
89
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
90
    $self->{filter}{out} ||= {};
91
    $self->{filter}{in} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
92
    
many changed
Yuki Kimoto authored on 2011-01-23
93
    # Create filters
94
    my $usage = "Usage: \$dbi->apply_filter(" .
95
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1}, " .
96
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2}, ...)";
97

            
98
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
99
        
many changed
Yuki Kimoto authored on 2011-01-23
100
        # Column
101
        my $column = $cinfos[$i];
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
102
        
many changed
Yuki Kimoto authored on 2011-01-23
103
        # Filter
104
        my $filter = $cinfos[$i + 1] || {};
105
        croak $usage unless  ref $filter eq 'HASH';
106
        foreach my $ftype (keys %$filter) {
107
            croak $usage unless $ftype eq 'in' || $ftype eq 'out'; 
108
        }
109
        my $in_filter = $filter->{in};
110
        my $out_filter = $filter->{out};
111
        
112
        # Out filter
113
        if (ref $out_filter eq 'CODE') {
114
            $self->{filter}{out}{$table}{$column}
115
              = $out_filter;
116
            $self->{filter}{out}{$table}{"$table.$column"}
117
              = $out_filter;
118
        }
119
        elsif (defined $out_filter) {
120
            croak qq{Filter "$out_filter" is not registered}
121
              unless exists $self->filters->{$out_filter};
cleanup
Yuki Kimoto authored on 2010-12-22
122
            
many changed
Yuki Kimoto authored on 2011-01-23
123
            $self->{filter}{out}{$table}{$column}
124
              = $self->filters->{$out_filter};
125
            $self->{filter}{out}{$table}{"$table.$column"}
126
              = $self->filters->{$out_filter};
cleanup
Yuki Kimoto authored on 2010-12-21
127
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
128
        
many changed
Yuki Kimoto authored on 2011-01-23
129
        # In filter
130
        if (ref $in_filter eq 'CODE') {
131
            $self->{filter}{in}{$table}{$column}
132
              = $in_filter;
133
            $self->{filter}{in}{$table}{"$table.$column"}
134
              = $in_filter;
135
        }
136
        elsif (defined $in_filter) {
137
            croak qq{Filter "$in_filter" is not registered}
138
              unless exists $self->filters->{$in_filter};
139
            $self->{filter}{in}{$table}{$column}
140
              = $self->filters->{$in_filter};
141
            $self->{filter}{in}{$table}{"$table.$column"}
142
              = $self->filters->{$in_filter};
143
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
144
    }
145
    
many changed
Yuki Kimoto authored on 2011-01-23
146
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
147
}
148

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
149
sub method {
added helper method
yuki-kimoto authored on 2010-10-17
150
    my $self = shift;
151
    
152
    # Merge
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
153
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
154
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
added helper method
yuki-kimoto authored on 2010-10-17
155
    
156
    return $self;
157
}
158

            
packaging one directory
yuki-kimoto authored on 2009-11-16
159
sub connect {
cleanup
Yuki Kimoto authored on 2011-01-25
160
    my $self = ref $_[0] ? shift : shift->new(@_);;
removed register_format()
yuki-kimoto authored on 2010-05-26
161
    
many changed
Yuki Kimoto authored on 2011-01-23
162
    # Attributes
packaging one directory
yuki-kimoto authored on 2009-11-16
163
    my $data_source = $self->data_source;
many changed
Yuki Kimoto authored on 2011-01-23
164
    croak qq{"data_source" must be specified to connect()"}
check arguments of connect m...
Yuki Kimoto authored on 2010-12-20
165
      unless $data_source;
packaging one directory
yuki-kimoto authored on 2009-11-16
166
    my $user        = $self->user;
167
    my $password    = $self->password;
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
168
    my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
added dbi_options attribute
kimoto authored on 2010-12-20
169
    
update document
yuki-kimoto authored on 2010-01-30
170
    # Connect
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
171
    my $dbh = eval {DBI->connect(
packaging one directory
yuki-kimoto authored on 2009-11-16
172
        $data_source,
173
        $user,
174
        $password,
175
        {
176
            RaiseError => 1,
177
            PrintError => 0,
178
            AutoCommit => 1,
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
179
            %$dbi_option
packaging one directory
yuki-kimoto authored on 2009-11-16
180
        }
181
    )};
182
    
update document
yuki-kimoto authored on 2010-01-30
183
    # Connect error
packaging one directory
yuki-kimoto authored on 2009-11-16
184
    croak $@ if $@;
185
    
update document
yuki-kimoto authored on 2010-01-30
186
    # Database handle
packaging one directory
yuki-kimoto authored on 2009-11-16
187
    $self->dbh($dbh);
update document
yuki-kimoto authored on 2010-01-30
188
    
packaging one directory
yuki-kimoto authored on 2009-11-16
189
    return $self;
190
}
191

            
cleanup
yuki-kimoto authored on 2010-10-17
192
sub create_query {
193
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
194
    
cleanup
yuki-kimoto authored on 2010-10-17
195
    # Cache
196
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
197
    
cleanup
yuki-kimoto authored on 2010-10-17
198
    # Create query
199
    my $query;
200
    if ($cache) {
201
        
202
        # Get query
203
        my $q = $self->cache_method->($self, $source);
204
        
205
        # Create query
206
        $query = DBIx::Custom::Query->new($q) if $q;
207
    }
208
    
209
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
210

            
cleanup
yuki-kimoto authored on 2010-10-17
211
        # Create SQL object
212
        my $builder = $self->query_builder;
213
        
214
        # Create query
215
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
216

            
cleanup
yuki-kimoto authored on 2010-10-17
217
        # Cache query
218
        $self->cache_method->($self, $source,
219
                             {sql     => $query->sql, 
220
                              columns => $query->columns})
221
          if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
222
    }
223
    
cleanup
yuki-kimoto authored on 2010-10-17
224
    # Prepare statement handle
225
    my $sth;
226
    eval { $sth = $self->dbh->prepare($query->{sql})};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
227
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
packaging one directory
yuki-kimoto authored on 2009-11-16
228
    
cleanup
yuki-kimoto authored on 2010-10-17
229
    # Set statement handle
230
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
231
    
cleanup
yuki-kimoto authored on 2010-10-17
232
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
233
}
234

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

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

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

            
add tests
yuki-kimoto authored on 2010-08-10
274
    # Source of SQL
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
275
    my $source = "delete from $table $w";
add tests
yuki-kimoto authored on 2010-08-10
276
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
277
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
278
    # Create query
279
    my $query = $self->create_query($source);
280
    return $query if $args{query};
281
    
packaging one directory
yuki-kimoto authored on 2009-11-16
282
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
283
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
284
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
285
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
286
    
287
    return $ret_val;
288
}
289

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

            
added helper method
yuki-kimoto authored on 2010-10-17
292
sub DESTROY { }
293

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

            
cleanup
yuki-kimoto authored on 2010-10-17
296
sub execute{
297
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
298
    
299
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
300
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
301
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
302
          unless $VALID_EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
303
    }
304
    
cleanup
yuki-kimoto authored on 2010-10-17
305
    my $params = $args{param} || {};
packaging one directory
yuki-kimoto authored on 2009-11-16
306
    
cleanup
yuki-kimoto authored on 2010-10-17
307
    # First argument is the soruce of SQL
308
    $query = $self->create_query($query)
309
      unless ref $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
310
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
311
    # Auto filter
cleanup
Yuki Kimoto authored on 2011-01-12
312
    my $filter = {};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
313
    my $tables = $args{table} || [];
314
    $tables = [$tables]
315
      unless ref $tables eq 'ARRAY';
316
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-01-12
317
        $filter = {
318
            %$filter,
319
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
320
        }
321
    }
322
    
cleanup
Yuki Kimoto authored on 2011-01-12
323
    # Filter argument
324
    my $f = $args{filter} || $query->filter || {};
325
    foreach my $column (keys %$f) {
326
        my $fname = $f->{$column};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
327
        if (!defined $fname) {
cleanup
Yuki Kimoto authored on 2011-01-12
328
            $f->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
329
        }
330
        elsif (ref $fname ne 'CODE') {
many changed
Yuki Kimoto authored on 2011-01-23
331
          croak qq{Filter "$fname" is not registered"}
cleanup
Yuki Kimoto authored on 2010-12-21
332
            unless exists $self->filters->{$fname};
333
          
cleanup
Yuki Kimoto authored on 2011-01-12
334
          $f->{$column} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2010-12-21
335
        }
336
    }
cleanup
Yuki Kimoto authored on 2011-01-12
337
    $filter = {%$filter, %$f};
packaging one directory
yuki-kimoto authored on 2009-11-16
338
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
339
    # Bind
340
    my $bind = $self->_bind($params, $query->columns, $filter);
cleanup
yuki-kimoto authored on 2010-10-17
341
    
342
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
343
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
344
    my $affected;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
345
    eval {$affected = $sth->execute(@$bind)};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
346
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
347
    
348
    # Return resultset if select statement is executed
349
    if ($sth->{NUM_OF_FIELDS}) {
350
        
cleanup
Yuki Kimoto authored on 2011-01-12
351
        # Auto in filter
cleanup
Yuki Kimoto authored on 2011-01-12
352
        my $in_filter = {};
353
        foreach my $table (@$tables) {
354
            $in_filter = {
355
                %$in_filter,
356
                %{$self->{filter}{in}{$table} || {}}
357
            }
358
        }
359
        
360
        # Result
361
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
362
            sth            => $sth,
363
            filters        => $self->filters,
364
            filter_check   => $self->filter_check,
cleanup
Yuki Kimoto authored on 2011-01-12
365
            default_filter => $self->{default_in_filter},
cleanup
Yuki Kimoto authored on 2011-01-12
366
            filter         => $in_filter || {}
cleanup
yuki-kimoto authored on 2010-10-17
367
        );
368

            
369
        return $result;
370
    }
371
    return $affected;
372
}
373

            
added experimental expand me...
yuki-kimoto authored on 2010-10-20
374
sub expand {
375
    my $self = shift;
376
    my $source = ref $_[0] eq 'HASH' ? $_[0] : {@_};
377
    my $table = (keys %$source)[0];
378
    my $param = $source->{$table};
379
    
380
    # Expand table name
381
    my $expand = {};
382
    foreach my $column (keys %$param) {
383
        $expand->{"$table.$column"} = $param->{$column};
384
    }
385
    
386
    return %$expand;
387
}
388

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

            
394
    # Check arguments
395
    foreach my $name (keys %args) {
396
        croak qq{"$name" is invalid argument}
397
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
398
    }
399
    
cleanup
yuki-kimoto authored on 2010-10-17
400
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
401
    my $table  = $args{table};
402
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
403
    my $param  = $args{param} || {};
404
    my $append = $args{append} || '';
405
    my $filter = $args{filter};
406
    
407
    # Insert keys
408
    my @insert_keys = keys %$param;
409
    
410
    # Templte for insert
411
    my $source = "insert into $table {insert_param "
412
               . join(' ', @insert_keys) . '}';
add tests
yuki-kimoto authored on 2010-08-10
413
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
414
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
415
    # Create query
416
    my $query = $self->create_query($source);
417
    return $query if $args{query};
418
    
packaging one directory
yuki-kimoto authored on 2009-11-16
419
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
420
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
421
        $query,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
422
        param  => $param,
423
        filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
424
        table => $table
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
425
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
426
    
427
    return $ret_val;
428
}
429

            
pod fix
Yuki Kimoto authored on 2011-01-21
430
sub each_column {
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
431
    my ($self, $cb) = @_;
432
    
433
    # Iterate all tables
434
    my $sth_tables = $self->dbh->table_info;
435
    while (my $table_info = $sth_tables->fetchrow_hashref) {
436
        
437
        # Table
438
        my $table = $table_info->{TABLE_NAME};
439
        
440
        # Iterate all columns
441
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
442
        while (my $column_info = $sth_columns->fetchrow_hashref) {
443
            my $column = $column_info->{COLUMN_NAME};
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
444
            $self->$cb($table, $column, $column_info);
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
445
        }
446
    }
447
}
448

            
added dbi_options attribute
kimoto authored on 2010-12-20
449
sub new {
450
    my $self = shift->SUPER::new(@_);
451
    
452
    # Check attribute names
453
    my @attrs = keys %$self;
454
    foreach my $attr (@attrs) {
455
        croak qq{"$attr" is invalid attribute name}
456
          unless $self->can($attr);
457
    }
cleanup
Yuki Kimoto authored on 2011-01-25
458

            
459
    $self->register_tag(
460
        '?'     => \&DBIx::Custom::Tag::placeholder,
461
        '='     => \&DBIx::Custom::Tag::equal,
462
        '<>'    => \&DBIx::Custom::Tag::not_equal,
463
        '>'     => \&DBIx::Custom::Tag::greater_than,
464
        '<'     => \&DBIx::Custom::Tag::lower_than,
465
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
466
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
467
        'like'  => \&DBIx::Custom::Tag::like,
468
        'in'    => \&DBIx::Custom::Tag::in,
469
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
470
        'update_param' => \&DBIx::Custom::Tag::update_param
471
    );
added dbi_options attribute
kimoto authored on 2010-12-20
472
    
473
    return $self;
474
}
475

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

            
cleanup
yuki-kimoto authored on 2010-10-17
478
sub register_filter {
479
    my $invocant = shift;
480
    
481
    # Register filter
482
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
483
    $invocant->filters({%{$invocant->filters}, %$filters});
484
    
485
    return $invocant;
486
}
packaging one directory
yuki-kimoto authored on 2009-11-16
487

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
490
our %VALID_SELECT_ARGS
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
491
  = map { $_ => 1 } qw/table column where append relation filter query/;
refactoring select
yuki-kimoto authored on 2010-04-28
492

            
packaging one directory
yuki-kimoto authored on 2009-11-16
493
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
494
    my ($self, %args) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
495
    
refactoring select
yuki-kimoto authored on 2010-04-28
496
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
497
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
498
        croak qq{"$name" is invalid argument}
refactoring select
yuki-kimoto authored on 2010-04-28
499
          unless $VALID_SELECT_ARGS{$name};
500
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
501
    
refactoring select
yuki-kimoto authored on 2010-04-28
502
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
503
    my $table = $args{table};
504
    my $tables = ref $table eq 'ARRAY' ? $table
505
               : defined $table ? [$table]
506
               : [];
507
    croak qq{"table" option must be specified} unless @$tables;
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
508
    my $columns  = $args{column} || [];
update document
yuki-kimoto authored on 2010-08-07
509
    my $where    = $args{where};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
510
    my $relation = $args{relation};
511
    my $append   = $args{append};
512
    my $filter   = $args{filter};
packaging one directory
yuki-kimoto authored on 2009-11-16
513
    
add tests
yuki-kimoto authored on 2010-08-10
514
    # Source of SQL
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
515
    my $source = 'select ';
packaging one directory
yuki-kimoto authored on 2009-11-16
516
    
added commit method
yuki-kimoto authored on 2010-05-27
517
    # Column clause
packaging one directory
yuki-kimoto authored on 2009-11-16
518
    if (@$columns) {
519
        foreach my $column (@$columns) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
520
            $source .= "$column, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
521
        }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
522
        $source =~ s/, $/ /;
packaging one directory
yuki-kimoto authored on 2009-11-16
523
    }
524
    else {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
525
        $source .= '* ';
packaging one directory
yuki-kimoto authored on 2009-11-16
526
    }
527
    
added commit method
yuki-kimoto authored on 2010-05-27
528
    # Table
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
529
    $source .= 'from ';
packaging one directory
yuki-kimoto authored on 2009-11-16
530
    foreach my $table (@$tables) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
531
        $source .= "$table, ";
packaging one directory
yuki-kimoto authored on 2009-11-16
532
    }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
533
    $source =~ s/, $/ /;
packaging one directory
yuki-kimoto authored on 2009-11-16
534
    
added commit method
yuki-kimoto authored on 2010-05-27
535
    # Where clause
update document
yuki-kimoto authored on 2010-08-07
536
    my $param;
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
537
    my $wexists;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
538
    if (ref $where eq 'HASH') {
update document
yuki-kimoto authored on 2010-08-07
539
        $param = $where;
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
540
        $wexists = keys %$where;
541
        
542
        if ($wexists) {
543
            $source .= 'where (';
544
            foreach my $where_key (keys %$where) {
545
                $source .= "{= $where_key} and ";
546
            }
547
            $source =~ s/ and $//;
548
            $source .= ') ';
packaging one directory
yuki-kimoto authored on 2009-11-16
549
        }
update document
yuki-kimoto authored on 2010-08-07
550
    }
551
    elsif (ref $where eq 'ARRAY') {
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
552
        my $w = $where->[0] || '';
update document
yuki-kimoto authored on 2010-08-07
553
        $param = $where->[1];
554
        
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
555
        $wexists = $w =~ /\S/;
556
        $source .= "where ($w) " if $wexists;
557
    }
558
    elsif (ref $where eq 'DBIx::Custom::Where') {
559
        $param = $where->param;
560
        my $w = $where->to_string;
561
        $wexists = $w =~ /\S/;
562
        $source .= $w;
packaging one directory
yuki-kimoto authored on 2009-11-16
563
    }
564
    
added commit method
yuki-kimoto authored on 2010-05-27
565
    # Relation
566
    if ($relation) {
fix select method empty wher...
Yuki Kimoto authored on 2011-01-17
567
        $source .= $wexists ? "and " : "where ";
added commit method
yuki-kimoto authored on 2010-05-27
568
        foreach my $rkey (keys %$relation) {
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
569
            $source .= "$rkey = " . $relation->{$rkey} . " and ";
packaging one directory
yuki-kimoto authored on 2009-11-16
570
        }
571
    }
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
572
    $source =~ s/ and $//;
added commit method
yuki-kimoto authored on 2010-05-27
573
    
574
    # Append some statement
renamed default_query_filter...
yuki-kimoto authored on 2010-08-03
575
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
576
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
577
    # Create query
578
    my $query = $self->create_query($source);
579
    return $query if $args{query};
580
    
packaging one directory
yuki-kimoto authored on 2009-11-16
581
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
582
    my $result = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
583
        $query, param  => $param, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
584
        table => $tables);    
packaging one directory
yuki-kimoto authored on 2009-11-16
585
    
586
    return $result;
587
}
588

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
589
sub table {
590
    my $self = shift;
591
    my $name = shift;
592
    
593
    # Create table
594
    $self->{_tables} ||= {};
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
595
    unless (defined $self->{_tables}->{$name}) {
596
        # Base table
597
        my $base_table = $self->base_table;
598
        
599
        # Base methods
600
        my $bmethods = ref $base_table->{_methods} eq 'HASH'
601
                     ? $base_table->{_methods}
602
                     : {};
603
        
604
        # Copy Methods
605
        my $methods = {};
606
        $methods->{$_} = $bmethods->{$_} for keys %$bmethods;
607
        
608
        # Create table
609
        my $table = $base_table->new(
610
            dbi      => $self,
611
            name     => $name,
612
            base     => $base_table,
613
            _methods => $methods
614
        );
615
        $self->{_tables}->{$name} = $table;
616
    }
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
617
    
618
    return $self->{_tables}{$name};
619
}
620

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

            
625
sub update {
626
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
627
    
cleanup
yuki-kimoto authored on 2010-10-17
628
    # Check arguments
629
    foreach my $name (keys %args) {
630
        croak qq{"$name" is invalid argument}
631
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
632
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
633
    
cleanup
yuki-kimoto authored on 2010-10-17
634
    # Arguments
635
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
636
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
637
    my $param            = $args{param} || {};
638
    my $where            = $args{where} || {};
639
    my $append = $args{append} || '';
640
    my $filter           = $args{filter};
641
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
642
    
cleanup
yuki-kimoto authored on 2010-10-17
643
    # Update keys
644
    my @update_keys = keys %$param;
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
645
    
cleanup
yuki-kimoto authored on 2010-10-17
646
    # Update clause
647
    my $update_clause = '{update_param ' . join(' ', @update_keys) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
648

            
649
    # Where
650
    my $w;
651
    if (ref $where eq 'HASH') {
652
        my $clause = ['and'];
653
        push @$clause, "{= $_}" for keys %$where;
654
        $w = $self->where;
655
        $w->clause($clause);
656
        $w->param($where);
657
    }
658
    else { $w = $where }
removed experimental registe...
yuki-kimoto authored on 2010-08-24
659
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
660
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
661
      unless ref $w eq 'DBIx::Custom::Where';
removed reconnect method
yuki-kimoto authored on 2010-05-28
662
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
663
    $where = $w->param;
664
    
665
    croak qq{"where" must be specified}
666
      if "$w" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
667
    
cleanup
yuki-kimoto authored on 2010-10-17
668
    # Source of SQL
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
669
    my $source = "update $table $update_clause $w";
cleanup
yuki-kimoto authored on 2010-10-17
670
    $source .= " $append" if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
671
    
cleanup
yuki-kimoto authored on 2010-10-17
672
    # Rearrange parameters
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
673
    foreach my $wkey (keys %$where) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
674
        
cleanup
yuki-kimoto authored on 2010-10-17
675
        if (exists $param->{$wkey}) {
676
            $param->{$wkey} = [$param->{$wkey}]
677
              unless ref $param->{$wkey} eq 'ARRAY';
678
            
679
            push @{$param->{$wkey}}, $where->{$wkey};
680
        }
681
        else {
682
            $param->{$wkey} = $where->{$wkey};
683
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
684
    }
cleanup
yuki-kimoto authored on 2010-10-17
685
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
686
    # Create query
687
    my $query = $self->create_query($source);
688
    return $query if $args{query};
689
    
cleanup
yuki-kimoto authored on 2010-10-17
690
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
691
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
692
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
693
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
694
    
695
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
696
}
697

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
700
sub where {
701
    return DBIx::Custom::Where->new(query_builder => shift->query_builder)
702
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
703

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
704
sub _bind {
cleanup
Yuki Kimoto authored on 2011-01-12
705
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
706
    
cleanup
Yuki Kimoto authored on 2011-01-12
707
    # bind values
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
708
    my @bind;
add tests
yuki-kimoto authored on 2010-08-08
709
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
710
    # Build bind values
711
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
712
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
713
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
714
        
715
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
716
        my $value;
717
        if(ref $params->{$column} eq 'ARRAY') {
718
            my $i = $count->{$column} || 0;
719
            $i += $not_exists->{$column} || 0;
720
            my $found;
721
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
722
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
723
                    $not_exists->{$column}++;
724
                }
725
                else  {
726
                    $value = $params->{$column}->[$k];
727
                    $found = 1;
728
                    last
729
                }
730
            }
731
            next unless $found;
732
        }
733
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
734
        
cleanup
Yuki Kimoto authored on 2011-01-12
735
        # Filter
736
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
737
        
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
738
        push @bind, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
739
        
740
        # Count up 
741
        $count->{$column}++;
742
    }
743
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
744
    return \@bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
745
}
746

            
cleanup
yuki-kimoto authored on 2010-10-17
747
sub _croak {
748
    my ($self, $error, $append) = @_;
749
    $append ||= "";
750
    
751
    # Verbose
752
    if ($Carp::Verbose) { croak $error }
753
    
754
    # Not verbose
755
    else {
756
        
757
        # Remove line and module infromation
758
        my $at_pos = rindex($error, ' at ');
759
        $error = substr($error, 0, $at_pos);
760
        $error =~ s/\s+$//;
761
        
762
        croak "$error$append";
763
    }
764
}
765

            
cleanup
Yuki Kimoto authored on 2011-01-25
766
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
767
__PACKAGE__->attr(
768
    dbi_options => sub { {} },
769
    filter_check  => 1
770
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
771

            
cleanup
Yuki Kimoto authored on 2011-01-25
772
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
773
sub default_bind_filter {
774
    my $self = shift;
775
    
776
    if (@_) {
777
        my $fname = $_[0];
778
        
779
        if (@_ && !$fname) {
780
            $self->{default_out_filter} = undef;
781
        }
782
        else {
many changed
Yuki Kimoto authored on 2011-01-23
783
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
784
              unless exists $self->filters->{$fname};
785
        
786
            $self->{default_out_filter} = $self->filters->{$fname};
787
        }
788
        return $self;
789
    }
790
    
791
    return $self->{default_out_filter};
792
}
793

            
cleanup
Yuki Kimoto authored on 2011-01-25
794
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
795
sub default_fetch_filter {
796
    my $self = shift;
797
    
798
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
799
        my $fname = $_[0];
800

            
cleanup
Yuki Kimoto authored on 2011-01-12
801
        if (@_ && !$fname) {
802
            $self->{default_in_filter} = undef;
803
        }
804
        else {
many changed
Yuki Kimoto authored on 2011-01-23
805
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
806
              unless exists $self->filters->{$fname};
807
        
808
            $self->{default_in_filter} = $self->filters->{$fname};
809
        }
810
        
811
        return $self;
812
    }
813
    
many changed
Yuki Kimoto authored on 2011-01-23
814
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
815
}
816

            
cleanup
Yuki Kimoto authored on 2011-01-25
817
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
818
sub register_tag_processor {
819
    return shift->query_builder->register_tag_processor(@_);
820
}
821

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
824
=head1 NAME
825

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

            
828
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
829

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
835
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
836
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
837
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
838
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
839
    
840
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
841
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
842
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
843
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
844
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
845
    
846
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
847
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
848
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
849
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
850
    
851
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
852
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
853
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
854
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
855
    
856
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
857
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
858

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
859
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
860
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
861
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
862
        column => [qw/author title/],
863
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
864
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
865
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
866
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
867
    );
cleanup
yuki-kimoto authored on 2010-08-05
868

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

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

            
883
    # Get DBI object
884
    my $dbh = $dbi->dbh;
885

            
removed register_format()
yuki-kimoto authored on 2010-05-26
886
    # Fetch
887
    while (my $row = $result->fetch) {
888
        # ...
889
    }
890
    
891
    # Fetch hash
892
    while (my $row = $result->fetch_hash) {
893
        
894
    }
895
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
896
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
897

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

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

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

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

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

            
920
=head1 GUIDE
921

            
922
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
923

            
924
=head1 EXAMPLES
925

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

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

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

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

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

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

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

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

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

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

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

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

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

            
958
DBI options.
959
C<connect()> method use this value to connect the database.
960

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
968
=head2 C<password>
969

            
970
    my $password = $dbi->password;
971
    $dbi         = $dbi->password('lkj&le`@s');
972

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
995
    my $user = $dbi->user;
996
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
997

            
cleanup
yuki-kimoto authored on 2010-10-17
998
User name.
999
C<connect()> method use this value to connect the database.
1000
    
1001
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
1002

            
cleanup
yuki-kimoto authored on 2010-10-17
1003
L<DBIx::Custom> inherits all methods from L<Object::Simple>
1004
and implements the following new ones.
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1005

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1008
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1009
        $table,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1010
        $column1 => {in => $infilter1, out => $outfilter1}
1011
        $column2 => {in => $infilter2, out => $outfilter2}
1012
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1013
    );
1014

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
1022
    $result = $dbi->execute(
1023
        "select * from table1 where {= key1} and {= key2};",
1024
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1025
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
1026
    );
1027
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1028
=head2 C<begin_work>
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1029

            
cleanup
yuki-kimoto authored on 2010-10-17
1030
    $dbi->begin_work;
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1031

            
cleanup
yuki-kimoto authored on 2010-10-17
1032
Start transaction.
1033
This is same as L<DBI>'s C<begin_work>.
added commit method
yuki-kimoto authored on 2010-05-27
1034

            
cleanup
yuki-kimoto authored on 2010-08-05
1035
L<DBIx::Custom> inherits all methods from L<Object::Simple>
1036
and implements the following new ones.
added commit method
yuki-kimoto authored on 2010-05-27
1037

            
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1038
=head2 C<commit>
cleanup
yuki-kimoto authored on 2010-10-17
1039

            
1040
    $dbi->commit;
1041

            
1042
Commit transaction.
1043
This is same as L<DBI>'s C<commit>.
1044

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

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

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

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

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

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

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

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

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

            
added experimental expand me...
yuki-kimoto authored on 2010-10-20
1078
=head2 C<(experimental) expand>
1079

            
1080
    my %expand = $dbi->expand($source);
1081

            
1082
The following hash
1083

            
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1084
    {book => {title => 'Perl', author => 'Ken'}}
added experimental expand me...
yuki-kimoto authored on 2010-10-20
1085

            
1086
is expanded to
1087

            
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1088
    ('book.title' => 'Perl', 'book.author' => 'Ken')
added experimental expand me...
yuki-kimoto authored on 2010-10-20
1089

            
1090
This is used in C<select()>
1091

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1094
    $dbi->delete(table  => $table,
1095
                 where  => \%where,
1096
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1097
                 filter => \%filter,
1098
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1099

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1119
=head2 C<insert>
1120

            
1121
    $dbi->insert(table  => $table, 
1122
                 param  => \%param,
1123
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1124
                 filter => \%filter,
1125
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1126

            
1127
Execute insert statement.
1128
C<insert> method have C<table>, C<param>, C<append>
1129
and C<filter> arguments.
1130
C<table> is a table name.
1131
C<param> is the pairs of column name value. this must be hash reference.
1132
C<append> is a string added at the end of the SQL statement.
1133
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1134
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1135
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1136
This is overwrites C<default_bind_filter>.
1137
Return value of C<insert()> is the count of affected rows.
1138

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
1141
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1142
        sub {
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1143
            my ($self, $table, $column, $info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1144
            
pod fix
Yuki Kimoto authored on 2011-01-21
1145
            my $type = $info->{TYPE_NAME};
1146
            
1147
            if ($type eq 'DATE') {
1148
                # ...
1149
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1150
        }
1151
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1152
Get column informations from database.
1153
Argument is callback.
1154
You can do anything in callback.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1155
Callback receive four arguments, dbi object, table name,
1156
column name and columninformation.
1157

            
1158
=head2 C<(experimental) method>
1159

            
1160
    $dbi->method(
1161
        update_or_insert => sub {
1162
            my $self = shift;
1163
            # do something
1164
        },
1165
        find_or_create   => sub {
1166
            my $self = shift;
1167
            # do something
1168
        }
1169
    );
1170

            
1171
Register method. These method is called from L<DBIx::Custom> object directory.
1172

            
1173
    $dbi->update_or_insert;
1174
    $dbi->find_or_create;
1175

            
1176
=head2 C<new>
1177

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

            
1181
Create a new L<DBIx::Custom> object.
1182

            
1183
=head2 C<(experimental) not_exists>
1184

            
1185
    my $not_exists = $dbi->not_exists;
1186

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1189
=head2 C<register_filter>
1190

            
1191
    $dbi->register_filter(%filters);
1192
    $dbi->register_filter(\%filters);
1193
    
1194
Register filter. Registered filters is available in the following attributes
1195
or arguments.
1196

            
1197
=over 4
1198

            
1199
=item *
1200

            
1201
C<filter> argument of C<insert()>, C<update()>,
1202
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1203
methods
1204

            
1205
=item *
1206

            
1207
C<execute()> method
1208

            
1209
=item *
1210

            
1211
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1212

            
1213
=item *
1214

            
1215
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1216

            
1217
=back
1218

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1221
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1222
        limit => sub {
1223
            ...;
1224
        }
1225
    );
1226

            
cleanup
Yuki Kimoto authored on 2011-01-25
1227
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1228

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

            
1231
    $dbi->rollback;
1232

            
1233
Rollback transaction.
1234
This is same as L<DBI>'s C<rollback>.
1235

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1236
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1237
    
cleanup
yuki-kimoto authored on 2010-08-05
1238
    my $result = $dbi->select(table    => $table,
1239
                              column   => [@column],
1240
                              where    => \%where,
1241
                              append   => $append,
1242
                              relation => \%relation,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1243
                              filter   => \%filter,
1244
                              query    => 1);
update document
yuki-kimoto authored on 2009-11-19
1245

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1246
Execute select statement.
cleanup
yuki-kimoto authored on 2010-08-09
1247
C<select> method have C<table>, C<column>, C<where>, C<append>,
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1248
C<relation> and C<filter> arguments.
1249
C<table> is a table name.
cleanup
yuki-kimoto authored on 2010-08-09
1250
C<where> is where clause. this is normally hash reference.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1251
C<append> is a string added at the end of the SQL statement.
1252
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1253
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1254
default to 0. This is experimental.
update document
yuki-kimoto authored on 2009-11-19
1255

            
cleanup
yuki-kimoto authored on 2010-08-09
1256
If you use more complex condition,
1257
you can specify a array reference to C<where> argument.
1258

            
1259
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1260
        table  => 'book',
cleanup
yuki-kimoto authored on 2010-08-09
1261
        column => ['title', 'author'],
1262
        where  => ['{= title} or {like author}',
1263
                   {title => '%Perl%', author => 'Ken'}]
1264
    );
1265

            
1266
First element is a string. it contains tags,
1267
such as "{= title} or {like author}".
1268
Second element is paramters.
1269

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1272
    $dbi->update(table  => $table, 
1273
                 param  => \%params,
1274
                 where  => \%where,
1275
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1276
                 filter => \%filter,
1277
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1278

            
cleanup
yuki-kimoto authored on 2010-10-17
1279
Execute update statement.
1280
C<update> method have C<table>, C<param>, C<where>, C<append>
1281
and C<filter> arguments.
1282
C<table> is a table name.
1283
C<param> is column-value pairs. this must be hash reference.
1284
C<where> is where clause. this must be hash reference.
1285
C<append> is a string added at the end of the SQL statement.
1286
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1287
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1288
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1289
This is overwrites C<default_bind_filter>.
1290
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1291

            
cleanup
Yuki Kimoto authored on 2011-01-12
1292
=head2 C<(experimental) table>
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1293

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
1294
    $dbi->table('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1295
        insert => sub { ... },
1296
        update => sub { ... }
1297
    );
1298
    
1299
    my $table = $dbi->table('book');
1300

            
1301
Create a L<DBIx::Custom::Table> object,
1302
or get a L<DBIx::Custom::Table> object.
1303

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1306
    $dbi->update_all(table  => $table, 
1307
                     param  => \%params,
1308
                     filter => \%filter,
1309
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1310

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

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

            
1318
    my $where = $dbi->where;
1319

            
1320
Create a new L<DBIx::Custom::Where> object.
1321

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

            
1324
    $dbi          = $dbi->cache_method(\&cache_method);
1325
    $cache_method = $dbi->cache_method
1326

            
1327
Method to set and get caches.
1328

            
cleanup
Yuki Kimoto authored on 2011-01-25
1329
=head1 Tags
1330

            
1331
The following tags is available.
1332

            
1333
=head2 C<?>
1334

            
1335
Placeholder tag.
1336

            
1337
    {? NAME}    ->   ?
1338

            
1339
=head2 C<=>
1340

            
1341
Equal tag.
1342

            
1343
    {= NAME}    ->   NAME = ?
1344

            
1345
=head2 C<E<lt>E<gt>>
1346

            
1347
Not equal tag.
1348

            
1349
    {<> NAME}   ->   NAME <> ?
1350

            
1351
=head2 C<E<lt>>
1352

            
1353
Lower than tag
1354

            
1355
    {< NAME}    ->   NAME < ?
1356

            
1357
=head2 C<E<gt>>
1358

            
1359
Greater than tag
1360

            
1361
    {> NAME}    ->   NAME > ?
1362

            
1363
=head2 C<E<gt>=>
1364

            
1365
Greater than or equal tag
1366

            
1367
    {>= NAME}   ->   NAME >= ?
1368

            
1369
=head2 C<E<lt>=>
1370

            
1371
Lower than or equal tag
1372

            
1373
    {<= NAME}   ->   NAME <= ?
1374

            
1375
=head2 C<like>
1376

            
1377
Like tag
1378

            
1379
    {like NAME}   ->   NAME like ?
1380

            
1381
=head2 C<in>
1382

            
1383
In tag.
1384

            
1385
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1386

            
1387
=head2 C<insert_param>
1388

            
1389
Insert parameter tag.
1390

            
1391
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1392

            
1393
=head2 C<update_param>
1394

            
1395
Updata parameter tag.
1396

            
1397
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1398

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

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

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

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

            
1408
C<< <kimoto.yuki at gmail.com> >>
1409

            
1410
L<http://github.com/yuki-kimoto/DBIx-Custom>
1411

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1412
=head1 AUTHOR
1413

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

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

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

            
1420
This program is free software; you can redistribute it and/or modify it
1421
under the same terms as Perl itself.
1422

            
1423
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1424

            
1425