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

            
autoload DBI method
Yuki Kimoto authored on 2011-01-26
3
our $VERSION = '0.1640';
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

            
added helper method
yuki-kimoto authored on 2010-10-17
56
our $AUTOLOAD;
57
sub AUTOLOAD {
58
    my $self = shift;
59

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
63
    # Method
64
    $self->{_methods} ||= {};
autoload DBI method
Yuki Kimoto authored on 2011-01-26
65
    my $method = $self->{_methods}->{$mname};
66
    return $self->$method(@_) if $method;
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
67
    
autoload DBI method
Yuki Kimoto authored on 2011-01-26
68
    # DBI method
69
    return $self->dbh->$mname(@_);
added helper method
yuki-kimoto authored on 2010-10-17
70
}
71

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

            
75
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
76
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
77
    $self->{filter}{out} ||= {};
78
    $self->{filter}{in} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
79
    
many changed
Yuki Kimoto authored on 2011-01-23
80
    # Create filters
81
    my $usage = "Usage: \$dbi->apply_filter(" .
82
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1}, " .
83
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2}, ...)";
84

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
136
sub method {
added helper method
yuki-kimoto authored on 2010-10-17
137
    my $self = shift;
138
    
139
    # Merge
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
140
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
141
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
added helper method
yuki-kimoto authored on 2010-10-17
142
    
143
    return $self;
144
}
145

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

            
cleanup
yuki-kimoto authored on 2010-10-17
179
sub create_query {
180
    my ($self, $source) = @_;
update document
yuki-kimoto authored on 2010-01-30
181
    
cleanup
yuki-kimoto authored on 2010-10-17
182
    # Cache
183
    my $cache = $self->cache;
update document
yuki-kimoto authored on 2010-01-30
184
    
cleanup
yuki-kimoto authored on 2010-10-17
185
    # Create query
186
    my $query;
187
    if ($cache) {
188
        
189
        # Get query
190
        my $q = $self->cache_method->($self, $source);
191
        
192
        # Create query
193
        $query = DBIx::Custom::Query->new($q) if $q;
194
    }
195
    
196
    unless ($query) {
cleanup insert
yuki-kimoto authored on 2010-04-28
197

            
cleanup
yuki-kimoto authored on 2010-10-17
198
        # Create SQL object
199
        my $builder = $self->query_builder;
200
        
201
        # Create query
202
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
203

            
cleanup
yuki-kimoto authored on 2010-10-17
204
        # Cache query
205
        $self->cache_method->($self, $source,
206
                             {sql     => $query->sql, 
207
                              columns => $query->columns})
208
          if $cache;
cleanup insert
yuki-kimoto authored on 2010-04-28
209
    }
210
    
cleanup
yuki-kimoto authored on 2010-10-17
211
    # Prepare statement handle
212
    my $sth;
213
    eval { $sth = $self->dbh->prepare($query->{sql})};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
214
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
packaging one directory
yuki-kimoto authored on 2009-11-16
215
    
cleanup
yuki-kimoto authored on 2010-10-17
216
    # Set statement handle
217
    $query->sth($sth);
packaging one directory
yuki-kimoto authored on 2009-11-16
218
    
cleanup
yuki-kimoto authored on 2010-10-17
219
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
220
}
221

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

            
cleanup
yuki-kimoto authored on 2010-10-17
225
sub delete {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
226
    my ($self, %args) = @_;
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
227
    
228
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
229
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
230
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
231
          unless $VALID_DELETE_ARGS{$name};
cleanup update and update_al...
yuki-kimoto authored on 2010-04-28
232
    }
233
    
234
    # Arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
235
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
236
    croak qq{"table" option must be specified} unless $table;
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
237
    my $where            = $args{where} || {};
cleanup
yuki-kimoto authored on 2010-10-17
238
    my $append = $args{append};
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
239
    my $filter           = $args{filter};
cleanup
yuki-kimoto authored on 2010-10-17
240
    my $allow_delete_all = $args{allow_delete_all};
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
241

            
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
242
    # Where
243
    my $w;
244
    if (ref $where eq 'HASH') {
245
        my $clause = ['and'];
246
        push @$clause, "{= $_}" for keys %$where;
247
        $w = $self->where;
248
        $w->clause($clause);
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
249
        $w->param($where);
packaging one directory
yuki-kimoto authored on 2009-11-16
250
    }
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
251
    else { $w = $where }
packaging one directory
yuki-kimoto authored on 2009-11-16
252
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
253
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
254
      unless ref $w eq 'DBIx::Custom::Where';
255
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
256
    $where = $w->param;
257
    
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
258
    croak qq{"where" must be specified}
259
      if "$w" eq '' && !$allow_delete_all;
260

            
add tests
yuki-kimoto authored on 2010-08-10
261
    # Source of SQL
make delete() using where ob...
Yuki Kimoto authored on 2011-01-26
262
    my $source = "delete from $table $w";
add tests
yuki-kimoto authored on 2010-08-10
263
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
264
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
265
    # Create query
266
    my $query = $self->create_query($source);
267
    return $query if $args{query};
268
    
packaging one directory
yuki-kimoto authored on 2009-11-16
269
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
270
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
271
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
272
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
273
    
274
    return $ret_val;
275
}
276

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

            
added helper method
yuki-kimoto authored on 2010-10-17
279
sub DESTROY { }
280

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

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

            
356
        return $result;
357
    }
358
    return $affected;
359
}
360

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

            
366
    # Check arguments
367
    foreach my $name (keys %args) {
368
        croak qq{"$name" is invalid argument}
369
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
370
    }
371
    
cleanup
yuki-kimoto authored on 2010-10-17
372
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
373
    my $table  = $args{table};
374
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
375
    my $param  = $args{param} || {};
376
    my $append = $args{append} || '';
377
    my $filter = $args{filter};
378
    
379
    # Insert keys
380
    my @insert_keys = keys %$param;
381
    
382
    # Templte for insert
383
    my $source = "insert into $table {insert_param "
384
               . join(' ', @insert_keys) . '}';
add tests
yuki-kimoto authored on 2010-08-10
385
    $source .= " $append" if $append;
packaging one directory
yuki-kimoto authored on 2009-11-16
386
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
387
    # Create query
388
    my $query = $self->create_query($source);
389
    return $query if $args{query};
390
    
packaging one directory
yuki-kimoto authored on 2009-11-16
391
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
392
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
393
        $query,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
394
        param  => $param,
395
        filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
396
        table => $table
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
397
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
398
    
399
    return $ret_val;
400
}
401

            
pod fix
Yuki Kimoto authored on 2011-01-21
402
sub each_column {
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
403
    my ($self, $cb) = @_;
404
    
405
    # Iterate all tables
406
    my $sth_tables = $self->dbh->table_info;
407
    while (my $table_info = $sth_tables->fetchrow_hashref) {
408
        
409
        # Table
410
        my $table = $table_info->{TABLE_NAME};
411
        
412
        # Iterate all columns
413
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
414
        while (my $column_info = $sth_columns->fetchrow_hashref) {
415
            my $column = $column_info->{COLUMN_NAME};
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
416
            $self->$cb($table, $column, $column_info);
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
417
        }
418
    }
419
}
420

            
added dbi_options attribute
kimoto authored on 2010-12-20
421
sub new {
422
    my $self = shift->SUPER::new(@_);
423
    
424
    # Check attribute names
425
    my @attrs = keys %$self;
426
    foreach my $attr (@attrs) {
427
        croak qq{"$attr" is invalid attribute name}
428
          unless $self->can($attr);
429
    }
cleanup
Yuki Kimoto authored on 2011-01-25
430

            
431
    $self->register_tag(
432
        '?'     => \&DBIx::Custom::Tag::placeholder,
433
        '='     => \&DBIx::Custom::Tag::equal,
434
        '<>'    => \&DBIx::Custom::Tag::not_equal,
435
        '>'     => \&DBIx::Custom::Tag::greater_than,
436
        '<'     => \&DBIx::Custom::Tag::lower_than,
437
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
438
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
439
        'like'  => \&DBIx::Custom::Tag::like,
440
        'in'    => \&DBIx::Custom::Tag::in,
441
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
442
        'update_param' => \&DBIx::Custom::Tag::update_param
443
    );
added dbi_options attribute
kimoto authored on 2010-12-20
444
    
445
    return $self;
446
}
447

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

            
cleanup
yuki-kimoto authored on 2010-10-17
450
sub register_filter {
451
    my $invocant = shift;
452
    
453
    # Register filter
454
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
455
    $invocant->filters({%{$invocant->filters}, %$filters});
456
    
457
    return $invocant;
458
}
packaging one directory
yuki-kimoto authored on 2009-11-16
459

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

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

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

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
561
sub table {
562
    my $self = shift;
563
    my $name = shift;
564
    
565
    # Create table
566
    $self->{_tables} ||= {};
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
567
    unless (defined $self->{_tables}->{$name}) {
568
        # Base table
569
        my $base_table = $self->base_table;
570
        
571
        # Base methods
572
        my $bmethods = ref $base_table->{_methods} eq 'HASH'
573
                     ? $base_table->{_methods}
574
                     : {};
575
        
576
        # Copy Methods
577
        my $methods = {};
578
        $methods->{$_} = $bmethods->{$_} for keys %$bmethods;
579
        
580
        # Create table
581
        my $table = $base_table->new(
582
            dbi      => $self,
583
            name     => $name,
584
            base     => $base_table,
585
            _methods => $methods
586
        );
587
        $self->{_tables}->{$name} = $table;
588
    }
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
589
    
590
    return $self->{_tables}{$name};
591
}
592

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

            
597
sub update {
598
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
599
    
cleanup
yuki-kimoto authored on 2010-10-17
600
    # Check arguments
601
    foreach my $name (keys %args) {
602
        croak qq{"$name" is invalid argument}
603
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
604
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
605
    
cleanup
yuki-kimoto authored on 2010-10-17
606
    # Arguments
607
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
608
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
609
    my $param            = $args{param} || {};
610
    my $where            = $args{where} || {};
611
    my $append = $args{append} || '';
612
    my $filter           = $args{filter};
613
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
614
    
cleanup
yuki-kimoto authored on 2010-10-17
615
    # Update keys
616
    my @update_keys = keys %$param;
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
617
    
cleanup
yuki-kimoto authored on 2010-10-17
618
    # Update clause
619
    my $update_clause = '{update_param ' . join(' ', @update_keys) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
620

            
621
    # Where
622
    my $w;
623
    if (ref $where eq 'HASH') {
624
        my $clause = ['and'];
625
        push @$clause, "{= $_}" for keys %$where;
626
        $w = $self->where;
627
        $w->clause($clause);
628
        $w->param($where);
629
    }
630
    else { $w = $where }
removed experimental registe...
yuki-kimoto authored on 2010-08-24
631
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
632
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
633
      unless ref $w eq 'DBIx::Custom::Where';
removed reconnect method
yuki-kimoto authored on 2010-05-28
634
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
635
    $where = $w->param;
636
    
637
    croak qq{"where" must be specified}
638
      if "$w" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
639
    
cleanup
yuki-kimoto authored on 2010-10-17
640
    # Source of SQL
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
641
    my $source = "update $table $update_clause $w";
cleanup
yuki-kimoto authored on 2010-10-17
642
    $source .= " $append" if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
643
    
cleanup
yuki-kimoto authored on 2010-10-17
644
    # Rearrange parameters
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
645
    foreach my $wkey (keys %$where) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
646
        
cleanup
yuki-kimoto authored on 2010-10-17
647
        if (exists $param->{$wkey}) {
648
            $param->{$wkey} = [$param->{$wkey}]
649
              unless ref $param->{$wkey} eq 'ARRAY';
650
            
651
            push @{$param->{$wkey}}, $where->{$wkey};
652
        }
653
        else {
654
            $param->{$wkey} = $where->{$wkey};
655
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
656
    }
cleanup
yuki-kimoto authored on 2010-10-17
657
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
658
    # Create query
659
    my $query = $self->create_query($source);
660
    return $query if $args{query};
661
    
cleanup
yuki-kimoto authored on 2010-10-17
662
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
663
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
664
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
665
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
666
    
667
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
668
}
669

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
672
sub where {
673
    return DBIx::Custom::Where->new(query_builder => shift->query_builder)
674
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
675

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
676
sub _bind {
cleanup
Yuki Kimoto authored on 2011-01-12
677
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
678
    
cleanup
Yuki Kimoto authored on 2011-01-12
679
    # bind values
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
680
    my @bind;
add tests
yuki-kimoto authored on 2010-08-08
681
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
682
    # Build bind values
683
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
684
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
685
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
686
        
687
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
688
        my $value;
689
        if(ref $params->{$column} eq 'ARRAY') {
690
            my $i = $count->{$column} || 0;
691
            $i += $not_exists->{$column} || 0;
692
            my $found;
693
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
694
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
695
                    $not_exists->{$column}++;
696
                }
697
                else  {
698
                    $value = $params->{$column}->[$k];
699
                    $found = 1;
700
                    last
701
                }
702
            }
703
            next unless $found;
704
        }
705
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
706
        
cleanup
Yuki Kimoto authored on 2011-01-12
707
        # Filter
708
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
709
        
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
710
        push @bind, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
711
        
712
        # Count up 
713
        $count->{$column}++;
714
    }
715
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
716
    return \@bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
717
}
718

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
738
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
739
__PACKAGE__->attr(
740
    dbi_options => sub { {} },
741
    filter_check  => 1
742
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
743

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
766
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
767
sub default_fetch_filter {
768
    my $self = shift;
769
    
770
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
771
        my $fname = $_[0];
772

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
789
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
790
sub register_tag_processor {
791
    return shift->query_builder->register_tag_processor(@_);
792
}
793

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
796
=head1 NAME
797

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

            
800
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
801

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
807
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
808
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
809
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
810
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
811
    
812
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
813
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
814
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
815
                 where  => {id => 5},
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 all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
819
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
820
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
821
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
822
    
823
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
824
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
825
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
826
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
827
    
828
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
829
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
830

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

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

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

            
855
    # Get DBI object
856
    my $dbh = $dbi->dbh;
857

            
removed register_format()
yuki-kimoto authored on 2010-05-26
858
    # Fetch
859
    while (my $row = $result->fetch) {
860
        # ...
861
    }
862
    
863
    # Fetch hash
864
    while (my $row = $result->fetch_hash) {
865
        
866
    }
867
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
868
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
869

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

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

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

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

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

            
892
=head1 GUIDE
893

            
894
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
895

            
896
=head1 EXAMPLES
897

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

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

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

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

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

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

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

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

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

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

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

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

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

            
930
DBI options.
931
C<connect()> method use this value to connect the database.
932

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
940
=head2 C<password>
941

            
942
    my $password = $dbi->password;
943
    $dbi         = $dbi->password('lkj&le`@s');
944

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
967
    my $user = $dbi->user;
968
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
969

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
995
    $result = $dbi->execute(
996
        "select * from table1 where {= key1} and {= key2};",
997
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
998
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
999
    );
1000
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1001
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1002

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1036
    $dbi->delete(table  => $table,
1037
                 where  => \%where,
1038
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1039
                 filter => \%filter,
1040
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1041

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1061
=head2 C<insert>
1062

            
1063
    $dbi->insert(table  => $table, 
1064
                 param  => \%param,
1065
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1066
                 filter => \%filter,
1067
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1068

            
1069
Execute insert statement.
1070
C<insert> method have C<table>, C<param>, C<append>
1071
and C<filter> arguments.
1072
C<table> is a table name.
1073
C<param> is the pairs of column name value. 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-10-17
1078
This is overwrites C<default_bind_filter>.
1079
Return value of C<insert()> is the count of affected rows.
1080

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
1083
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1084
        sub {
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1085
            my ($self, $table, $column, $info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1086
            
pod fix
Yuki Kimoto authored on 2011-01-21
1087
            my $type = $info->{TYPE_NAME};
1088
            
1089
            if ($type eq 'DATE') {
1090
                # ...
1091
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1092
        }
1093
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1094
Get column informations from database.
1095
Argument is callback.
1096
You can do anything in callback.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1097
Callback receive four arguments, dbi object, table name,
1098
column name and columninformation.
1099

            
1100
=head2 C<(experimental) method>
1101

            
1102
    $dbi->method(
1103
        update_or_insert => sub {
1104
            my $self = shift;
1105
            # do something
1106
        },
1107
        find_or_create   => sub {
1108
            my $self = shift;
1109
            # do something
1110
        }
1111
    );
1112

            
1113
Register method. These method is called from L<DBIx::Custom> object directory.
1114

            
1115
    $dbi->update_or_insert;
1116
    $dbi->find_or_create;
1117

            
1118
=head2 C<new>
1119

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

            
1123
Create a new L<DBIx::Custom> object.
1124

            
1125
=head2 C<(experimental) not_exists>
1126

            
1127
    my $not_exists = $dbi->not_exists;
1128

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1131
=head2 C<register_filter>
1132

            
1133
    $dbi->register_filter(%filters);
1134
    $dbi->register_filter(\%filters);
1135
    
1136
Register filter. Registered filters is available in the following attributes
1137
or arguments.
1138

            
1139
=over 4
1140

            
1141
=item *
1142

            
1143
C<filter> argument of C<insert()>, C<update()>,
1144
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1145
methods
1146

            
1147
=item *
1148

            
1149
C<execute()> method
1150

            
1151
=item *
1152

            
1153
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1154

            
1155
=item *
1156

            
1157
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1158

            
1159
=back
1160

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1163
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1164
        limit => sub {
1165
            ...;
1166
        }
1167
    );
1168

            
cleanup
Yuki Kimoto authored on 2011-01-25
1169
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1170

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

            
1173
    $dbi->rollback;
1174

            
1175
Rollback transaction.
1176
This is same as L<DBI>'s C<rollback>.
1177

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1178
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1179
    
cleanup
yuki-kimoto authored on 2010-08-05
1180
    my $result = $dbi->select(table    => $table,
1181
                              column   => [@column],
1182
                              where    => \%where,
1183
                              append   => $append,
1184
                              relation => \%relation,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1185
                              filter   => \%filter,
1186
                              query    => 1);
update document
yuki-kimoto authored on 2009-11-19
1187

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

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

            
1201
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1202
        table  => 'book',
cleanup
yuki-kimoto authored on 2010-08-09
1203
        column => ['title', 'author'],
1204
        where  => ['{= title} or {like author}',
1205
                   {title => '%Perl%', author => 'Ken'}]
1206
    );
1207

            
1208
First element is a string. it contains tags,
1209
such as "{= title} or {like author}".
1210
Second element is paramters.
1211

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1214
    $dbi->update(table  => $table, 
1215
                 param  => \%params,
1216
                 where  => \%where,
1217
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1218
                 filter => \%filter,
1219
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1220

            
cleanup
yuki-kimoto authored on 2010-10-17
1221
Execute update statement.
1222
C<update> method have C<table>, C<param>, C<where>, C<append>
1223
and C<filter> arguments.
1224
C<table> is a table name.
1225
C<param> is column-value pairs. this must be hash reference.
1226
C<where> is where clause. this must be hash reference.
1227
C<append> is a string added at the end of the SQL statement.
1228
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1229
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1230
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1231
This is overwrites C<default_bind_filter>.
1232
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1233

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

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
1236
    $dbi->table('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1237
        insert => sub { ... },
1238
        update => sub { ... }
1239
    );
1240
    
1241
    my $table = $dbi->table('book');
1242

            
1243
Create a L<DBIx::Custom::Table> object,
1244
or get a L<DBIx::Custom::Table> object.
1245

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1248
    $dbi->update_all(table  => $table, 
1249
                     param  => \%params,
1250
                     filter => \%filter,
1251
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1252

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

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

            
1260
    my $where = $dbi->where;
1261

            
1262
Create a new L<DBIx::Custom::Where> object.
1263

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

            
1266
    $dbi          = $dbi->cache_method(\&cache_method);
1267
    $cache_method = $dbi->cache_method
1268

            
1269
Method to set and get caches.
1270

            
cleanup
Yuki Kimoto authored on 2011-01-25
1271
=head1 Tags
1272

            
1273
The following tags is available.
1274

            
1275
=head2 C<?>
1276

            
1277
Placeholder tag.
1278

            
1279
    {? NAME}    ->   ?
1280

            
1281
=head2 C<=>
1282

            
1283
Equal tag.
1284

            
1285
    {= NAME}    ->   NAME = ?
1286

            
1287
=head2 C<E<lt>E<gt>>
1288

            
1289
Not equal tag.
1290

            
1291
    {<> NAME}   ->   NAME <> ?
1292

            
1293
=head2 C<E<lt>>
1294

            
1295
Lower than tag
1296

            
1297
    {< NAME}    ->   NAME < ?
1298

            
1299
=head2 C<E<gt>>
1300

            
1301
Greater than tag
1302

            
1303
    {> NAME}    ->   NAME > ?
1304

            
1305
=head2 C<E<gt>=>
1306

            
1307
Greater than or equal tag
1308

            
1309
    {>= NAME}   ->   NAME >= ?
1310

            
1311
=head2 C<E<lt>=>
1312

            
1313
Lower than or equal tag
1314

            
1315
    {<= NAME}   ->   NAME <= ?
1316

            
1317
=head2 C<like>
1318

            
1319
Like tag
1320

            
1321
    {like NAME}   ->   NAME like ?
1322

            
1323
=head2 C<in>
1324

            
1325
In tag.
1326

            
1327
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1328

            
1329
=head2 C<insert_param>
1330

            
1331
Insert parameter tag.
1332

            
1333
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1334

            
1335
=head2 C<update_param>
1336

            
1337
Updata parameter tag.
1338

            
1339
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1340

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

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

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

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

            
1350
C<< <kimoto.yuki at gmail.com> >>
1351

            
1352
L<http://github.com/yuki-kimoto/DBIx-Custom>
1353

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1354
=head1 AUTHOR
1355

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

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

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

            
1362
This program is free software; you can redistribute it and/or modify it
1363
under the same terms as Perl itself.
1364

            
1365
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1366

            
1367