DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
1405 lines | 35.928kb
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(" .
84
                "TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1}, " .
85
                "COLUMN2, {in => INFILTER2, out => OUTFILTER2}, ...)";
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
        
many changed
Yuki Kimoto authored on 2011-01-23
92
        # Filter
93
        my $filter = $cinfos[$i + 1] || {};
94
        croak $usage unless  ref $filter eq 'HASH';
95
        foreach my $ftype (keys %$filter) {
96
            croak $usage unless $ftype eq 'in' || $ftype eq 'out'; 
97
        }
98
        my $in_filter = $filter->{in};
99
        my $out_filter = $filter->{out};
100
        
101
        # Out filter
102
        if (ref $out_filter eq 'CODE') {
103
            $self->{filter}{out}{$table}{$column}
104
              = $out_filter;
105
            $self->{filter}{out}{$table}{"$table.$column"}
106
              = $out_filter;
107
        }
108
        elsif (defined $out_filter) {
109
            croak qq{Filter "$out_filter" is not registered}
110
              unless exists $self->filters->{$out_filter};
cleanup
Yuki Kimoto authored on 2010-12-22
111
            
many changed
Yuki Kimoto authored on 2011-01-23
112
            $self->{filter}{out}{$table}{$column}
113
              = $self->filters->{$out_filter};
114
            $self->{filter}{out}{$table}{"$table.$column"}
115
              = $self->filters->{$out_filter};
cleanup
Yuki Kimoto authored on 2010-12-21
116
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
117
        
many changed
Yuki Kimoto authored on 2011-01-23
118
        # In filter
119
        if (ref $in_filter eq 'CODE') {
120
            $self->{filter}{in}{$table}{$column}
121
              = $in_filter;
122
            $self->{filter}{in}{$table}{"$table.$column"}
123
              = $in_filter;
124
        }
125
        elsif (defined $in_filter) {
126
            croak qq{Filter "$in_filter" is not registered}
127
              unless exists $self->filters->{$in_filter};
128
            $self->{filter}{in}{$table}{$column}
129
              = $self->filters->{$in_filter};
130
            $self->{filter}{in}{$table}{"$table.$column"}
131
              = $self->filters->{$in_filter};
132
        }
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
133
    }
134
    
many changed
Yuki Kimoto authored on 2011-01-23
135
    return $self;
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
136
}
137

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

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

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

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

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

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

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-27
266
    # SQL stack
267
    my @sql;
268

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
836
=head1 NAME
837

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

            
840
=head1 SYNOPSYS
cleanup
yuki-kimoto authored on 2010-08-05
841

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

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

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

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

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

            
895
    # Get DBI object
896
    my $dbh = $dbi->dbh;
897

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

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

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

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

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

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

            
932
=head1 GUIDE
933

            
934
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide
935

            
936
=head1 EXAMPLES
937

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

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

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

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

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

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

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

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

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

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

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

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

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

            
970
DBI options.
971
C<connect()> method use this value to connect the database.
972

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
980
=head2 C<password>
981

            
982
    my $password = $dbi->password;
983
    $dbi         = $dbi->password('lkj&le`@s');
984

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

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

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

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

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

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

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

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

            
1007
    my $safety_column_name = $self->safety_column_name;
1008
    $dbi                   = $self->safety_column_name($name);
1009

            
1010
Safety column name regex.
1011
Default is qr/^[\w\.]*$/
1012

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1015
    my $user = $dbi->user;
1016
    $dbi     = $dbi->user('Ken');
cleanup
yuki-kimoto authored on 2010-08-05
1017

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

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

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

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

            
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1029
    $dbi->apply_filter(
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1030
        $table,
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1031
        $column1 => {in => $infilter1, out => $outfilter1}
1032
        $column2 => {in => $infilter2, out => $outfilter2}
1033
        ...,
added auto_filter method
kimoto.yuki@gmail.com authored on 2010-12-21
1034
    );
1035

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

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

            
cleanup
Yuki Kimoto authored on 2010-12-21
1043
    $result = $dbi->execute(
1044
        "select * from table1 where {= key1} and {= key2};",
1045
         param => {key1 => 1, key2 => 2},
renamed auto_filter to apply...
Yuki Kimoto authored on 2011-01-12
1046
         table => ['table1']
cleanup
Yuki Kimoto authored on 2010-12-21
1047
    );
1048
    
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
1049
=head2 C<connect>
packaging one directory
yuki-kimoto authored on 2009-11-16
1050

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1109
=head2 C<insert>
1110

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

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

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

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

            
1148
=head2 C<(experimental) method>
1149

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

            
1161
Register method. These method is called from L<DBIx::Custom> object directory.
1162

            
1163
    $dbi->update_or_insert;
1164
    $dbi->find_or_create;
1165

            
1166
=head2 C<new>
1167

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

            
1171
Create a new L<DBIx::Custom> object.
1172

            
1173
=head2 C<(experimental) not_exists>
1174

            
1175
    my $not_exists = $dbi->not_exists;
1176

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

            
cleanup
yuki-kimoto authored on 2010-10-17
1179
=head2 C<register_filter>
1180

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

            
1187
=over 4
1188

            
1189
=item *
1190

            
1191
C<filter> argument of C<insert()>, C<update()>,
1192
C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1193
methods
1194

            
1195
=item *
1196

            
1197
C<execute()> method
1198

            
1199
=item *
1200

            
1201
C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1202

            
1203
=item *
1204

            
1205
C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1206

            
1207
=back
1208

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

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

            
cleanup
Yuki Kimoto authored on 2011-01-25
1217
Register tag.
added register_tag_processor
Yuki Kimoto authored on 2011-01-20
1218

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

            
1221
    $dbi->rollback;
1222

            
1223
Rollback transaction.
1224
This is same as L<DBI>'s C<rollback>.
1225

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1307
Method to set and get caches.
1308

            
cleanup
Yuki Kimoto authored on 2011-01-25
1309
=head1 Tags
1310

            
1311
The following tags is available.
1312

            
1313
=head2 C<?>
1314

            
1315
Placeholder tag.
1316

            
1317
    {? NAME}    ->   ?
1318

            
1319
=head2 C<=>
1320

            
1321
Equal tag.
1322

            
1323
    {= NAME}    ->   NAME = ?
1324

            
1325
=head2 C<E<lt>E<gt>>
1326

            
1327
Not equal tag.
1328

            
1329
    {<> NAME}   ->   NAME <> ?
1330

            
1331
=head2 C<E<lt>>
1332

            
1333
Lower than tag
1334

            
1335
    {< NAME}    ->   NAME < ?
1336

            
1337
=head2 C<E<gt>>
1338

            
1339
Greater than tag
1340

            
1341
    {> NAME}    ->   NAME > ?
1342

            
1343
=head2 C<E<gt>=>
1344

            
1345
Greater than or equal tag
1346

            
1347
    {>= NAME}   ->   NAME >= ?
1348

            
1349
=head2 C<E<lt>=>
1350

            
1351
Lower than or equal tag
1352

            
1353
    {<= NAME}   ->   NAME <= ?
1354

            
1355
=head2 C<like>
1356

            
1357
Like tag
1358

            
1359
    {like NAME}   ->   NAME like ?
1360

            
1361
=head2 C<in>
1362

            
1363
In tag.
1364

            
1365
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
1366

            
1367
=head2 C<insert_param>
1368

            
1369
Insert parameter tag.
1370

            
1371
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
1372

            
1373
=head2 C<update_param>
1374

            
1375
Updata parameter tag.
1376

            
1377
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
1378

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

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

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

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

            
1388
C<< <kimoto.yuki at gmail.com> >>
1389

            
1390
L<http://github.com/yuki-kimoto/DBIx-Custom>
1391

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
1392
=head1 AUTHOR
1393

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

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

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

            
1400
This program is free software; you can redistribute it and/or modify it
1401
under the same terms as Perl itself.
1402

            
1403
=cut
added cache_method attribute
yuki-kimoto authored on 2010-06-25
1404

            
1405