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

            
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
3
our $VERSION = '0.1651';
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;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
17
use DBIx::Custom::Model;
cleanup
Yuki Kimoto authored on 2011-01-25
18
use DBIx::Custom::Tag;
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
19
use DBIx::Custom::Util;
update document
yuki-kimoto authored on 2010-05-27
20
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
21

            
fix tests
Yuki Kimoto authored on 2011-01-13
22
__PACKAGE__->attr(
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
23
    [qw/data_source dbh password user/],
fix tests
Yuki Kimoto authored on 2011-01-13
24
    cache => 1,
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
25
    dbi_option => sub { {} },
26
    default_dbi_option => sub {{
27
        RaiseError => 1,
28
        PrintError => 0,
29
        AutoCommit => 1
30
    }},
add models() attribute
Yuki Kimoto authored on 2011-02-21
31
    models => sub { {} },
cleanup
Yuki Kimoto authored on 2011-01-23
32
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
many changed
Yuki Kimoto authored on 2011-01-23
33
    result_class  => 'DBIx::Custom::Result',
update pod
Yuki Kimoto authored on 2011-02-07
34
    safety_column_name => sub { qr/^[\w\.]*$/ },
35
    stash => sub { {} }
many changed
Yuki Kimoto authored on 2011-01-23
36
);
37

            
38
__PACKAGE__->attr(
39
    cache_method => sub {
40
        sub {
41
            my $self = shift;
42
            
43
            $self->{_cached} ||= {};
44
            
45
            if (@_ > 1) {
46
                $self->{_cached}{$_[0]} = $_[1] 
47
            }
48
            else {
49
                return $self->{_cached}{$_[0]}
50
            }
51
        }
52
    }
53
);
54

            
55
__PACKAGE__->attr(
fix tests
Yuki Kimoto authored on 2011-01-13
56
    filters => sub {
57
        {
58
            encode_utf8 => sub { encode_utf8($_[0]) },
59
            decode_utf8 => sub { decode_utf8($_[0]) }
60
        }
many changed
Yuki Kimoto authored on 2011-01-23
61
    }
fix tests
Yuki Kimoto authored on 2011-01-13
62
);
cleanup
yuki-kimoto authored on 2010-10-17
63

            
added helper method
yuki-kimoto authored on 2010-10-17
64
our $AUTOLOAD;
65
sub AUTOLOAD {
66
    my $self = shift;
67

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

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
71
    # Method
72
    $self->{_methods} ||= {};
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
73
    if (my $method = $self->{_methods}->{$mname}) {
74
        return $self->$method(@_)
75
    }
76
    elsif ($self->dbh->can($mname)) {
77
        $self->dbh->$mname(@_);
78
    }
79
    else {
80
        croak qq/Can't locate object method "$mname" via "$package"/
81
    }
added helper method
yuki-kimoto authored on 2010-10-17
82
}
83

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

            
87
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
88
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
89
    $self->{filter}{out} ||= {};
90
    $self->{filter}{in} ||= {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
91
    $self->{filter}{end} ||= {};
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(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
95
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
96
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
many changed
Yuki Kimoto authored on 2011-01-23
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
        
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
103
        if (ref $column eq 'ARRAY') {
104
            foreach my $c (@$column) {
105
                push @cinfos, $c, $cinfos[$i + 1];
106
            }
107
            next;
108
        }
109
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
110
        # Filter info
111
        my $finfo = $cinfos[$i + 1] || {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
112
        croak "$usage (table: $table)" unless  ref $finfo eq 'HASH';
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
113
        foreach my $ftype (keys %$finfo) {
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
114
            croak "$usage (table: $table 2)" unless $ftype eq 'in' || $ftype eq 'out'
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
115
                             || $ftype eq 'end'; 
many changed
Yuki Kimoto authored on 2011-01-23
116
        }
117
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
118
        foreach my $way (qw/in out end/) {
119
            my $filter = $finfo->{$way};
cleanup
Yuki Kimoto authored on 2010-12-22
120
            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
121
            # State
122
            my $state = !exists $finfo->{$way} ? 'not_exists'
123
                      : !defined $filter        ? 'not_defined'
124
                      : ref $filter eq 'CODE'   ? 'code'
125
                      : 'name';
126
            
127
            next if $state eq 'not_exists';
128
            
129
            # Check filter
130
            croak qq{Filter "$filter" is not registered}
131
              if  $state eq 'name'
132
               && ! exists $self->filters->{$filter};
133
            
134
            # Filter
135
            my $f = $state eq 'not_defined' ? undef
136
                  : $state eq 'code'        ? $filter
137
                  : $self->filters->{$filter};
138
            $self->{filter}{$way}{$table}{$column} = $f;
139
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
140
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
many changed
Yuki Kimoto authored on 2011-01-23
141
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
142
    }
143
    
many changed
Yuki Kimoto authored on 2011-01-23
144
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
145
}
146

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
216
        # Cache query
217
        $self->cache_method->($self, $source,
218
                             {sql     => $query->sql, 
add table tag
Yuki Kimoto authored on 2011-02-09
219
                              columns => $query->columns,
220
                              tables  => $query->tables})
cleanup
yuki-kimoto authored on 2010-10-17
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 2011-02-09
232
    # Set filters
233
    $query->filters($self->filters);
234
    
cleanup
yuki-kimoto authored on 2010-10-17
235
    return $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
236
}
237

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-27
280
    # SQL stack
281
    my @sql;
282

            
283
    # Delete
284
    push @sql, "delete from $table $swhere";
285
    push @sql, $append if $append;
286
    
287
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
288
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
289
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
290
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
291
    return $query if $args{query};
292
    
packaging one directory
yuki-kimoto authored on 2009-11-16
293
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
294
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
295
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
296
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
297
    
298
    return $ret_val;
299
}
300

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

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
303
our %VALID_DELETE_AT_ARGS
304
  = map { $_ => 1 } qw/table where append filter query
305
                       primary_key param/;
306

            
307
sub delete_at {
308
    my ($self, %args) = @_;
309
    
310
    # Check arguments
311
    foreach my $name (keys %args) {
312
        croak qq{"$name" is invalid argument}
313
          unless $VALID_DELETE_AT_ARGS{$name};
314
    }
315
    
316
    # Primary key
317
    my $primary_keys = delete $args{primary_key};
318
    $primary_keys = [$primary_keys] unless ref $primary_keys;
319
    
320
    # Where clause
321
    my $where = {};
322
    if (exists $args{where}) {
323
        my $where_columns = delete $args{where};
324
        $where_columns = [$where_columns] unless ref $where_columns;
325
        
326
        for(my $i = 0; $i < @$primary_keys; $i ++) {
327
           $where->{$primary_keys->[$i]} = $where_columns->[$i];
328
        }
329
    }
330
    elsif (exists $args{param}) {
331
        my $param = delete $args{param};
332
        
333
        for(my $i = 0; $i < @$primary_keys; $i ++) {
334
           $where->{$primary_keys->[$i]}
335
             = delete $param->{$primary_keys->[$i]};
336
        }
337
    }
338
    
339
    return $self->delete(where => $where, %args);
340
}
341

            
added helper method
yuki-kimoto authored on 2010-10-17
342
sub DESTROY { }
343

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

            
cleanup
yuki-kimoto authored on 2010-10-17
346
sub execute{
347
    my ($self, $query, %args)  = @_;
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
348
    
349
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
350
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
351
        croak qq{"$name" is invalid argument}
cleanup
yuki-kimoto authored on 2010-10-17
352
          unless $VALID_EXECUTE_ARGS{$name};
refactoring delete and delet...
yuki-kimoto authored on 2010-04-28
353
    }
354
    
cleanup
yuki-kimoto authored on 2010-10-17
355
    my $params = $args{param} || {};
packaging one directory
yuki-kimoto authored on 2009-11-16
356
    
cleanup
yuki-kimoto authored on 2010-10-17
357
    # First argument is the soruce of SQL
358
    $query = $self->create_query($query)
359
      unless ref $query;
packaging one directory
yuki-kimoto authored on 2009-11-16
360
    
add table tag
Yuki Kimoto authored on 2011-02-09
361
    # Applied filter
cleanup
Yuki Kimoto authored on 2011-01-12
362
    my $filter = {};
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
363
    
add table tag
Yuki Kimoto authored on 2011-02-09
364
    my $tables = $query->tables;
365
    my $arg_tables = $args{table} || [];
366
    $arg_tables = [$arg_tables]
367
      unless ref $arg_tables eq 'ARRAY';
368
    push @$tables, @$arg_tables;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
369
    foreach my $table (@$tables) {
cleanup
Yuki Kimoto authored on 2011-01-12
370
        $filter = {
371
            %$filter,
372
            %{$self->{filter}{out}->{$table} || {}}
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
373
        }
374
    }
375
    
cleanup
Yuki Kimoto authored on 2011-01-12
376
    # Filter argument
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
377
    my $f = DBIx::Custom::Util::array_filter_to_hash($args{filter})
378
         || $query->filter || {};
cleanup
Yuki Kimoto authored on 2011-01-12
379
    foreach my $column (keys %$f) {
380
        my $fname = $f->{$column};
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
381
        if (!defined $fname) {
cleanup
Yuki Kimoto authored on 2011-01-12
382
            $f->{$column} = undef;
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
383
        }
384
        elsif (ref $fname ne 'CODE') {
many changed
Yuki Kimoto authored on 2011-01-23
385
          croak qq{Filter "$fname" is not registered"}
cleanup
Yuki Kimoto authored on 2010-12-21
386
            unless exists $self->filters->{$fname};
387
          
cleanup
Yuki Kimoto authored on 2011-01-12
388
          $f->{$column} = $self->filters->{$fname};
cleanup
Yuki Kimoto authored on 2010-12-21
389
        }
390
    }
cleanup
Yuki Kimoto authored on 2011-01-12
391
    $filter = {%$filter, %$f};
packaging one directory
yuki-kimoto authored on 2009-11-16
392
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
393
    # Bind
394
    my $bind = $self->_bind($params, $query->columns, $filter);
cleanup
yuki-kimoto authored on 2010-10-17
395
    
396
    # Execute
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
397
    my $sth = $query->sth;
cleanup
yuki-kimoto authored on 2010-10-17
398
    my $affected;
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
399
    eval {$affected = $sth->execute(@$bind)};
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
400
    $self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@;
cleanup
yuki-kimoto authored on 2010-10-17
401
    
402
    # Return resultset if select statement is executed
403
    if ($sth->{NUM_OF_FIELDS}) {
404
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
405
        # Result in and end filter
406
        my $in_filter  = {};
407
        my $end_filter = {};
cleanup
Yuki Kimoto authored on 2011-01-12
408
        foreach my $table (@$tables) {
409
            $in_filter = {
410
                %$in_filter,
411
                %{$self->{filter}{in}{$table} || {}}
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
412
            };
413
            $end_filter = {
414
                %$end_filter,
415
                %{$self->{filter}{end}{$table} || {}}
416
            };
cleanup
Yuki Kimoto authored on 2011-01-12
417
        }
418
        
419
        # Result
420
        my $result = $self->result_class->new(
cleanup
Yuki Kimoto authored on 2010-12-22
421
            sth            => $sth,
422
            filters        => $self->filters,
423
            filter_check   => $self->filter_check,
cleanup
Yuki Kimoto authored on 2011-01-12
424
            default_filter => $self->{default_in_filter},
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
425
            filter         => $in_filter || {},
426
            end_filter     => $end_filter || {}
cleanup
yuki-kimoto authored on 2010-10-17
427
        );
428

            
429
        return $result;
430
    }
431
    return $affected;
432
}
433

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

            
439
    # Check arguments
440
    foreach my $name (keys %args) {
441
        croak qq{"$name" is invalid argument}
442
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
443
    }
444
    
cleanup
yuki-kimoto authored on 2010-10-17
445
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
446
    my $table  = $args{table};
447
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
448
    my $param  = $args{param} || {};
449
    my $append = $args{append} || '';
450
    my $filter = $args{filter};
451
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
452
    # Columns
453
    my @columns;
454
    my $safety = $self->safety_column_name;
455
    foreach my $column (keys %$param) {
456
        croak qq{"$column" is not safety column name}
457
          unless $column =~ /$safety/;
458
        push @columns, $column;
459
    }
cleanup
yuki-kimoto authored on 2010-10-17
460
    
cleanup
Yuki Kimoto authored on 2011-01-27
461
    # SQL stack
462
    my @sql;
463
    
464
    # Insert
465
    push @sql, "insert into $table {insert_param ". join(' ', @columns) . '}';
466
    push @sql, $append if $append;
467
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
468
    # SQL
cleanup
Yuki Kimoto authored on 2011-01-27
469
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
470
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
471
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
472
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
473
    return $query if $args{query};
474
    
packaging one directory
yuki-kimoto authored on 2009-11-16
475
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
476
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
477
        $query,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
478
        param  => $param,
479
        filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
480
        table => $table
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
481
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
482
    
483
    return $ret_val;
484
}
485

            
pod fix
Yuki Kimoto authored on 2011-01-21
486
sub each_column {
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
487
    my ($self, $cb) = @_;
488
    
489
    # Iterate all tables
490
    my $sth_tables = $self->dbh->table_info;
491
    while (my $table_info = $sth_tables->fetchrow_hashref) {
492
        
493
        # Table
494
        my $table = $table_info->{TABLE_NAME};
495
        
496
        # Iterate all columns
497
        my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%');
498
        while (my $column_info = $sth_columns->fetchrow_hashref) {
499
            my $column = $column_info->{COLUMN_NAME};
removed experimental txn_sco...
Yuki Kimoto authored on 2011-01-24
500
            $self->$cb($table, $column, $column_info);
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
501
        }
502
    }
503
}
504

            
added dbi_options attribute
kimoto authored on 2010-12-20
505
sub new {
506
    my $self = shift->SUPER::new(@_);
507
    
508
    # Check attribute names
509
    my @attrs = keys %$self;
510
    foreach my $attr (@attrs) {
511
        croak qq{"$attr" is invalid attribute name}
512
          unless $self->can($attr);
513
    }
cleanup
Yuki Kimoto authored on 2011-01-25
514

            
515
    $self->register_tag(
516
        '?'     => \&DBIx::Custom::Tag::placeholder,
517
        '='     => \&DBIx::Custom::Tag::equal,
518
        '<>'    => \&DBIx::Custom::Tag::not_equal,
519
        '>'     => \&DBIx::Custom::Tag::greater_than,
520
        '<'     => \&DBIx::Custom::Tag::lower_than,
521
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
522
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
523
        'like'  => \&DBIx::Custom::Tag::like,
524
        'in'    => \&DBIx::Custom::Tag::in,
525
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
526
        'update_param' => \&DBIx::Custom::Tag::update_param
527
    );
added dbi_options attribute
kimoto authored on 2010-12-20
528
    
529
    return $self;
530
}
531

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

            
cleanup
yuki-kimoto authored on 2010-10-17
534
sub register_filter {
535
    my $invocant = shift;
536
    
537
    # Register filter
538
    my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_};
539
    $invocant->filters({%{$invocant->filters}, %$filters});
540
    
541
    return $invocant;
542
}
packaging one directory
yuki-kimoto authored on 2009-11-16
543

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

            
refactoring select
yuki-kimoto authored on 2010-04-28
546
our %VALID_SELECT_ARGS
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
547
  = map { $_ => 1 } qw/table column where append relation filter query selection/;
refactoring select
yuki-kimoto authored on 2010-04-28
548

            
packaging one directory
yuki-kimoto authored on 2009-11-16
549
sub select {
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
550
    my ($self, %args) = @_;
packaging one directory
yuki-kimoto authored on 2009-11-16
551
    
refactoring select
yuki-kimoto authored on 2010-04-28
552
    # Check arguments
select, insert, update, upda...
yuki-kimoto authored on 2010-06-14
553
    foreach my $name (keys %args) {
add tests
yuki-kimoto authored on 2010-08-10
554
        croak qq{"$name" is invalid argument}
refactoring select
yuki-kimoto authored on 2010-04-28
555
          unless $VALID_SELECT_ARGS{$name};
556
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
557
    
refactoring select
yuki-kimoto authored on 2010-04-28
558
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
559
    my $table = $args{table};
560
    my $tables = ref $table eq 'ARRAY' ? $table
561
               : defined $table ? [$table]
562
               : [];
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
563
    my $columns   = $args{column} || [];
select method column option ...
Yuki Kimoto authored on 2011-02-22
564
    $columns = [$columns] unless ref $columns;
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
565
    my $selection = $args{selection} || '';
566
    my $where     = $args{where} || {};
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
567
    my $relation  = $args{relation} || {};
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
568
    my $append    = $args{append};
569
    my $filter    = $args{filter};
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
570

            
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
571
    # Relation
572
    if (!$selection && keys %$relation) {
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
573
        foreach my $rcolumn (keys %$relation) {
574
            my $table1 = (split (/\./, $rcolumn))[0];
575
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
576
            
577
            my $table1_exists;
578
            my $table2_exists;
579
            foreach my $table (@$tables) {
580
                $table1_exists = 1 if $table eq $table1;
581
                $table2_exists = 1 if $table eq $table2;
582
            }
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
583
            unshift @$tables, $table1 unless $table1_exists;
584
            unshift @$tables, $table2 unless $table2_exists;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
585
        }
586
    }
packaging one directory
yuki-kimoto authored on 2009-11-16
587
    
cleanup
Yuki Kimoto authored on 2011-01-27
588
    # SQL stack
589
    my @sql;
590
    
591
    push @sql, 'select';
packaging one directory
yuki-kimoto authored on 2009-11-16
592
    
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
593
    if ($selection) {
594
        croak qq{Can't contain "where" clause in selection}
595
          if $selection =~ /\swhere\s/;
596
        push @sql, $selection;
597
    }
598
    else {
599
        # Column clause
600
        if (@$columns) {
601
            foreach my $column (@$columns) {
602
                push @sql, ($column, ',');
603
            }
604
            pop @sql if $sql[-1] eq ',';
605
        }
606
        else { push @sql, '*' }
607
        
608
        # Table
609
        croak qq{"table" option must be specified} unless @$tables;
610
        push @sql, 'from';
611
        foreach my $table (@$tables) {
612
            push @sql, ($table, ',');
packaging one directory
yuki-kimoto authored on 2009-11-16
613
        }
cleanup
Yuki Kimoto authored on 2011-01-27
614
        pop @sql if $sql[-1] eq ',';
packaging one directory
yuki-kimoto authored on 2009-11-16
615
    }
616
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
617
    # Where
618
    my $w;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
619
    if (ref $where eq 'HASH') {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
620
        my $clause = ['and'];
621
        push @$clause, "{= $_}" for keys %$where;
622
        $w = $self->where;
623
        $w->clause($clause);
624
        $w->param($where);
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
625
    }
626
    elsif (ref $where eq 'DBIx::Custom::Where') {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
627
        $w = $where;
628
        $where = $w->param;
packaging one directory
yuki-kimoto authored on 2009-11-16
629
    }
630
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
631
    croak qq{"where" must be hash reference or DBIx::Custom::Where object}
632
      unless ref $w eq 'DBIx::Custom::Where';
633
    
634
    # String where
635
    my $swhere = "$w";
cleanup
Yuki Kimoto authored on 2011-01-27
636
    push @sql, $swhere;
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
637
    
added commit method
yuki-kimoto authored on 2010-05-27
638
    # Relation
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
639
    if (!$selection && keys %$relation) {
cleanup
Yuki Kimoto authored on 2011-01-27
640
        push @sql, $swhere eq '' ? 'where' : 'and';
641
        foreach my $rcolumn (keys %$relation) {
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-21
642
            my $table1 = (split (/\./, $rcolumn))[0];
643
            my $table2 = (split (/\./, $relation->{$rcolumn}))[0];
644
            push @$tables, ($table1, $table2);
645
            
cleanup
Yuki Kimoto authored on 2011-01-27
646
            push @sql, ("$rcolumn = " . $relation->{$rcolumn},  'and');
packaging one directory
yuki-kimoto authored on 2009-11-16
647
        }
648
    }
cleanup
Yuki Kimoto authored on 2011-01-27
649
    pop @sql if $sql[-1] eq 'and';
added commit method
yuki-kimoto authored on 2010-05-27
650
    
cleanup
Yuki Kimoto authored on 2011-01-27
651
    # Append statement
652
    push @sql, $append if $append;
653
    
654
    # SQL
655
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
656
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
657
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
658
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
659
    return $query if $args{query};
660
    
packaging one directory
yuki-kimoto authored on 2009-11-16
661
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
662
    my $result = $self->execute(
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
663
        $query, param  => $where, filter => $filter,
664
        table => $tables);
packaging one directory
yuki-kimoto authored on 2009-11-16
665
    
666
    return $result;
667
}
668

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
669
our %VALID_SELECT_AT_ARGS
670
  = map { $_ => 1 } qw/table column where append relation filter query selection
671
                       param primary_key/;
672

            
673
sub select_at {
674
    my ($self, %args) = @_;
675
    
676
    # Check arguments
677
    foreach my $name (keys %args) {
678
        croak qq{"$name" is invalid argument}
679
          unless $VALID_SELECT_AT_ARGS{$name};
680
    }
681
    
682
    # Primary key
683
    my $primary_keys = delete $args{primary_key};
684
    $primary_keys = [$primary_keys] unless ref $primary_keys;
685
    
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
686
    # Table
687
    croak qq{"table" option must be specified} unless $args{table};
688
    my $table = ref $args{table} ? $args{table}->[-1] : $args{table};
689
    
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
690
    # Where clause
691
    my $where = {};
692
    if (exists $args{where}) {
693
        my $where_columns = delete $args{where};
694
        $where_columns = [$where_columns] unless ref $where_columns;
695
        
696
        for(my $i = 0; $i < @$primary_keys; $i ++) {
DBIx::Custom::Model select()...
Yuki Kimoto authored on 2011-02-22
697
           $where->{$table . '.' . $primary_keys->[$i]} = $where_columns->[$i];
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
698
        }
699
    }
700
    elsif (exists $args{param}) {
701
        my $param = delete $args{param};
702
        for(my $i = 0; $i < @$primary_keys; $i ++) {
703
           $where->{$primary_keys->[$i]}
704
             = delete $param->{$primary_keys->[$i]};
705
        }
706
    }
707
    
708
    return $self->select(where => $where, %args);
709
}
710

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
711
sub model {
712
    my ($self, $name, $model) = @_;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
713
    
714
    # Set
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
715
    if ($model) {
add models() attribute
Yuki Kimoto authored on 2011-02-21
716
        $self->models->{$name} = $model;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
717
        return $self;
718
    }
719
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
720
    # Check model existance
721
    croak qq{Model "$name" is not included}
add models() attribute
Yuki Kimoto authored on 2011-02-21
722
      unless $self->models->{$name};
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
723
    
724
    # Get
add models() attribute
Yuki Kimoto authored on 2011-02-21
725
    return $self->models->{$name};
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
726
}
727

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
728
sub include_model {
729
    my ($self, $name_space, $model_infos) = @_;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
730
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
731
    $name_space ||= '';
732
    unless ($model_infos) {
733
        # Load name space module
734
        croak qq{"$name_space" is invalid class name}
735
          if $name_space =~ /[^\w:]/;
736
        eval "use $name_space";
737
        croak qq{Name space module "$name_space.pm" is needed. $@} if $@;
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
738
        
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
739
        # Search model modules
740
        my $path = $INC{"$name_space.pm"};
741
        $path =~ s/\.pm$//;
742
        opendir my $dh, $path
743
          or croak qq{Can't open directory "$path": $!};
744
        $model_infos = [];
745
        while (my $module = readdir $dh) {
746
            push @$model_infos, $module
747
              if $module =~ s/\.pm$//;
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
748
        }
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
749
        
750
        close $dh;
751
    }
752
    
753
    foreach my $model_info (@$model_infos) {
754
        
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
755
        # Model class, name, table
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
756
        my $model_class;
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
757
        my $model_name;
758
        my $model_table;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
759
        if (ref $model_info eq 'HASH') {
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
760
            $model_class = $model_info->{class};
761
            $model_name  = $model_info->{name};
762
            $model_table = $model_info->{table};
763
            
764
            $model_name  ||= $model_class;
765
            $model_table ||= $model_name;
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
766
        }
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
767
        else { $model_class =$model_name = $model_table = $model_info }
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
768
        my $mclass = "${name_space}::$model_class";
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
769
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
770
        # Load
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
771
        croak qq{"$mclass" is invalid class name}
772
          if $mclass =~ /[^\w:]/;
773
        unless ($mclass->can('isa')) {
774
            eval "use $mclass";
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
775
            croak $@ if $@;
776
        }
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
777
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
778
        # Instantiate
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
779
        my $model = $mclass->new(dbi => $self);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
780
        $model->name($model_name) unless $model->name;
781
        $model->table($model_table) unless $model->table;
removed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-28
782
        
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
783
        # Set
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
784
        $self->model($model->name, $model);
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-24
785
        
786
        # Apply filter
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
787
        croak "${name_space}::$model_class filter must be array reference"
788
          unless ref $model->filter eq 'ARRAY';
789
        $self->apply_filter($model->table, @{$model->filter});
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
790
    }
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
791
    return $self;
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
792
}
793

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
794
sub setup_model {
795
    my $self = shift;
796
    
797
    $self->each_column(
798
        sub {
799
            my ($self, $table, $column, $column_info) = @_;
800
            
801
            if (my $model = $self->models->{$table}) {
802
                push @{$model->columns}, $column;
803
            }
804
        }
805
    );
add experimental DBIx::Custo...
Yuki Kimoto authored on 2011-02-22
806
    return $self;
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
807
}
808

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

            
813
sub update {
814
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
815
    
cleanup
yuki-kimoto authored on 2010-10-17
816
    # Check arguments
817
    foreach my $name (keys %args) {
818
        croak qq{"$name" is invalid argument}
819
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
820
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
821
    
cleanup
yuki-kimoto authored on 2010-10-17
822
    # Arguments
823
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
824
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
825
    my $param            = $args{param} || {};
826
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
827
    my $append           = $args{append} || '';
cleanup
yuki-kimoto authored on 2010-10-17
828
    my $filter           = $args{filter};
829
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
830
    
cleanup
yuki-kimoto authored on 2010-10-17
831
    # Update keys
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
832
    my @clumns = keys %$param;
833

            
834
    # Columns
835
    my @columns;
836
    my $safety = $self->safety_column_name;
837
    foreach my $column (keys %$param) {
838
        croak qq{"$column" is not safety column name}
839
          unless $column =~ /$safety/;
840
        push @columns, $column;
841
    }
842
        
cleanup
yuki-kimoto authored on 2010-10-17
843
    # Update clause
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
844
    my $update_clause = '{update_param ' . join(' ', @clumns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
845

            
846
    # Where
847
    my $w;
848
    if (ref $where eq 'HASH') {
849
        my $clause = ['and'];
850
        push @$clause, "{= $_}" for keys %$where;
851
        $w = $self->where;
852
        $w->clause($clause);
853
        $w->param($where);
854
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
855
    elsif (ref $where eq 'DBIx::Custom::Where') {
856
        $w = $where;
857
        $where = $w->param;
858
    }  
removed experimental registe...
yuki-kimoto authored on 2010-08-24
859
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
860
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
861
      unless ref $w eq 'DBIx::Custom::Where';
removed reconnect method
yuki-kimoto authored on 2010-05-28
862
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
863
    # String where
864
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
865
    
866
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
867
      if "$swhere" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
868
    
cleanup
Yuki Kimoto authored on 2011-01-27
869
    # SQL stack
870
    my @sql;
871
    
872
    # Update
873
    push @sql, "update $table $update_clause $swhere";
874
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
875
    
cleanup
yuki-kimoto authored on 2010-10-17
876
    # Rearrange parameters
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
877
    foreach my $wkey (keys %$where) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
878
        
cleanup
yuki-kimoto authored on 2010-10-17
879
        if (exists $param->{$wkey}) {
880
            $param->{$wkey} = [$param->{$wkey}]
881
              unless ref $param->{$wkey} eq 'ARRAY';
882
            
883
            push @{$param->{$wkey}}, $where->{$wkey};
884
        }
885
        else {
886
            $param->{$wkey} = $where->{$wkey};
887
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
888
    }
cleanup
yuki-kimoto authored on 2010-10-17
889
    
cleanup
Yuki Kimoto authored on 2011-01-27
890
    # SQL
891
    my $sql = join(' ', @sql);
892
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
893
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
894
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
895
    return $query if $args{query};
896
    
cleanup
yuki-kimoto authored on 2010-10-17
897
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
898
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
899
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
900
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
901
    
902
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
903
}
904

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

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
907
our %VALID_UPDATE_AT_ARGS
908
  = map { $_ => 1 } qw/table param
909
                       where append filter query
910
                       primary_key param/;
911

            
912
sub update_at {
913
    my ($self, %args) = @_;
914
    
915
    # Check arguments
916
    foreach my $name (keys %args) {
917
        croak qq{"$name" is invalid argument}
918
          unless $VALID_UPDATE_AT_ARGS{$name};
919
    }
920
    
921
    # Primary key
922
    my $primary_keys = delete $args{primary_key};
923
    $primary_keys = [$primary_keys] unless ref $primary_keys;
924
    
925
    # Where clause
926
    my $where = {};
927
    my $param = {};
928
    
929
    if (exists $args{where}) {
930
        my $where_columns = delete $args{where};
931
        $where_columns = [$where_columns] unless ref $where_columns;
932
        
933
        for(my $i = 0; $i < @$primary_keys; $i ++) {
934
           $where->{$primary_keys->[$i]} = $where_columns->[$i];
935
        }
936
    }
937
    elsif (exists $args{param}) {
938
        $param = delete $args{param};
939
        for(my $i = 0; $i < @$primary_keys; $i ++) {
940
           $where->{$primary_keys->[$i]}
941
             = delete $param->{$primary_keys->[$i]};
942
        }
943
    }
944
    
945
    return $self->update(where => $where, param => $param, %args);
946
}
947

            
cleanup
Yuki Kimoto authored on 2011-01-25
948
sub where {
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
949
    my $self = shift;
950

            
951
    return DBIx::Custom::Where->new(
952
        query_builder => $self->query_builder,
953
        safety_column_name => $self->safety_column_name
954
    );
cleanup
Yuki Kimoto authored on 2011-01-25
955
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
956

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
957
sub _bind {
cleanup
Yuki Kimoto authored on 2011-01-12
958
    my ($self, $params, $columns, $filter) = @_;
removed reconnect method
yuki-kimoto authored on 2010-05-28
959
    
cleanup
Yuki Kimoto authored on 2011-01-12
960
    # bind values
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
961
    my @bind;
add tests
yuki-kimoto authored on 2010-08-08
962
    
removed reconnect method
yuki-kimoto authored on 2010-05-28
963
    # Build bind values
964
    my $count = {};
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
965
    my $not_exists = {};
cleanup
Yuki Kimoto authored on 2011-01-12
966
    foreach my $column (@$columns) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
967
        
968
        # Value
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
969
        my $value;
970
        if(ref $params->{$column} eq 'ARRAY') {
971
            my $i = $count->{$column} || 0;
972
            $i += $not_exists->{$column} || 0;
973
            my $found;
974
            for (my $k = $i; $i < @{$params->{$column}}; $k++) {
975
                if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') {
976
                    $not_exists->{$column}++;
977
                }
978
                else  {
979
                    $value = $params->{$column}->[$k];
980
                    $found = 1;
981
                    last
982
                }
983
            }
984
            next unless $found;
985
        }
986
        else { $value = $params->{$column} }
removed reconnect method
yuki-kimoto authored on 2010-05-28
987
        
cleanup
Yuki Kimoto authored on 2011-01-12
988
        # Filter
989
        my $f = $filter->{$column} || $self->{default_out_filter} || '';
cleanup
kimoto.yuki@gmail.com authored on 2010-12-21
990
        
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
991
        push @bind, $f ? $f->($value) : $value;
removed reconnect method
yuki-kimoto authored on 2010-05-28
992
        
993
        # Count up 
994
        $count->{$column}++;
995
    }
996
    
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
997
    return \@bind;
removed reconnect method
yuki-kimoto authored on 2010-05-28
998
}
999

            
cleanup
yuki-kimoto authored on 2010-10-17
1000
sub _croak {
1001
    my ($self, $error, $append) = @_;
1002
    $append ||= "";
1003
    
1004
    # Verbose
1005
    if ($Carp::Verbose) { croak $error }
1006
    
1007
    # Not verbose
1008
    else {
1009
        
1010
        # Remove line and module infromation
1011
        my $at_pos = rindex($error, ' at ');
1012
        $error = substr($error, 0, $at_pos);
1013
        $error =~ s/\s+$//;
1014
        
1015
        croak "$error$append";
1016
    }
1017
}
1018

            
cleanup
Yuki Kimoto authored on 2011-01-25
1019
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
1020
__PACKAGE__->attr(
1021
    dbi_options => sub { {} },
1022
    filter_check  => 1
1023
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1024

            
cleanup
Yuki Kimoto authored on 2011-01-25
1025
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1026
sub default_bind_filter {
1027
    my $self = shift;
1028
    
1029
    if (@_) {
1030
        my $fname = $_[0];
1031
        
1032
        if (@_ && !$fname) {
1033
            $self->{default_out_filter} = undef;
1034
        }
1035
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1036
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1037
              unless exists $self->filters->{$fname};
1038
        
1039
            $self->{default_out_filter} = $self->filters->{$fname};
1040
        }
1041
        return $self;
1042
    }
1043
    
1044
    return $self->{default_out_filter};
1045
}
1046

            
cleanup
Yuki Kimoto authored on 2011-01-25
1047
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
1048
sub default_fetch_filter {
1049
    my $self = shift;
1050
    
1051
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
1052
        my $fname = $_[0];
1053

            
cleanup
Yuki Kimoto authored on 2011-01-12
1054
        if (@_ && !$fname) {
1055
            $self->{default_in_filter} = undef;
1056
        }
1057
        else {
many changed
Yuki Kimoto authored on 2011-01-23
1058
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
1059
              unless exists $self->filters->{$fname};
1060
        
1061
            $self->{default_in_filter} = $self->filters->{$fname};
1062
        }
1063
        
1064
        return $self;
1065
    }
1066
    
many changed
Yuki Kimoto authored on 2011-01-23
1067
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
1068
}
1069

            
cleanup
Yuki Kimoto authored on 2011-01-25
1070
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1071
sub register_tag_processor {
1072
    return shift->query_builder->register_tag_processor(@_);
1073
}
1074

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1077
=head1 NAME
1078

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

            
1081
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
1082

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1088
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1089
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1090
                 param  => {title => 'Perl', author => 'Ken'},
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1091
                 filter => [title => 'to_something']);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1092
    
1093
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1094
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1095
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
1096
                 where  => {id => 5},
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1097
                 filter => [title => 'to_something']);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1098
    
1099
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1100
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1101
                     param  => {title => 'Perl'},
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1102
                     filter => [title => 'to_something']);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1103
    
1104
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1105
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
1106
                 where  => {author => 'Ken'},
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1107
                 filter => [title => 'to_something']);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1108
    
1109
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1110
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
1111

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1112
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
1113
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1114
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
1115
        column => [qw/author title/],
1116
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
1117
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
1118
        append => 'order by id limit 5',
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1119
        filter => [title => 'to_something']
added commit method
yuki-kimoto authored on 2010-05-27
1120
    );
cleanup
yuki-kimoto authored on 2010-08-05
1121

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1122
    # Execute SQL
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1123
    $dbi->execute("select title from book");
removed register_format()
yuki-kimoto authored on 2010-05-26
1124
    
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1125
    # Execute SQL with hash binding and filtering
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
1126
    $dbi->execute("select id from book where {= author} and {like title}",
removed register_format()
yuki-kimoto authored on 2010-05-26
1127
                  param  => {author => 'ken', title => '%Perl%'},
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1128
                  filter => [title => 'to_something']);
removed reconnect method
yuki-kimoto authored on 2010-05-28
1129

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

            
1136
    # Get DBI object
1137
    my $dbh = $dbi->dbh;
1138

            
removed register_format()
yuki-kimoto authored on 2010-05-26
1139
    # Fetch
1140
    while (my $row = $result->fetch) {
1141
        # ...
1142
    }
1143
    
1144
    # Fetch hash
1145
    while (my $row = $result->fetch_hash) {
1146
        
1147
    }
1148
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
1149
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
1150

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

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

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

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

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

            
1173
=head1 GUIDE
1174

            
1175
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
1176

            
1177
=head1 EXAMPLES
1178

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1211
DBI options.
add default_dbi_option()
Yuki Kimoto authored on 2011-02-19
1212

            
1213
Each option specified can ovewrite C<default_dbi_option>.
1214

            
1215
C<connect()> method use this value to connect the database.
1216

            
1217

            
1218
=head2 C<default_dbi_option>
1219

            
1220
    my $default_dbi_option = $dbi->default_dbi_option;
1221
    $dbi            = $dbi->default_dbi_option($default_dbi_option);
1222

            
1223
DBI default options.
1224

            
1225
    RaiseError => 1,
1226
    PrintError => 0,
1227
    AutoCommit => 1,
1228

            
added dbi_options attribute
kimoto authored on 2010-12-20
1229
C<connect()> method use this value to connect the database.
1230

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

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

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

            
add models() attribute
Yuki Kimoto authored on 2011-02-21
1238
Filters
1239

            
1240
=head2 C<(experimental) models>
1241

            
1242
    my $models = $dbi->models;
1243
    $dbi       = $dbi->models(\%models);
1244

            
1245
Models
1246

            
cleanup
yuki-kimoto authored on 2010-10-17
1247
=head2 C<password>
1248

            
1249
    my $password = $dbi->password;
1250
    $dbi         = $dbi->password('lkj&le`@s');
1251

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

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

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-01-27
1272
=head2 C<(experimental) safety_column_name>
1273

            
1274
    my $safety_column_name = $self->safety_column_name;
1275
    $dbi                   = $self->safety_column_name($name);
1276

            
1277
Safety column name regex.
1278
Default is qr/^[\w\.]*$/
1279

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1282
    my $user = $dbi->user;
1283
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1284

            
cleanup
yuki-kimoto authored on 2010-10-17
1285
User name.
1286
C<connect()> method use this value to connect the database.
update pod
Yuki Kimoto authored on 2011-01-27
1287

            
cleanup
yuki-kimoto authored on 2010-10-17
1288
=head1 METHODS
added commit method
yuki-kimoto authored on 2010-05-27
1289

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1296
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1297
        $table,
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1298
        $column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1}
1299
        $column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2}
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1300
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1301
    );
1302

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
1310
    $result = $dbi->execute(
1311
        "select * from table1 where {= key1} and {= key2};",
1312
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1313
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
1314
    );
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1315

            
1316
You can use three name as column name.
1317

            
1318
    1. column        : author
1319
    2. table.column  : book.author
1320
    3. table__column : book__author
1321

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

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

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

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

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

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

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

            
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1347
    my $result = $dbi->execute($query,  param => $params, filter => \@filter);
1348
    my $result = $dbi->execute($source, param => $params, filter => \@filter);
update document
yuki-kimoto authored on 2009-11-19
1349

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

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

            
cleanup
yuki-kimoto authored on 2010-08-05
1357
    $dbi->delete(table  => $table,
1358
                 where  => \%where,
1359
                 append => $append,
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1360
                 filter => \@filter,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1361
                 query  => 1);
bind_filter argument is chan...
yuki-kimoto authored on 2009-11-19
1362

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

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

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

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

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1382
=head3 C<delete_at()>
1383

            
1384
To delete row by using primary key, use C<delete_at()>
1385

            
1386
    $dbi->delete_at(
1387
        table => 'book',
1388
        primary_key => ['id'],
1389
        where => ['123']
1390
    );
1391

            
1392
In this example, row which id column is 123 is deleted.
1393
NOTE that you must pass array reference as C<where>.
1394

            
1395
You can also write arguments like this.
1396

            
1397
    $dbi->delete_at(
1398
        table => 'book',
1399
        primary_key => ['id'],
1400
        param => {id => '123'}
1401
    );
1402

            
cleanup
yuki-kimoto authored on 2010-10-17
1403
=head2 C<insert>
1404

            
1405
    $dbi->insert(table  => $table, 
1406
                 param  => \%param,
1407
                 append => $append,
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1408
                 filter => \@filter,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1409
                 query  => 1);
cleanup
yuki-kimoto authored on 2010-10-17
1410

            
1411
Execute insert statement.
1412
C<insert> method have C<table>, C<param>, C<append>
1413
and C<filter> arguments.
1414
C<table> is a table name.
1415
C<param> is the pairs of column name value. this must be hash reference.
1416
C<append> is a string added at the end of the SQL statement.
1417
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1418
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1419
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1420
This is overwrites C<default_bind_filter>.
1421
Return value of C<insert()> is the count of affected rows.
1422

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
1425
    $dbi->each_column(
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1426
        sub {
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1427
            my ($self, $table, $column, $column_info) = @_;
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1428
            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1429
            my $type = $column_info->{TYPE_NAME};
pod fix
Yuki Kimoto authored on 2011-01-21
1430
            
1431
            if ($type eq 'DATE') {
1432
                # ...
1433
            }
added experimental iterate_a...
Yuki Kimoto authored on 2010-12-22
1434
        }
1435
    );
pod fix
Yuki Kimoto authored on 2011-01-21
1436
Get column informations from database.
1437
Argument is callback.
1438
You can do anything in callback.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1439
Callback receive four arguments, dbi object, table name,
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1440
column name and column information.
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1441

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1442
=head2 C<(experimental) include_model>
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1443

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1444
    $dbi->include_model(
1445
        'MyModel' => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1446
            'book', 'person', 'company'
1447
        ]
1448
    );
1449

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1450
Include models. First argument is name space.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1451
Second argument is array reference of class base names.
1452

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1453
If you don't specify second argument, All models under name space is
1454
included.
1455

            
1456
    $dbi->include_model('MyModel');
1457

            
1458
Note that in this case name spece module is needed.
1459

            
1460
    # MyModel.pm
1461
    package MyModel;
1462
    
1463
    use base 'DBIx::Custom::Model';
1464

            
1465
The following model is instantiated and included.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1466

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1467
    MyModel::book
1468
    MyModel::person
1469
    MyModel::company
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1470

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1471
You can get these instance by C<model()>.
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1472

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1473
    my $book_model = $dbi->model('book');
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1474

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1475
If you want to other name as model class,
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1476
you can do like this.
1477

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1478
    $dbi->include_model(
1479
        'MyModel' => [
removed experimental base_ta...
Yuki Kimoto authored on 2011-02-15
1480
            {'book' => 'Book'},
1481
            {'person' => 'Person'}
1482
        ]
1483
    );
1484

            
added experimental not_exist...
Yuki Kimoto authored on 2011-01-26
1485
=head2 C<(experimental) method>
1486

            
1487
    $dbi->method(
1488
        update_or_insert => sub {
1489
            my $self = shift;
1490
            # do something
1491
        },
1492
        find_or_create   => sub {
1493
            my $self = shift;
1494
            # do something
1495
        }
1496
    );
1497

            
1498
Register method. These method is called from L<DBIx::Custom> object directory.
1499

            
1500
    $dbi->update_or_insert;
1501
    $dbi->find_or_create;
1502

            
1503
=head2 C<new>
1504

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

            
1508
Create a new L<DBIx::Custom> object.
1509

            
1510
=head2 C<(experimental) not_exists>
1511

            
1512
    my $not_exists = $dbi->not_exists;
1513

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1516
=head2 C<register_filter>
1517

            
1518
    $dbi->register_filter(%filters);
1519
    $dbi->register_filter(\%filters);
1520
    
1521
Register filter. Registered filters is available in the following attributes
1522
or arguments.
1523

            
1524
=over 4
1525

            
1526
=item *
1527

            
1528
C<filter> argument of C<insert()>, C<update()>,
1529
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1530
methods
1531

            
1532
=item *
1533

            
1534
C<execute()> method
1535

            
1536
=item *
1537

            
1538
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1539

            
1540
=item *
1541

            
1542
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1543

            
1544
=back
1545

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

            
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
1548
    $dbi->register_tag(
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1549
        limit => sub {
1550
            ...;
1551
        }
1552
    );
1553

            
cleanup
Yuki Kimoto authored on 2011-01-25
1554
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1555

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

            
1558
    $dbi->rollback;
1559

            
1560
Rollback transaction.
1561
This is same as L<DBI>'s C<rollback>.
1562

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1563
=head2 C<select>
packaging one directory
yuki-kimoto authored on 2009-11-16
1564
    
select method column option ...
Yuki Kimoto authored on 2011-02-22
1565
    my $result = $dbi->select(
1566
        table     => $table,
1567
        column    => [@column],
1568
        where     => \%where,
1569
        append    => $append,
1570
        relation  => \%relation,
1571
        filter    => \%filter,
1572
        query     => 1,
1573
        selection => $selection
1574
    );
update document
yuki-kimoto authored on 2009-11-19
1575

            
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1576
Execute select statement.
cleanup
yuki-kimoto authored on 2010-08-09
1577
C<select> method have C<table>, C<column>, C<where>, C<append>,
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1578
C<relation> and C<filter> arguments.
1579
C<table> is a table name.
select method column option ...
Yuki Kimoto authored on 2011-02-22
1580
C<column> is column names. this is array reference or string.
cleanup
yuki-kimoto authored on 2010-08-09
1581
C<where> is where clause. this is normally hash reference.
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1582
C<append> is a string added at the end of the SQL statement.
1583
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1584
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1585
default to 0. This is experimental.
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1586
C<selection> is string of column name and tables. This is experimental
1587

            
1588
    selection => 'name, location.name as location_name ' .
1589
                 'from company inner join location'
update document
yuki-kimoto authored on 2009-11-19
1590

            
cleanup
yuki-kimoto authored on 2010-08-09
1591
First element is a string. it contains tags,
1592
such as "{= title} or {like author}".
1593
Second element is paramters.
1594

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1595
=head3 C<select_at()>
1596

            
1597
To select row by using primary key, use C<select_at()>.
1598

            
1599
    $dbi->select_at(table => 'book', primary_key => ['id'], where => ['123']);
1600

            
1601
In this example, row which id colunm is 123 is selected.
1602
NOTE that you must pass array reference as C<where>.
1603

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1606
    $dbi->update(table  => $table, 
1607
                 param  => \%params,
1608
                 where  => \%where,
1609
                 append => $append,
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1610
                 filter => \@filter,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1611
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1612

            
cleanup
yuki-kimoto authored on 2010-10-17
1613
Execute update statement.
1614
C<update> method have C<table>, C<param>, C<where>, C<append>
1615
and C<filter> arguments.
1616
C<table> is a table name.
1617
C<param> is column-value pairs. this must be hash reference.
1618
C<where> is where clause. this must be hash reference.
1619
C<append> is a string added at the end of the SQL statement.
1620
C<filter> is filters when parameter binding is executed.
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1621
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value.
1622
default to 0. This is experimental.
cleanup
yuki-kimoto authored on 2010-10-17
1623
This is overwrites C<default_bind_filter>.
1624
Return value of C<update()> is the count of affected rows.
removed reconnect method
yuki-kimoto authored on 2010-05-28
1625

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1626
=head2 C<(experimental) model>
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1627

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1628
    $dbi->model('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1629
        insert => sub { ... },
1630
        update => sub { ... }
1631
    );
1632
    
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1633
    my $model = $dbi->model('book');
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1634

            
add feture. all model class ...
Yuki Kimoto authored on 2011-02-18
1635
Set and get a L<DBIx::Custom::Model> object,
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1636

            
add experimental setup_model...
Yuki Kimoto authored on 2011-02-21
1637
=head2 C<(experimental) setup_model>
1638

            
1639
    $dbi->setup_model;
1640

            
1641
Setup all model objects.
1642
C<columns> and C<primary_key> is automatically set.
1643

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1646
    $dbi->update_all(table  => $table, 
1647
                     param  => \%params,
all filter can receive array...
Yuki Kimoto authored on 2011-02-25
1648
                     filter => \@filter,
cleanup
yuki-kimoto authored on 2010-10-17
1649
                     append => $append);
renamed build_query to creat...
yuki-kimoto authored on 2010-08-06
1650

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

            
add experimental update_at()...
Yuki Kimoto authored on 2011-02-21
1656
=head3 C<update_at()>
1657

            
1658
To update row by using primary key, use C<update_at()>
1659

            
1660
    $dbi->update_at(
1661
        table => 'book',
1662
        primary_key => ['id'],
1663
        where => ['123'],
1664
        param => {name => 'Ken'}
1665
    );
1666

            
1667
In this example, row which id column is 123 is updated.
1668
NOTE that you must pass array reference as C<where>.
1669
If C<param> contains primary key,
1670
the key and value is delete from C<param>.
1671

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

            
1674
    my $where = $dbi->where;
1675

            
1676
Create a new L<DBIx::Custom::Where> object.
1677

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

            
1680
    $dbi          = $dbi->cache_method(\&cache_method);
1681
    $cache_method = $dbi->cache_method
1682

            
1683
Method to set and get caches.
1684

            
cleanup
Yuki Kimoto authored on 2011-01-25
1685
=head1 Tags
1686

            
1687
The following tags is available.
1688

            
add experimental selection o...
Yuki Kimoto authored on 2011-02-09
1689
=head2 C<(experimental) table>
add table tag
Yuki Kimoto authored on 2011-02-09
1690

            
1691
Table tag
1692

            
1693
    {table TABLE}    ->    TABLE
1694

            
1695
This is used to teach what is applied table to C<execute()>.
1696

            
cleanup
Yuki Kimoto authored on 2011-01-25
1697
=head2 C<?>
1698

            
1699
Placeholder tag.
1700

            
1701
    {? NAME}    ->   ?
1702

            
1703
=head2 C<=>
1704

            
1705
Equal tag.
1706

            
1707
    {= NAME}    ->   NAME = ?
1708

            
1709
=head2 C<E<lt>E<gt>>
1710

            
1711
Not equal tag.
1712

            
1713
    {<> NAME}   ->   NAME <> ?
1714

            
1715
=head2 C<E<lt>>
1716

            
1717
Lower than tag
1718

            
1719
    {< NAME}    ->   NAME < ?
1720

            
1721
=head2 C<E<gt>>
1722

            
1723
Greater than tag
1724

            
1725
    {> NAME}    ->   NAME > ?
1726

            
1727
=head2 C<E<gt>=>
1728

            
1729
Greater than or equal tag
1730

            
1731
    {>= NAME}   ->   NAME >= ?
1732

            
1733
=head2 C<E<lt>=>
1734

            
1735
Lower than or equal tag
1736

            
1737
    {<= NAME}   ->   NAME <= ?
1738

            
1739
=head2 C<like>
1740

            
1741
Like tag
1742

            
1743
    {like NAME}   ->   NAME like ?
1744

            
1745
=head2 C<in>
1746

            
1747
In tag.
1748

            
1749
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1750

            
1751
=head2 C<insert_param>
1752

            
1753
Insert parameter tag.
1754

            
1755
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1756

            
1757
=head2 C<update_param>
1758

            
1759
Updata parameter tag.
1760

            
1761
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1762

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

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

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

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

            
1772
C<< <kimoto.yuki at gmail.com> >>
1773

            
1774
L<http://github.com/yuki-kimoto/DBIx-Custom>
1775

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1776
=head1 AUTHOR
1777

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

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

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

            
1784
This program is free software; you can redistribute it and/or modify it
1785
under the same terms as Perl itself.
1786

            
1787
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1788

            
1789