DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
1421 lines | 36.296kb
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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
255
    # Where keys
removed register_format()
yuki-kimoto authored on 2010-05-26
256
    my @where_keys = keys %$where;
packaging one directory
yuki-kimoto authored on 2009-11-16
257
    
258
    # Not exists where keys
add tests
yuki-kimoto authored on 2010-08-10
259
    croak qq{"where" argument must be specified and } .
260
          qq{contains the pairs of column name and value}
cleanup
yuki-kimoto authored on 2010-10-17
261
      if !@where_keys && !$allow_delete_all;
packaging one directory
yuki-kimoto authored on 2009-11-16
262
    
263
    # Where clause
264
    my $where_clause = '';
265
    if (@where_keys) {
266
        $where_clause = 'where ';
add tests
yuki-kimoto authored on 2010-08-10
267
        $where_clause .= "{= $_} and " for @where_keys;
packaging one directory
yuki-kimoto authored on 2009-11-16
268
        $where_clause =~ s/ and $//;
269
    }
270
    
add tests
yuki-kimoto authored on 2010-08-10
271
    # Source of SQL
cleanup
yuki-kimoto authored on 2010-10-17
272
    my $source = "delete from $table $where_clause";
add tests
yuki-kimoto authored on 2010-08-10
273
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
274
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
275
    # Create query
276
    my $query = $self->create_query($source);
277
    return $query if $args{query};
278
    
packaging one directory
yuki-kimoto authored on 2009-11-16
279
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
280
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
281
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
282
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
283
    
284
    return $ret_val;
285
}
286

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

            
added helper method
yuki-kimoto authored on 2010-10-17
289
sub DESTROY { }
290

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

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

            
366
        return $result;
367
    }
368
    return $affected;
369
}
370

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

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

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

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

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

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

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

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

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

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

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

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

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

            
622
sub update {
623
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
624
    
cleanup
yuki-kimoto authored on 2010-10-17
625
    # Check arguments
626
    foreach my $name (keys %args) {
627
        croak qq{"$name" is invalid argument}
628
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
629
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
630
    
cleanup
yuki-kimoto authored on 2010-10-17
631
    # Arguments
632
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
633
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
634
    my $param            = $args{param} || {};
635
    my $where            = $args{where} || {};
636
    my $append = $args{append} || '';
637
    my $filter           = $args{filter};
638
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
639
    
cleanup
yuki-kimoto authored on 2010-10-17
640
    # Update keys
641
    my @update_keys = keys %$param;
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
642
    
cleanup
yuki-kimoto authored on 2010-10-17
643
    # Where keys
644
    my @where_keys = keys %$where;
removed reconnect method
yuki-kimoto authored on 2010-05-28
645
    
cleanup
yuki-kimoto authored on 2010-10-17
646
    # Not exists where keys
647
    croak qq{"where" argument must be specified and } .
648
          qq{contains the pairs of column name and value}
649
      if !@where_keys && !$allow_update_all;
removed experimental registe...
yuki-kimoto authored on 2010-08-24
650
    
cleanup
yuki-kimoto authored on 2010-10-17
651
    # Update clause
652
    my $update_clause = '{update_param ' . join(' ', @update_keys) . '}';
removed experimental registe...
yuki-kimoto authored on 2010-08-24
653
    
cleanup
yuki-kimoto authored on 2010-10-17
654
    # Where clause
655
    my $where_clause = '';
656
    my $new_where = {};
removed reconnect method
yuki-kimoto authored on 2010-05-28
657
    
cleanup
yuki-kimoto authored on 2010-10-17
658
    if (@where_keys) {
659
        $where_clause = 'where ';
660
        $where_clause .= "{= $_} and " for @where_keys;
661
        $where_clause =~ s/ and $//;
removed reconnect method
yuki-kimoto authored on 2010-05-28
662
    }
663
    
cleanup
yuki-kimoto authored on 2010-10-17
664
    # Source of SQL
665
    my $source = "update $table $update_clause $where_clause";
666
    $source .= " $append" if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
667
    
cleanup
yuki-kimoto authored on 2010-10-17
668
    # Rearrange parameters
669
    foreach my $wkey (@where_keys) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
670
        
cleanup
yuki-kimoto authored on 2010-10-17
671
        if (exists $param->{$wkey}) {
672
            $param->{$wkey} = [$param->{$wkey}]
673
              unless ref $param->{$wkey} eq 'ARRAY';
674
            
675
            push @{$param->{$wkey}}, $where->{$wkey};
676
        }
677
        else {
678
            $param->{$wkey} = $where->{$wkey};
679
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
680
    }
cleanup
yuki-kimoto authored on 2010-10-17
681
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
682
    # Create query
683
    my $query = $self->create_query($source);
684
    return $query if $args{query};
685
    
cleanup
yuki-kimoto authored on 2010-10-17
686
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
687
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
688
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
689
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
690
    
691
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
692
}
693

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
696
sub where {
697
    return DBIx::Custom::Where->new(query_builder => shift->query_builder)
698
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
699

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
820
=head1 NAME
821

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

            
824
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
825

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

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

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

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

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

            
879
    # Get DBI object
880
    my $dbh = $dbi->dbh;
881

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

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

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

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

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

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

            
916
=head1 GUIDE
917

            
918
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
919

            
920
=head1 EXAMPLES
921

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

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

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

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

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

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

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

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

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

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

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

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

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

            
954
DBI options.
955
C<connect()> method use this value to connect the database.
956

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
964
=head2 C<password>
965

            
966
    my $password = $dbi->password;
967
    $dbi         = $dbi->password('lkj&le`@s');
968

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
991
    my $user = $dbi->user;
992
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
993

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

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

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

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

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

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

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

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

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

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

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

            
1036
    $dbi->commit;
1037

            
1038
Commit transaction.
1039
This is same as L<DBI>'s C<commit>.
1040

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

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

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

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

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

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

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

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

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

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

            
1076
    my %expand = $dbi->expand($source);
1077

            
1078
The following hash
1079

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

            
1082
is expanded to
1083

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

            
1086
This is used in C<select()>
1087

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1115
=head2 C<insert>
1116

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

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

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

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

            
1154
=head2 C<(experimental) method>
1155

            
1156
    $dbi->method(
1157
        update_or_insert => sub {
1158
            my $self = shift;
1159
            # do something
1160
        },
1161
        find_or_create   => sub {
1162
            my $self = shift;
1163
            # do something
1164
        }
1165
    );
1166

            
1167
Register method. These method is called from L<DBIx::Custom> object directory.
1168

            
1169
    $dbi->update_or_insert;
1170
    $dbi->find_or_create;
1171

            
1172
=head2 C<new>
1173

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

            
1177
Create a new L<DBIx::Custom> object.
1178

            
1179
=head2 C<(experimental) not_exists>
1180

            
1181
    my $not_exists = $dbi->not_exists;
1182

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1185
=head2 C<register_filter>
1186

            
1187
    $dbi->register_filter(%filters);
1188
    $dbi->register_filter(\%filters);
1189
    
1190
Register filter. Registered filters is available in the following attributes
1191
or arguments.
1192

            
1193
=over 4
1194

            
1195
=item *
1196

            
1197
C<filter> argument of C<insert()>, C<update()>,
1198
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1199
methods
1200

            
1201
=item *
1202

            
1203
C<execute()> method
1204

            
1205
=item *
1206

            
1207
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1208

            
1209
=item *
1210

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

            
1213
=back
1214

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1217
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1218
        limit => sub {
1219
            ...;
1220
        }
1221
    );
1222

            
cleanup
Yuki Kimoto authored on 2011-01-25
1223
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1224

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

            
1227
    $dbi->rollback;
1228

            
1229
Rollback transaction.
1230
This is same as L<DBI>'s C<rollback>.
1231

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

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

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

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

            
1262
First element is a string. it contains tags,
1263
such as "{= title} or {like author}".
1264
Second element is paramters.
1265

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

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

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

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

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

            
1297
Create a L<DBIx::Custom::Table> object,
1298
or get a L<DBIx::Custom::Table> object.
1299

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

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

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

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

            
1314
    my $where = $dbi->where;
1315

            
1316
Create a new L<DBIx::Custom::Where> object.
1317

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

            
1320
    $dbi          = $dbi->cache_method(\&cache_method);
1321
    $cache_method = $dbi->cache_method
1322

            
1323
Method to set and get caches.
1324

            
cleanup
Yuki Kimoto authored on 2011-01-25
1325
=head1 Tags
1326

            
1327
The following tags is available.
1328

            
1329
=head2 C<?>
1330

            
1331
Placeholder tag.
1332

            
1333
    {? NAME}    ->   ?
1334

            
1335
=head2 C<=>
1336

            
1337
Equal tag.
1338

            
1339
    {= NAME}    ->   NAME = ?
1340

            
1341
=head2 C<E<lt>E<gt>>
1342

            
1343
Not equal tag.
1344

            
1345
    {<> NAME}   ->   NAME <> ?
1346

            
1347
=head2 C<E<lt>>
1348

            
1349
Lower than tag
1350

            
1351
    {< NAME}    ->   NAME < ?
1352

            
1353
=head2 C<E<gt>>
1354

            
1355
Greater than tag
1356

            
1357
    {> NAME}    ->   NAME > ?
1358

            
1359
=head2 C<E<gt>=>
1360

            
1361
Greater than or equal tag
1362

            
1363
    {>= NAME}   ->   NAME >= ?
1364

            
1365
=head2 C<E<lt>=>
1366

            
1367
Lower than or equal tag
1368

            
1369
    {<= NAME}   ->   NAME <= ?
1370

            
1371
=head2 C<like>
1372

            
1373
Like tag
1374

            
1375
    {like NAME}   ->   NAME like ?
1376

            
1377
=head2 C<in>
1378

            
1379
In tag.
1380

            
1381
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1382

            
1383
=head2 C<insert_param>
1384

            
1385
Insert parameter tag.
1386

            
1387
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1388

            
1389
=head2 C<update_param>
1390

            
1391
Updata parameter tag.
1392

            
1393
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1394

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

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

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

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

            
1404
C<< <kimoto.yuki at gmail.com> >>
1405

            
1406
L<http://github.com/yuki-kimoto/DBIx-Custom>
1407

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1408
=head1 AUTHOR
1409

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

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

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

            
1416
This program is free software; you can redistribute it and/or modify it
1417
under the same terms as Perl itself.
1418

            
1419
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1420

            
1421