DBIx-Custom / lib / DBIx / Custom.pm /
Newer Older
1404 lines | 35.903kb
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) },
28
    safety_column_name => sub { qr/^[\w\.]*$/ }
many changed
Yuki Kimoto authored on 2011-01-23
29
);
30

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
931
=head1 GUIDE
932

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

            
935
=head1 EXAMPLES
936

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1147
=head2 C<(experimental) method>
1148

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

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

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

            
1165
=head2 C<new>
1166

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

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

            
1172
=head2 C<(experimental) not_exists>
1173

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

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

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

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

            
1186
=over 4
1187

            
1188
=item *
1189

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

            
1194
=item *
1195

            
1196
C<execute()> method
1197

            
1198
=item *
1199

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

            
1202
=item *
1203

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

            
1206
=back
1207

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

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

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

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

            
1220
    $dbi->rollback;
1221

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1306
Method to set and get caches.
1307

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

            
1310
The following tags is available.
1311

            
1312
=head2 C<?>
1313

            
1314
Placeholder tag.
1315

            
1316
    {? NAME}    ->   ?
1317

            
1318
=head2 C<=>
1319

            
1320
Equal tag.
1321

            
1322
    {= NAME}    ->   NAME = ?
1323

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

            
1326
Not equal tag.
1327

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

            
1330
=head2 C<E<lt>>
1331

            
1332
Lower than tag
1333

            
1334
    {< NAME}    ->   NAME < ?
1335

            
1336
=head2 C<E<gt>>
1337

            
1338
Greater than tag
1339

            
1340
    {> NAME}    ->   NAME > ?
1341

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

            
1344
Greater than or equal tag
1345

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

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

            
1350
Lower than or equal tag
1351

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

            
1354
=head2 C<like>
1355

            
1356
Like tag
1357

            
1358
    {like NAME}   ->   NAME like ?
1359

            
1360
=head2 C<in>
1361

            
1362
In tag.
1363

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

            
1366
=head2 C<insert_param>
1367

            
1368
Insert parameter tag.
1369

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

            
1372
=head2 C<update_param>
1373

            
1374
Updata parameter tag.
1375

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

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

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

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

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

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

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

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

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

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

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

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

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

            
1404