DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
1397 lines | 35.635kb
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
    
cleanup
Yuki Kimoto authored on 2011-01-12
336
    # Create bind values
337
    my $binds = $self->_build_binds($params, $query->columns, $filter);
cleanup
yuki-kimoto authored on 2010-10-17
338
    
339
    # Execute
340
    my $sth      = $query->sth;
341
    my $affected;
cleanup
Yuki Kimoto authored on 2011-01-12
342
    eval {$affected = $sth->execute(@$binds)};
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

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

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-12
698
sub _build_binds {
699
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
700
    
cleanup
Yuki Kimoto authored on 2011-01-12
701
    # bind values
702
    my @binds;
add tests
yuki-kimoto authored on 2010-08-08
703
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
704
    # Build bind values
705
    my $count = {};
cleanup
Yuki Kimoto authored on 2011-01-12
706
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
707
        
708
        # Value
709
        my $value = ref $params->{$column} eq 'ARRAY'
710
                  ? $params->{$column}->[$count->{$column} || 0]
711
                  : $params->{$column};
712
        
cleanup
Yuki Kimoto authored on 2011-01-12
713
        # Filter
714
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
715
        
cleanup
Yuki Kimoto authored on 2011-01-12
716
        push @binds, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
717
        
718
        # Count up 
719
        $count->{$column}++;
720
    }
721
    
cleanup
Yuki Kimoto authored on 2011-01-12
722
    return \@binds;
removed reconnect method
yuki-kimoto authored on 2010-05-28
723
}
724

            
cleanup
yuki-kimoto authored on 2010-10-17
725
sub _croak {
726
    my ($self, $error, $append) = @_;
727
    $append ||= "";
728
    
729
    # Verbose
730
    if ($Carp::Verbose) { croak $error }
731
    
732
    # Not verbose
733
    else {
734
        
735
        # Remove line and module infromation
736
        my $at_pos = rindex($error, ' at ');
737
        $error = substr($error, 0, $at_pos);
738
        $error =~ s/\s+$//;
739
        
740
        croak "$error$append";
741
    }
742
}
743

            
cleanup
Yuki Kimoto authored on 2011-01-25
744
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
745
__PACKAGE__->attr(
746
    dbi_options => sub { {} },
747
    filter_check  => 1
748
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
749

            
cleanup
Yuki Kimoto authored on 2011-01-25
750
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
751
sub default_bind_filter {
752
    my $self = shift;
753
    
754
    if (@_) {
755
        my $fname = $_[0];
756
        
757
        if (@_ && !$fname) {
758
            $self->{default_out_filter} = undef;
759
        }
760
        else {
many changed
Yuki Kimoto authored on 2011-01-23
761
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
762
              unless exists $self->filters->{$fname};
763
        
764
            $self->{default_out_filter} = $self->filters->{$fname};
765
        }
766
        return $self;
767
    }
768
    
769
    return $self->{default_out_filter};
770
}
771

            
cleanup
Yuki Kimoto authored on 2011-01-25
772
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
773
sub default_fetch_filter {
774
    my $self = shift;
775
    
776
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
777
        my $fname = $_[0];
778

            
cleanup
Yuki Kimoto authored on 2011-01-12
779
        if (@_ && !$fname) {
780
            $self->{default_in_filter} = undef;
781
        }
782
        else {
many changed
Yuki Kimoto authored on 2011-01-23
783
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
784
              unless exists $self->filters->{$fname};
785
        
786
            $self->{default_in_filter} = $self->filters->{$fname};
787
        }
788
        
789
        return $self;
790
    }
791
    
many changed
Yuki Kimoto authored on 2011-01-23
792
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
793
}
794

            
cleanup
Yuki Kimoto authored on 2011-01-25
795
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
796
sub register_tag_processor {
797
    return shift->query_builder->register_tag_processor(@_);
798
}
799

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
802
=head1 NAME
803

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

            
806
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
807

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
813
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
814
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
815
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
816
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
817
    
818
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
819
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
820
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
821
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
822
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
823
    
824
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
825
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
826
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
827
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
828
    
829
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
830
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
831
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
832
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
833
    
834
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
835
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
836

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
837
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
838
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
839
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
840
        column => [qw/author title/],
841
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
842
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
843
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
844
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
845
    );
cleanup
yuki-kimoto authored on 2010-08-05
846

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

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

            
861
    # Get DBI object
862
    my $dbh = $dbi->dbh;
863

            
removed register_format()
yuki-kimoto authored on 2010-05-26
864
    # Fetch
865
    while (my $row = $result->fetch) {
866
        # ...
867
    }
868
    
869
    # Fetch hash
870
    while (my $row = $result->fetch_hash) {
871
        
872
    }
873
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
874
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
875

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

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

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

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

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

            
898
=head1 GUIDE
899

            
900
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
901

            
902
=head1 EXAMPLES
903

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

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

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

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

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

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

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

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

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

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

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

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

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

            
936
DBI options.
937
C<connect()> method use this value to connect the database.
938

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
946
=head2 C<password>
947

            
948
    my $password = $dbi->password;
949
    $dbi         = $dbi->password('lkj&le`@s');
950

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
973
    my $user = $dbi->user;
974
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
975

            
cleanup
yuki-kimoto authored on 2010-10-17
976
User name.
977
C<connect()> method use this value to connect the database.
978
    
979
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
980

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
986
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
987
        $table,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
988
        $column1 => {in => $infilter1, out => $outfilter1}
989
        $column2 => {in => $infilter2, out => $outfilter2}
990
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
991
    );
992

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
1000
    $result = $dbi->execute(
1001
        "select * from table1 where {= key1} and {= key2};",
1002
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1003
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
1004
    );
1005
    
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1006
=head2 C<begin_work>
added check_filter attribute
yuki-kimoto authored on 2010-08-08
1007

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

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

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

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

            
1018
    $dbi->commit;
1019

            
1020
Commit transaction.
1021
This is same as L<DBI>'s C<commit>.
1022

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

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

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

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

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

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

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

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

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

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

            
1058
    my %expand = $dbi->expand($source);
1059

            
1060
The following hash
1061

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

            
1064
is expanded to
1065

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

            
1068
This is used in C<select()>
1069

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1072
    $dbi->delete(table  => $table,
1073
                 where  => \%where,
1074
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1075
                 filter => \%filter,
1076
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1077

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

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

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

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1097
=head2 C<(experimental) method>
added helper method
yuki-kimoto authored on 2010-10-17
1098

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1099
    $dbi->method(
added helper method
yuki-kimoto authored on 2010-10-17
1100
        update_or_insert => sub {
1101
            my $self = shift;
1102
            # do something
1103
        },
1104
        find_or_create   => sub {
1105
            my $self = shift;
1106
            # do something
1107
        }
1108
    );
1109

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
1110
Register method. These method is called from L<DBIx::Custom> object directory.
added helper method
yuki-kimoto authored on 2010-10-17
1111

            
1112
    $dbi->update_or_insert;
1113
    $dbi->find_or_create;
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

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

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

            
1140
Create a new L<DBIx::Custom> object.
1141

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1161
=head2 C<register_filter>
1162

            
1163
    $dbi->register_filter(%filters);
1164
    $dbi->register_filter(\%filters);
1165
    
1166
Register filter. Registered filters is available in the following attributes
1167
or arguments.
1168

            
1169
=over 4
1170

            
1171
=item *
1172

            
1173
C<filter> argument of C<insert()>, C<update()>,
1174
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1175
methods
1176

            
1177
=item *
1178

            
1179
C<execute()> method
1180

            
1181
=item *
1182

            
1183
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1184

            
1185
=item *
1186

            
1187
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1188

            
1189
=back
1190

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1193
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1194
        limit => sub {
1195
            ...;
1196
        }
1197
    );
1198

            
cleanup
Yuki Kimoto authored on 2011-01-25
1199
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1200

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

            
1203
    $dbi->rollback;
1204

            
1205
Rollback transaction.
1206
This is same as L<DBI>'s C<rollback>.
1207

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

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

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

            
1231
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1232
        table  => 'book',
cleanup
yuki-kimoto authored on 2010-08-09
1233
        column => ['title', 'author'],
1234
        where  => ['{= title} or {like author}',
1235
                   {title => '%Perl%', author => 'Ken'}]
1236
    );
1237

            
1238
First element is a string. it contains tags,
1239
such as "{= title} or {like author}".
1240
Second element is paramters.
1241

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1244
    $dbi->update(table  => $table, 
1245
                 param  => \%params,
1246
                 where  => \%where,
1247
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1248
                 filter => \%filter,
1249
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1250

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

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

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
1266
    $dbi->table('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1267
        insert => sub { ... },
1268
        update => sub { ... }
1269
    );
1270
    
1271
    my $table = $dbi->table('book');
1272

            
1273
Create a L<DBIx::Custom::Table> object,
1274
or get a L<DBIx::Custom::Table> object.
1275

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1278
    $dbi->update_all(table  => $table, 
1279
                     param  => \%params,
1280
                     filter => \%filter,
1281
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1282

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

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

            
1290
    my $where = $dbi->where;
1291

            
1292
Create a new L<DBIx::Custom::Where> object.
1293

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

            
1296
    $dbi          = $dbi->cache_method(\&cache_method);
1297
    $cache_method = $dbi->cache_method
1298

            
1299
Method to set and get caches.
1300

            
cleanup
Yuki Kimoto authored on 2011-01-25
1301
=head1 Tags
1302

            
1303
The following tags is available.
1304

            
1305
=head2 C<?>
1306

            
1307
Placeholder tag.
1308

            
1309
    {? NAME}    ->   ?
1310

            
1311
=head2 C<=>
1312

            
1313
Equal tag.
1314

            
1315
    {= NAME}    ->   NAME = ?
1316

            
1317
=head2 C<E<lt>E<gt>>
1318

            
1319
Not equal tag.
1320

            
1321
    {<> NAME}   ->   NAME <> ?
1322

            
1323
=head2 C<E<lt>>
1324

            
1325
Lower than tag
1326

            
1327
    {< NAME}    ->   NAME < ?
1328

            
1329
=head2 C<E<gt>>
1330

            
1331
Greater than tag
1332

            
1333
    {> NAME}    ->   NAME > ?
1334

            
1335
=head2 C<E<gt>=>
1336

            
1337
Greater than or equal tag
1338

            
1339
    {>= NAME}   ->   NAME >= ?
1340

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

            
1343
Lower than or equal tag
1344

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

            
1347
=head2 C<like>
1348

            
1349
Like tag
1350

            
1351
    {like NAME}   ->   NAME like ?
1352

            
1353
=head2 C<in>
1354

            
1355
In tag.
1356

            
1357
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1358

            
1359
=head2 C<insert_param>
1360

            
1361
Insert parameter tag.
1362

            
1363
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1364

            
1365
=head2 C<update_param>
1366

            
1367
Updata parameter tag.
1368

            
1369
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1370

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

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

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

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

            
1380
C<< <kimoto.yuki at gmail.com> >>
1381

            
1382
L<http://github.com/yuki-kimoto/DBIx-Custom>
1383

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1384
=head1 AUTHOR
1385

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

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

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

            
1392
This program is free software; you can redistribute it and/or modify it
1393
under the same terms as Perl itself.
1394

            
1395
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1396

            
1397