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

            
many changed
Yuki Kimoto authored on 2011-01-23
3
our $VERSION = '0.1636';
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;
update document
yuki-kimoto authored on 2010-05-27
17
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
18

            
fix tests
Yuki Kimoto authored on 2011-01-13
19
__PACKAGE__->attr(
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
20
    [qw/data_source dbh password user/],
fix tests
Yuki Kimoto authored on 2011-01-13
21
    cache => 1,
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
22
    dbi_option => sub { {} },
cleanup
Yuki Kimoto authored on 2011-01-23
23
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
many changed
Yuki Kimoto authored on 2011-01-23
24
    result_class  => 'DBIx::Custom::Result',
25
    table_class   => 'DBIx::Custom::Table'
26
);
27

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
67
our $AUTOLOAD;
68

            
69
sub AUTOLOAD {
70
    my $self = shift;
71

            
72
    # Method
73
    my ($package, $method) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/;
74

            
75
    # Helper
76
    $self->{_helpers} ||= {};
77
    croak qq/Can't locate object method "$method" via "$package"/
78
      unless my $helper = $self->{_helpers}->{$method};
79

            
80
    # Run
81
    return $self->$helper(@_);
82
}
83

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
148
sub helper {
149
    my $self = shift;
150
    
151
    # Merge
152
    my $helpers = ref $_[0] eq 'HASH' ? $_[0] : {@_};
153
    $self->{_helpers} = {%{$self->{_helpers} || {}}, %$helpers};
154
    
155
    return $self;
156
}
157

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
458
sub register_filter {
459
    my $invocant = shift;
460
    
461
    # Register filter
462
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
463
    $invocant->filters({%{$invocant->filters}, %$filters});
464
    
465
    return $invocant;
466
}
packaging one directory
yuki-kimoto authored on 2009-11-16
467

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
468
sub register_tag_processor {
469
    return shift->query_builder->register_tag_processor(@_);
470
}
471

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

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

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
571
sub table {
572
    my $self = shift;
573
    my $name = shift;
574
    
575
    # Table class
576
    my $table_class = $self->table_class;
577
    croak qq{Invalid table class name "$table_class"}
578
      unless $table_class =~ /^[\w:]+$/;
579
    unless ($table_class->can('isa')) {
580
        eval "require $table_class";
581
        croak $@ if $@;
582
    }
583
    # Create table
584
    $self->{_tables} ||= {};
585
    $self->{_tables}->{$name}
586
        = $table_class->new(name => $name, dbi => $self)
587
      unless defined $self->{_tables}->{$name};
588
    
589
    # Helper
590
    $self->{_tables}->{$name}->helper(@_) if @_;
591
    
592
    return $self->{_tables}{$name};
593
}
594

            
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
595
sub txn_scope {
596
    my $self = shift;
597
    
598
    require DBIx::TransactionManager;
599
    
600
    $self->{_transaction_manager}
601
      ||= DBIx::TransactionManager->new($self->dbh);
602
    
603
    return $self->{_transaction_manager}->txn_scope;
604
}
605

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

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

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

            
added test
Yuki Kimoto authored on 2011-01-19
684
sub where { DBIx::Custom::Where->new(
685
              query_builder => shift->query_builder) }
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
686

            
cleanup
Yuki Kimoto authored on 2011-01-12
687
sub _build_binds {
688
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
689
    
cleanup
Yuki Kimoto authored on 2011-01-12
690
    # bind values
691
    my @binds;
add tests
yuki-kimoto authored on 2010-08-08
692
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
693
    # Build bind values
694
    my $count = {};
cleanup
Yuki Kimoto authored on 2011-01-12
695
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
696
        
697
        # Value
698
        my $value = ref $params->{$column} eq 'ARRAY'
699
                  ? $params->{$column}->[$count->{$column} || 0]
700
                  : $params->{$column};
701
        
cleanup
Yuki Kimoto authored on 2011-01-12
702
        # Filter
703
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
704
        
cleanup
Yuki Kimoto authored on 2011-01-12
705
        push @binds, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
706
        
707
        # Count up 
708
        $count->{$column}++;
709
    }
710
    
cleanup
Yuki Kimoto authored on 2011-01-12
711
    return \@binds;
removed reconnect method
yuki-kimoto authored on 2010-05-28
712
}
713

            
cleanup
yuki-kimoto authored on 2010-10-17
714
sub _croak {
715
    my ($self, $error, $append) = @_;
716
    $append ||= "";
717
    
718
    # Verbose
719
    if ($Carp::Verbose) { croak $error }
720
    
721
    # Not verbose
722
    else {
723
        
724
        # Remove line and module infromation
725
        my $at_pos = rindex($error, ' at ');
726
        $error = substr($error, 0, $at_pos);
727
        $error =~ s/\s+$//;
728
        
729
        croak "$error$append";
730
    }
731
}
732

            
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
733
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
734
__PACKAGE__->attr(
735
    dbi_options => sub { {} },
736
    filter_check  => 1
737
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
738

            
cleanup
Yuki Kimoto authored on 2011-01-12
739
sub default_bind_filter {
740
    my $self = shift;
741
    
742
    if (@_) {
743
        my $fname = $_[0];
744
        
745
        if (@_ && !$fname) {
746
            $self->{default_out_filter} = undef;
747
        }
748
        else {
many changed
Yuki Kimoto authored on 2011-01-23
749
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
750
              unless exists $self->filters->{$fname};
751
        
752
            $self->{default_out_filter} = $self->filters->{$fname};
753
        }
754
        return $self;
755
    }
756
    
757
    return $self->{default_out_filter};
758
}
759

            
760
sub default_fetch_filter {
761
    my $self = shift;
762
    
763
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
764
        my $fname = $_[0];
765

            
cleanup
Yuki Kimoto authored on 2011-01-12
766
        if (@_ && !$fname) {
767
            $self->{default_in_filter} = undef;
768
        }
769
        else {
many changed
Yuki Kimoto authored on 2011-01-23
770
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
771
              unless exists $self->filters->{$fname};
772
        
773
            $self->{default_in_filter} = $self->filters->{$fname};
774
        }
775
        
776
        return $self;
777
    }
778
    
many changed
Yuki Kimoto authored on 2011-01-23
779
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
780
}
781

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
784
=head1 NAME
785

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

            
788
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
789

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
795
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
796
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
797
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
798
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
799
    
800
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
801
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
802
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
803
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
804
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
805
    
806
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
807
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
808
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
809
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
810
    
811
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
812
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
813
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
814
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
815
    
816
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
817
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
818

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
819
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
820
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
821
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
822
        column => [qw/author title/],
823
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
824
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
825
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
826
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
827
    );
cleanup
yuki-kimoto authored on 2010-08-05
828

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

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

            
843
    # Get DBI object
844
    my $dbh = $dbi->dbh;
845

            
removed register_format()
yuki-kimoto authored on 2010-05-26
846
    # Fetch
847
    while (my $row = $result->fetch) {
848
        # ...
849
    }
850
    
851
    # Fetch hash
852
    while (my $row = $result->fetch_hash) {
853
        
854
    }
855
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
856
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
857

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

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

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

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

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

            
880
=head1 GUIDE
881

            
882
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
883

            
884
=head1 EXAMPLES
885

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

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

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

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

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

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

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

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

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

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

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

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

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

            
918
DBI options.
919
C<connect()> method use this value to connect the database.
920

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
928
=head2 C<filter_check>
929

            
930
    my $filter_check = $dbi->filter_check;
931
    $dbi             = $dbi->filter_check(0);
932

            
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
933
B<this attribute is now deprecated and has no mean
934
because check is always done>. 
cleanup
yuki-kimoto authored on 2010-10-17
935

            
936
=head2 C<password>
937

            
938
    my $password = $dbi->password;
939
    $dbi         = $dbi->password('lkj&le`@s');
940

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
963
    my $user = $dbi->user;
964
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
965

            
cleanup
yuki-kimoto authored on 2010-10-17
966
User name.
967
C<connect()> method use this value to connect the database.
968
    
969
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
970

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
974
=head2 C<(experimental) apply_filter >
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
975

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
976
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
977
        $table,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
978
        $column1 => {in => $infilter1, out => $outfilter1}
979
        $column2 => {in => $infilter2, out => $outfilter2}
980
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
981
    );
982

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
990
    $result = $dbi->execute(
991
        "select * from table1 where {= key1} and {= key2};",
992
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
993
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
994
    );
995
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
996
=head2 C<begin_work>
added check_filter attribute
yuki-kimoto authored on 2010-08-08
997

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

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

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

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

            
1008
    $dbi->commit;
1009

            
1010
Commit transaction.
1011
This is same as L<DBI>'s C<commit>.
1012

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

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

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

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

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

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

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

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

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

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

            
1048
    my %expand = $dbi->expand($source);
1049

            
1050
The following hash
1051

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

            
1054
is expanded to
1055

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

            
1058
This is used in C<select()>
1059

            
1060

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1064
    $dbi->delete(table  => $table,
1065
                 where  => \%where,
1066
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1067
                 filter => \%filter,
1068
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1069

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

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

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

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

            
added helper method
yuki-kimoto authored on 2010-10-17
1089
=head2 C<(experimental) helper>
1090

            
1091
    $dbi->helper(
1092
        update_or_insert => sub {
1093
            my $self = shift;
1094
            # do something
1095
        },
1096
        find_or_create   => sub {
1097
            my $self = shift;
1098
            # do something
1099
        }
1100
    );
1101

            
1102
Register helper methods. These method is called from L<DBIx::Custom> object directory.
1103

            
1104
    $dbi->update_or_insert;
1105
    $dbi->find_or_create;
1106

            
cleanup
yuki-kimoto authored on 2010-10-17
1107
=head2 C<insert>
1108

            
1109
    $dbi->insert(table  => $table, 
1110
                 param  => \%param,
1111
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1112
                 filter => \%filter,
1113
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1114

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

            
added dbi_options attribute
kimoto authored on 2010-12-20
1127
=head2 C<new>
1128

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

            
1132
Create a new L<DBIx::Custom> object.
1133

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1153
=head2 C<register_filter>
1154

            
1155
    $dbi->register_filter(%filters);
1156
    $dbi->register_filter(\%filters);
1157
    
1158
Register filter. Registered filters is available in the following attributes
1159
or arguments.
1160

            
1161
=over 4
1162

            
1163
=item *
1164

            
1165
C<filter> argument of C<insert()>, C<update()>,
1166
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1167
methods
1168

            
1169
=item *
1170

            
1171
C<execute()> method
1172

            
1173
=item *
1174

            
1175
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1176

            
1177
=item *
1178

            
1179
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1180

            
1181
=back
1182

            
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1183
=head2 C<register_tag_processor>
1184

            
1185
    $dbi->register_tag_processor(
1186
        limit => sub {
1187
            ...;
1188
        }
1189
    );
1190

            
1191
Register tag processor.
1192

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

            
1195
    $dbi->rollback;
1196

            
1197
Rollback transaction.
1198
This is same as L<DBI>'s C<rollback>.
1199

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1200
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1201
    
cleanup
yuki-kimoto authored on 2010-08-05
1202
    my $result = $dbi->select(table    => $table,
1203
                              column   => [@column],
1204
                              where    => \%where,
1205
                              append   => $append,
1206
                              relation => \%relation,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1207
                              filter   => \%filter,
1208
                              query    => 1);
update document
yuki-kimoto authored on 2009-11-19
1209

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

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

            
1223
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1224
        table  => 'book',
cleanup
yuki-kimoto authored on 2010-08-09
1225
        column => ['title', 'author'],
1226
        where  => ['{= title} or {like author}',
1227
                   {title => '%Perl%', author => 'Ken'}]
1228
    );
1229

            
1230
First element is a string. it contains tags,
1231
such as "{= title} or {like author}".
1232
Second element is paramters.
1233

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1236
    $dbi->update(table  => $table, 
1237
                 param  => \%params,
1238
                 where  => \%where,
1239
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1240
                 filter => \%filter,
1241
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1242

            
cleanup
yuki-kimoto authored on 2010-10-17
1243
Execute update statement.
1244
C<update> method have C<table>, C<param>, C<where>, C<append>
1245
and C<filter> arguments.
1246
C<table> is a table name.
1247
C<param> is column-value pairs. this must be hash reference.
1248
C<where> is where clause. this must be hash reference.
1249
C<append> is a string added at the end of the SQL statement.
1250
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1251
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1252
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1253
This is overwrites C<default_bind_filter>.
1254
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1255

            
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1256
=head2 C<(experimental) txn_scope>
1257

            
1258
    {
1259
        my $txn = $dbi->txn_scope;
1260
        $dbi->insert(table => 'book', param => {title => 'Perl'});
1261
        $dbi->insert(table => 'book', param => {title => 'Good days'});
1262
        $txn->commit;
1263
    }
1264

            
1265
Create transaction scope. If you escape scope(that is { .. }) and commited,
1266
Rollback is automatically done.
1267

            
1268
Note that this is feature of L<DBIx::TransactionManager>
1269
L<DBIx::TransactionManager> is required.
1270

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

            
1273
    $dbi->table('book',
1274
        insert => sub { ... },
1275
        update => sub { ... }
1276
    );
1277
    
1278
    my $table = $dbi->table('book');
1279

            
1280
Create a L<DBIx::Custom::Table> object,
1281
or get a L<DBIx::Custom::Table> object.
1282

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1285
    $dbi->update_all(table  => $table, 
1286
                     param  => \%params,
1287
                     filter => \%filter,
1288
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1289

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

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

            
1297
    my $where = $dbi->where;
1298

            
1299
Create a new L<DBIx::Custom::Where> object.
1300

            
cleanup
Yuki Kimoto authored on 2011-01-12
1301
=head2 C<(deprecated) cache_method>
1302

            
1303
    $dbi          = $dbi->cache_method(\&cache_method);
1304
    $cache_method = $dbi->cache_method
1305

            
1306
Method to set and get caches.
1307

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

            
1310
L<DBIx::Custom> is now stable. APIs keep backword compatible in the feature.
1311

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

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

            
1316
C<< <kimoto.yuki at gmail.com> >>
1317

            
1318
L<http://github.com/yuki-kimoto/DBIx-Custom>
1319

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1320
=head1 AUTHOR
1321

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

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

            
1326
Copyright 2009 Yuki Kimoto, all rights reserved.
1327

            
1328
This program is free software; you can redistribute it and/or modify it
1329
under the same terms as Perl itself.
1330

            
1331
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1332

            
1333