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

            
removed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-28
3
our $VERSION = '0.1642';
fixed DBIx::Custom::QueryBui...
yuki-kimoto authored on 2010-08-15
4

            
5
use 5.008001;
cleanup
yuki-kimoto authored on 2009-12-22
6
use strict;
7
use warnings;
8

            
remove run_transaction().
yuki-kimoto authored on 2010-01-30
9
use base 'Object::Simple';
many change
yuki-kimoto authored on 2010-02-11
10

            
packaging one directory
yuki-kimoto authored on 2009-11-16
11
use Carp 'croak';
12
use DBI;
13
use DBIx::Custom::Result;
cleanup
yuki-kimoto authored on 2010-02-11
14
use DBIx::Custom::Query;
cleanup
yuki-kimoto authored on 2010-08-05
15
use DBIx::Custom::QueryBuilder;
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
16
use DBIx::Custom::Where;
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
17
use DBIx::Custom::Table;
cleanup
Yuki Kimoto authored on 2011-01-25
18
use DBIx::Custom::Tag;
update document
yuki-kimoto authored on 2010-05-27
19
use Encode qw/encode_utf8 decode_utf8/;
packaging one directory
yuki-kimoto authored on 2009-11-16
20

            
fix tests
Yuki Kimoto authored on 2011-01-13
21
__PACKAGE__->attr(
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
22
    [qw/data_source dbh password user/],
fix tests
Yuki Kimoto authored on 2011-01-13
23
    cache => 1,
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
24
    dbi_option    => sub { {} },
cleanup
Yuki Kimoto authored on 2011-01-23
25
    query_builder => sub { DBIx::Custom::QueryBuilder->new },
many changed
Yuki Kimoto authored on 2011-01-23
26
    result_class  => 'DBIx::Custom::Result',
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
27
    base_table    => sub { DBIx::Custom::Table->new(dbi => shift) },
update pod
Yuki Kimoto authored on 2011-02-07
28
    safety_column_name => sub { qr/^[\w\.]*$/ },
29
    stash => sub { {} }
many changed
Yuki Kimoto authored on 2011-01-23
30
);
31

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

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

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

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

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

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

            
77
    # Initialize filters
cleanup
Yuki Kimoto authored on 2011-01-12
78
    $self->{filter} ||= {};
many changed
Yuki Kimoto authored on 2011-01-23
79
    $self->{filter}{out} ||= {};
80
    $self->{filter}{in} ||= {};
cleanup
Yuki Kimoto authored on 2010-12-22
81
    
many changed
Yuki Kimoto authored on 2011-01-23
82
    # Create filters
83
    my $usage = "Usage: \$dbi->apply_filter(" .
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
84
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " .
85
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)";
many changed
Yuki Kimoto authored on 2011-01-23
86

            
87
    for (my $i = 0; $i < @cinfos; $i += 2) {
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
88
        
many changed
Yuki Kimoto authored on 2011-01-23
89
        # Column
90
        my $column = $cinfos[$i];
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
91
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
92
        # Filter info
93
        my $finfo = $cinfos[$i + 1] || {};
94
        croak $usage unless  ref $finfo eq 'HASH';
95
        foreach my $ftype (keys %$finfo) {
96
            croak $usage unless $ftype eq 'in' || $ftype eq 'out'
97
                             || $ftype eq 'end'; 
many changed
Yuki Kimoto authored on 2011-01-23
98
        }
99
        
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
100
        foreach my $way (qw/in out end/) {
101
            my $filter = $finfo->{$way};
cleanup
Yuki Kimoto authored on 2010-12-22
102
            
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
103
            # State
104
            my $state = !exists $finfo->{$way} ? 'not_exists'
105
                      : !defined $filter        ? 'not_defined'
106
                      : ref $filter eq 'CODE'   ? 'code'
107
                      : 'name';
108
            
109
            next if $state eq 'not_exists';
110
            
111
            # Check filter
112
            croak qq{Filter "$filter" is not registered}
113
              if  $state eq 'name'
114
               && ! exists $self->filters->{$filter};
115
            
116
            # Filter
117
            my $f = $state eq 'not_defined' ? undef
118
                  : $state eq 'code'        ? $filter
119
                  : $self->filters->{$filter};
120
            $self->{filter}{$way}{$table}{$column} = $f;
121
            $self->{filter}{$way}{$table}{"$table.$column"} = $f;
122
            $self->{filter}{$way}{$table}{"${table}__$column"} = $f;
many changed
Yuki Kimoto authored on 2011-01-23
123
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
124
    }
125
    
many changed
Yuki Kimoto authored on 2011-01-23
126
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
127
}
128

            
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
129
sub method {
added helper method
yuki-kimoto authored on 2010-10-17
130
    my $self = shift;
131
    
132
    # Merge
renamed helper to method.
Yuki Kimoto authored on 2011-01-25
133
    my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_};
134
    $self->{_methods} = {%{$self->{_methods} || {}}, %$methods};
added helper method
yuki-kimoto authored on 2010-10-17
135
    
136
    return $self;
137
}
138

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
191
        # Create SQL object
192
        my $builder = $self->query_builder;
193
        
194
        # Create query
195
        $query = $builder->build_query($source);
removed register_format()
yuki-kimoto authored on 2010-05-26
196

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-27
257
    # SQL stack
258
    my @sql;
259

            
260
    # Delete
261
    push @sql, "delete from $table $swhere";
262
    push @sql, $append if $append;
263
    
264
    my $sql = join(' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
265
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
266
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
267
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
268
    return $query if $args{query};
269
    
packaging one directory
yuki-kimoto authored on 2009-11-16
270
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
271
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
272
        $query, param  => $where, filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
273
        table => $table);
packaging one directory
yuki-kimoto authored on 2009-11-16
274
    
275
    return $ret_val;
276
}
277

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

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

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

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

            
363
        return $result;
364
    }
365
    return $affected;
366
}
367

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

            
373
    # Check arguments
374
    foreach my $name (keys %args) {
375
        croak qq{"$name" is invalid argument}
376
          unless $VALID_INSERT_ARGS{$name};
packaging one directory
yuki-kimoto authored on 2009-11-16
377
    }
378
    
cleanup
yuki-kimoto authored on 2010-10-17
379
    # Arguments
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
380
    my $table  = $args{table};
381
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
382
    my $param  = $args{param} || {};
383
    my $append = $args{append} || '';
384
    my $filter = $args{filter};
385
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
386
    # Columns
387
    my @columns;
388
    my $safety = $self->safety_column_name;
389
    foreach my $column (keys %$param) {
390
        croak qq{"$column" is not safety column name}
391
          unless $column =~ /$safety/;
392
        push @columns, $column;
393
    }
cleanup
yuki-kimoto authored on 2010-10-17
394
    
cleanup
Yuki Kimoto authored on 2011-01-27
395
    # SQL stack
396
    my @sql;
397
    
398
    # Insert
399
    push @sql, "insert into $table {insert_param ". join(' ', @columns) . '}';
400
    push @sql, $append if $append;
401
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
402
    # SQL
cleanup
Yuki Kimoto authored on 2011-01-27
403
    my $sql = join (' ', @sql);
packaging one directory
yuki-kimoto authored on 2009-11-16
404
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
405
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
406
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
407
    return $query if $args{query};
408
    
packaging one directory
yuki-kimoto authored on 2009-11-16
409
    # Execute query
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
410
    my $ret_val = $self->execute(
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
411
        $query,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
412
        param  => $param,
413
        filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
414
        table => $table
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
415
    );
packaging one directory
yuki-kimoto authored on 2009-11-16
416
    
417
    return $ret_val;
418
}
419

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

            
added dbi_options attribute
kimoto authored on 2010-12-20
439
sub new {
440
    my $self = shift->SUPER::new(@_);
441
    
442
    # Check attribute names
443
    my @attrs = keys %$self;
444
    foreach my $attr (@attrs) {
445
        croak qq{"$attr" is invalid attribute name}
446
          unless $self->can($attr);
447
    }
cleanup
Yuki Kimoto authored on 2011-01-25
448

            
449
    $self->register_tag(
450
        '?'     => \&DBIx::Custom::Tag::placeholder,
451
        '='     => \&DBIx::Custom::Tag::equal,
452
        '<>'    => \&DBIx::Custom::Tag::not_equal,
453
        '>'     => \&DBIx::Custom::Tag::greater_than,
454
        '<'     => \&DBIx::Custom::Tag::lower_than,
455
        '>='    => \&DBIx::Custom::Tag::greater_than_equal,
456
        '<='    => \&DBIx::Custom::Tag::lower_than_equal,
457
        'like'  => \&DBIx::Custom::Tag::like,
458
        'in'    => \&DBIx::Custom::Tag::in,
459
        'insert_param' => \&DBIx::Custom::Tag::insert_param,
460
        'update_param' => \&DBIx::Custom::Tag::update_param
461
    );
added dbi_options attribute
kimoto authored on 2010-12-20
462
    
463
    return $self;
464
}
465

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

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

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

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

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

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
573
sub table {
574
    my $self = shift;
575
    my $name = shift;
576
    
577
    # Create table
578
    $self->{_tables} ||= {};
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
579
    unless (defined $self->{_tables}->{$name}) {
580
        # Base table
581
        my $base_table = $self->base_table;
582
        
583
        # Base methods
584
        my $bmethods = ref $base_table->{_methods} eq 'HASH'
585
                     ? $base_table->{_methods}
586
                     : {};
587
        
588
        # Copy Methods
589
        my $methods = {};
590
        $methods->{$_} = $bmethods->{$_} for keys %$bmethods;
removed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-28
591
        $methods->{"base_$_"} = $bmethods->{$_} for keys %$bmethods;
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
592
        
593
        # Create table
594
        my $table = $base_table->new(
595
            dbi      => $self,
596
            name     => $name,
597
        );
removed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-28
598
        $table->method($methods);
599
        
table object call dbi object...
Yuki Kimoto authored on 2011-01-25
600
        $self->{_tables}->{$name} = $table;
601
    }
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
602
    
603
    return $self->{_tables}{$name};
604
}
605

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

            
610
sub update {
611
    my ($self, %args) = @_;
version 0.0901
yuki-kimoto authored on 2009-12-17
612
    
cleanup
yuki-kimoto authored on 2010-10-17
613
    # Check arguments
614
    foreach my $name (keys %args) {
615
        croak qq{"$name" is invalid argument}
616
          unless $VALID_UPDATE_ARGS{$name};
removed reconnect method
yuki-kimoto authored on 2010-05-28
617
    }
added cache_method attribute
yuki-kimoto authored on 2010-06-25
618
    
cleanup
yuki-kimoto authored on 2010-10-17
619
    # Arguments
620
    my $table            = $args{table} || '';
added table not specified ex...
Yuki Kimoto authored on 2011-01-21
621
    croak qq{"table" option must be specified} unless $table;
cleanup
yuki-kimoto authored on 2010-10-17
622
    my $param            = $args{param} || {};
623
    my $where            = $args{where} || {};
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
624
    my $append           = $args{append} || '';
cleanup
yuki-kimoto authored on 2010-10-17
625
    my $filter           = $args{filter};
626
    my $allow_update_all = $args{allow_update_all};
version 0.0901
yuki-kimoto authored on 2009-12-17
627
    
cleanup
yuki-kimoto authored on 2010-10-17
628
    # Update keys
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
629
    my @clumns = keys %$param;
630

            
631
    # Columns
632
    my @columns;
633
    my $safety = $self->safety_column_name;
634
    foreach my $column (keys %$param) {
635
        croak qq{"$column" is not safety column name}
636
          unless $column =~ /$safety/;
637
        push @columns, $column;
638
    }
639
        
cleanup
yuki-kimoto authored on 2010-10-17
640
    # Update clause
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
641
    my $update_clause = '{update_param ' . join(' ', @clumns) . '}';
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
642

            
643
    # Where
644
    my $w;
645
    if (ref $where eq 'HASH') {
646
        my $clause = ['and'];
647
        push @$clause, "{= $_}" for keys %$where;
648
        $w = $self->where;
649
        $w->clause($clause);
650
        $w->param($where);
651
    }
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
652
    elsif (ref $where eq 'DBIx::Custom::Where') {
653
        $w = $where;
654
        $where = $w->param;
655
    }  
removed experimental registe...
yuki-kimoto authored on 2010-08-24
656
    
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
657
    croak qq{"where" must be hash refernce or DBIx::Custom::Where object}
658
      unless ref $w eq 'DBIx::Custom::Where';
removed reconnect method
yuki-kimoto authored on 2010-05-28
659
    
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
660
    # String where
661
    my $swhere = "$w";
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
662
    
663
    croak qq{"where" must be specified}
select() where can't receive...
Yuki Kimoto authored on 2011-01-27
664
      if "$swhere" eq '' && !$allow_update_all;
removed reconnect method
yuki-kimoto authored on 2010-05-28
665
    
cleanup
Yuki Kimoto authored on 2011-01-27
666
    # SQL stack
667
    my @sql;
668
    
669
    # Update
670
    push @sql, "update $table $update_clause $swhere";
671
    push @sql, $append if $append;
removed reconnect method
yuki-kimoto authored on 2010-05-28
672
    
cleanup
yuki-kimoto authored on 2010-10-17
673
    # Rearrange parameters
improved delete() and update...
Yuki Kimoto authored on 2011-01-26
674
    foreach my $wkey (keys %$where) {
removed reconnect method
yuki-kimoto authored on 2010-05-28
675
        
cleanup
yuki-kimoto authored on 2010-10-17
676
        if (exists $param->{$wkey}) {
677
            $param->{$wkey} = [$param->{$wkey}]
678
              unless ref $param->{$wkey} eq 'ARRAY';
679
            
680
            push @{$param->{$wkey}}, $where->{$wkey};
681
        }
682
        else {
683
            $param->{$wkey} = $where->{$wkey};
684
        }
removed reconnect method
yuki-kimoto authored on 2010-05-28
685
    }
cleanup
yuki-kimoto authored on 2010-10-17
686
    
cleanup
Yuki Kimoto authored on 2011-01-27
687
    # SQL
688
    my $sql = join(' ', @sql);
689
    
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
690
    # Create query
cleanup
Yuki Kimoto authored on 2011-01-27
691
    my $query = $self->create_query($sql);
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
692
    return $query if $args{query};
693
    
cleanup
yuki-kimoto authored on 2010-10-17
694
    # Execute query
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
695
    my $ret_val = $self->execute($query, param  => $param, 
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
696
                                 filter => $filter,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
697
                                 table => $table);
cleanup
yuki-kimoto authored on 2010-10-17
698
    
699
    return $ret_val;
removed reconnect method
yuki-kimoto authored on 2010-05-28
700
}
701

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

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

            
707
    return DBIx::Custom::Where->new(
708
        query_builder => $self->query_builder,
709
        safety_column_name => $self->safety_column_name
710
    );
cleanup
Yuki Kimoto authored on 2011-01-25
711
}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-18
712

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

            
cleanup
yuki-kimoto authored on 2010-10-17
756
sub _croak {
757
    my ($self, $error, $append) = @_;
758
    $append ||= "";
759
    
760
    # Verbose
761
    if ($Carp::Verbose) { croak $error }
762
    
763
    # Not verbose
764
    else {
765
        
766
        # Remove line and module infromation
767
        my $at_pos = rindex($error, ' at ');
768
        $error = substr($error, 0, $at_pos);
769
        $error =~ s/\s+$//;
770
        
771
        croak "$error$append";
772
    }
773
}
774

            
cleanup
Yuki Kimoto authored on 2011-01-25
775
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-23
776
__PACKAGE__->attr(
777
    dbi_options => sub { {} },
778
    filter_check  => 1
779
);
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
780

            
cleanup
Yuki Kimoto authored on 2011-01-25
781
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
782
sub default_bind_filter {
783
    my $self = shift;
784
    
785
    if (@_) {
786
        my $fname = $_[0];
787
        
788
        if (@_ && !$fname) {
789
            $self->{default_out_filter} = undef;
790
        }
791
        else {
many changed
Yuki Kimoto authored on 2011-01-23
792
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
793
              unless exists $self->filters->{$fname};
794
        
795
            $self->{default_out_filter} = $self->filters->{$fname};
796
        }
797
        return $self;
798
    }
799
    
800
    return $self->{default_out_filter};
801
}
802

            
cleanup
Yuki Kimoto authored on 2011-01-25
803
# DEPRECATED!
cleanup
Yuki Kimoto authored on 2011-01-12
804
sub default_fetch_filter {
805
    my $self = shift;
806
    
807
    if (@_) {
many changed
Yuki Kimoto authored on 2011-01-23
808
        my $fname = $_[0];
809

            
cleanup
Yuki Kimoto authored on 2011-01-12
810
        if (@_ && !$fname) {
811
            $self->{default_in_filter} = undef;
812
        }
813
        else {
many changed
Yuki Kimoto authored on 2011-01-23
814
            croak qq{Filter "$fname" is not registered}
cleanup
Yuki Kimoto authored on 2011-01-12
815
              unless exists $self->filters->{$fname};
816
        
817
            $self->{default_in_filter} = $self->filters->{$fname};
818
        }
819
        
820
        return $self;
821
    }
822
    
many changed
Yuki Kimoto authored on 2011-01-23
823
    return $self->{default_in_filter};
cleanup
Yuki Kimoto authored on 2011-01-12
824
}
825

            
cleanup
Yuki Kimoto authored on 2011-01-25
826
# DEPRECATED!
renamed DBIx::Custom::TagPro...
Yuki Kimoto authored on 2011-01-24
827
sub register_tag_processor {
828
    return shift->query_builder->register_tag_processor(@_);
829
}
830

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
833
=head1 NAME
834

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

            
837
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
838

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
844
    # Insert 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
845
    $dbi->insert(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
846
                 param  => {title => 'Perl', author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
847
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
848
    
849
    # Update 
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
850
    $dbi->update(table  => 'book', 
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
851
                 param  => {title => 'Perl', author => 'Ken'}, 
removed reconnect method
yuki-kimoto authored on 2010-05-28
852
                 where  => {id => 5},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
853
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
854
    
855
    # Update all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
856
    $dbi->update_all(table  => 'book',
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
857
                     param  => {title => 'Perl'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
858
                     filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
859
    
860
    # Delete
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
861
    $dbi->delete(table  => 'book',
removed reconnect method
yuki-kimoto authored on 2010-05-28
862
                 where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
863
                 filter => {title => 'to_something'});
removed reconnect method
yuki-kimoto authored on 2010-05-28
864
    
865
    # Delete all
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
866
    $dbi->delete_all(table => 'book');
cleanup
yuki-kimoto authored on 2010-08-05
867

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
868
    # Select
renamed fetch_rows to fetch_...
yuki-kimoto authored on 2010-05-01
869
    my $result = $dbi->select(
added insert, update, update...
Yuki Kimoto authored on 2011-01-04
870
        table  => 'book',
update document
yuki-kimoto authored on 2010-05-27
871
        column => [qw/author title/],
872
        where  => {author => 'Ken'},
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
873
        relation => {'book.id' => 'rental.book_id'},
updated document
yuki-kimoto authored on 2010-08-08
874
        append => 'order by id limit 5',
renamed dbi_options to dbi_o...
Yuki Kimoto authored on 2011-01-23
875
        filter => {title => 'to_something'}
added commit method
yuki-kimoto authored on 2010-05-27
876
    );
cleanup
yuki-kimoto authored on 2010-08-05
877

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

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

            
892
    # Get DBI object
893
    my $dbh = $dbi->dbh;
894

            
removed register_format()
yuki-kimoto authored on 2010-05-26
895
    # Fetch
896
    while (my $row = $result->fetch) {
897
        # ...
898
    }
899
    
900
    # Fetch hash
901
    while (my $row = $result->fetch_hash) {
902
        
903
    }
904
    
renamed update tag to update...
yuki-kimoto authored on 2010-08-09
905
=head1 DESCRIPTIONS
removed reconnect method
yuki-kimoto authored on 2010-05-28
906

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

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

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

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

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

            
929
=head1 GUIDE
930

            
931
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
932

            
933
=head1 EXAMPLES
934

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

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

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

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

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

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

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

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

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

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

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

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

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

            
967
DBI options.
968
C<connect()> method use this value to connect the database.
969

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
977
=head2 C<password>
978

            
979
    my $password = $dbi->password;
980
    $dbi         = $dbi->password('lkj&le`@s');
981

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

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

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

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

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

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

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

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

            
1004
    my $safety_column_name = $self->safety_column_name;
1005
    $dbi                   = $self->safety_column_name($name);
1006

            
1007
Safety column name regex.
1008
Default is qr/^[\w\.]*$/
1009

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1012
    my $user = $dbi->user;
1013
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1014

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1026
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1027
        $table,
fix bug : filter can't over...
Yuki Kimoto authored on 2011-02-09
1028
        $column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1}
1029
        $column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2}
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1030
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1031
    );
1032

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

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

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

            
1046
You can use three name as column name.
1047

            
1048
    1. column        : author
1049
    2. table.column  : book.author
1050
    3. table__column : book__author
1051

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1112
=head2 C<insert>
1113

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

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

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

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

            
1151
=head2 C<(experimental) method>
1152

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

            
1164
Register method. These method is called from L<DBIx::Custom> object directory.
1165

            
1166
    $dbi->update_or_insert;
1167
    $dbi->find_or_create;
1168

            
1169
=head2 C<new>
1170

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

            
1174
Create a new L<DBIx::Custom> object.
1175

            
1176
=head2 C<(experimental) not_exists>
1177

            
1178
    my $not_exists = $dbi->not_exists;
1179

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1182
=head2 C<register_filter>
1183

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

            
1190
=over 4
1191

            
1192
=item *
1193

            
1194
C<filter> argument of C<insert()>, C<update()>,
1195
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1196
methods
1197

            
1198
=item *
1199

            
1200
C<execute()> method
1201

            
1202
=item *
1203

            
1204
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1205

            
1206
=item *
1207

            
1208
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1209

            
1210
=back
1211

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1220
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1221

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

            
1224
    $dbi->rollback;
1225

            
1226
Rollback transaction.
1227
This is same as L<DBI>'s C<rollback>.
1228

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

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

            
cleanup
yuki-kimoto authored on 2010-08-09
1249
First element is a string. it contains tags,
1250
such as "{= title} or {like author}".
1251
Second element is paramters.
1252

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1255
    $dbi->update(table  => $table, 
1256
                 param  => \%params,
1257
                 where  => \%where,
1258
                 append => $append,
added experimental sugar met...
Yuki Kimoto authored on 2011-01-17
1259
                 filter => \%filter,
1260
                 query  => 1)
removed reconnect method
yuki-kimoto authored on 2010-05-28
1261

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

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

            
renamed experimental DBIx::C...
Yuki Kimoto authored on 2011-01-25
1277
    $dbi->table('book')->method(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1278
        insert => sub { ... },
1279
        update => sub { ... }
1280
    );
1281
    
1282
    my $table = $dbi->table('book');
1283

            
1284
Create a L<DBIx::Custom::Table> object,
1285
or get a L<DBIx::Custom::Table> object.
1286

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

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

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

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

            
1301
    my $where = $dbi->where;
1302

            
1303
Create a new L<DBIx::Custom::Where> object.
1304

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

            
1307
    $dbi          = $dbi->cache_method(\&cache_method);
1308
    $cache_method = $dbi->cache_method
1309

            
1310
Method to set and get caches.
1311

            
cleanup
Yuki Kimoto authored on 2011-01-25
1312
=head1 Tags
1313

            
1314
The following tags is available.
1315

            
1316
=head2 C<?>
1317

            
1318
Placeholder tag.
1319

            
1320
    {? NAME}    ->   ?
1321

            
1322
=head2 C<=>
1323

            
1324
Equal tag.
1325

            
1326
    {= NAME}    ->   NAME = ?
1327

            
1328
=head2 C<E<lt>E<gt>>
1329

            
1330
Not equal tag.
1331

            
1332
    {<> NAME}   ->   NAME <> ?
1333

            
1334
=head2 C<E<lt>>
1335

            
1336
Lower than tag
1337

            
1338
    {< NAME}    ->   NAME < ?
1339

            
1340
=head2 C<E<gt>>
1341

            
1342
Greater than tag
1343

            
1344
    {> NAME}    ->   NAME > ?
1345

            
1346
=head2 C<E<gt>=>
1347

            
1348
Greater than or equal tag
1349

            
1350
    {>= NAME}   ->   NAME >= ?
1351

            
1352
=head2 C<E<lt>=>
1353

            
1354
Lower than or equal tag
1355

            
1356
    {<= NAME}   ->   NAME <= ?
1357

            
1358
=head2 C<like>
1359

            
1360
Like tag
1361

            
1362
    {like NAME}   ->   NAME like ?
1363

            
1364
=head2 C<in>
1365

            
1366
In tag.
1367

            
1368
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1369

            
1370
=head2 C<insert_param>
1371

            
1372
Insert parameter tag.
1373

            
1374
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1375

            
1376
=head2 C<update_param>
1377

            
1378
Updata parameter tag.
1379

            
1380
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1381

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

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

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

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

            
1391
C<< <kimoto.yuki at gmail.com> >>
1392

            
1393
L<http://github.com/yuki-kimoto/DBIx-Custom>
1394

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1395
=head1 AUTHOR
1396

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

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

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

            
1403
This program is free software; you can redistribute it and/or modify it
1404
under the same terms as Perl itself.
1405

            
1406
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1407

            
1408