cleanup
|
1 |
package DBIx::Custom; |
2 | ||
add models() attribute
|
3 |
our $VERSION = '0.1648'; |
fixed DBIx::Custom::QueryBui...
|
4 | |
5 |
use 5.008001; |
|
cleanup
|
6 |
use strict; |
7 |
use warnings; |
|
8 | ||
remove run_transaction().
|
9 |
use base 'Object::Simple'; |
many change
|
10 | |
packaging one directory
|
11 |
use Carp 'croak'; |
12 |
use DBI; |
|
13 |
use DBIx::Custom::Result; |
|
cleanup
|
14 |
use DBIx::Custom::Query; |
cleanup
|
15 |
use DBIx::Custom::QueryBuilder; |
added experimental DBIx::Cus...
|
16 |
use DBIx::Custom::Where; |
add feture. all model class ...
|
17 |
use DBIx::Custom::Model; |
cleanup
|
18 |
use DBIx::Custom::Tag; |
update document
|
19 |
use Encode qw/encode_utf8 decode_utf8/; |
packaging one directory
|
20 | |
fix tests
|
21 |
__PACKAGE__->attr( |
added experimental DBIx::Cus...
|
22 |
[qw/data_source dbh password user/], |
fix tests
|
23 |
cache => 1, |
add default_dbi_option()
|
24 |
dbi_option => sub { {} }, |
25 |
default_dbi_option => sub {{ |
|
26 |
RaiseError => 1, |
|
27 |
PrintError => 0, |
|
28 |
AutoCommit => 1 |
|
29 |
}}, |
|
add models() attribute
|
30 |
models => sub { {} }, |
cleanup
|
31 |
query_builder => sub { DBIx::Custom::QueryBuilder->new }, |
many changed
|
32 |
result_class => 'DBIx::Custom::Result', |
update pod
|
33 |
safety_column_name => sub { qr/^[\w\.]*$/ }, |
34 |
stash => sub { {} } |
|
many changed
|
35 |
); |
36 | ||
37 |
__PACKAGE__->attr( |
|
38 |
cache_method => sub { |
|
39 |
sub { |
|
40 |
my $self = shift; |
|
41 |
|
|
42 |
$self->{_cached} ||= {}; |
|
43 |
|
|
44 |
if (@_ > 1) { |
|
45 |
$self->{_cached}{$_[0]} = $_[1] |
|
46 |
} |
|
47 |
else { |
|
48 |
return $self->{_cached}{$_[0]} |
|
49 |
} |
|
50 |
} |
|
51 |
} |
|
52 |
); |
|
53 | ||
54 |
__PACKAGE__->attr( |
|
fix tests
|
55 |
filters => sub { |
56 |
{ |
|
57 |
encode_utf8 => sub { encode_utf8($_[0]) }, |
|
58 |
decode_utf8 => sub { decode_utf8($_[0]) } |
|
59 |
} |
|
many changed
|
60 |
} |
fix tests
|
61 |
); |
cleanup
|
62 | |
added helper method
|
63 |
our $AUTOLOAD; |
64 |
sub AUTOLOAD { |
|
65 |
my $self = shift; |
|
66 | ||
renamed helper to method.
|
67 |
# Method name |
68 |
my ($package, $mname) = $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; |
|
added helper method
|
69 | |
renamed helper to method.
|
70 |
# Method |
71 |
$self->{_methods} ||= {}; |
|
add feture. all model class ...
|
72 |
if (my $method = $self->{_methods}->{$mname}) { |
73 |
return $self->$method(@_) |
|
74 |
} |
|
75 |
elsif ($self->dbh->can($mname)) { |
|
76 |
$self->dbh->$mname(@_); |
|
77 |
} |
|
78 |
else { |
|
79 |
croak qq/Can't locate object method "$mname" via "$package"/ |
|
80 |
} |
|
added helper method
|
81 |
} |
82 | ||
renamed auto_filter to apply...
|
83 |
sub apply_filter { |
many changed
|
84 |
my ($self, $table, @cinfos) = @_; |
85 | ||
86 |
# Initialize filters |
|
cleanup
|
87 |
$self->{filter} ||= {}; |
many changed
|
88 |
$self->{filter}{out} ||= {}; |
89 |
$self->{filter}{in} ||= {}; |
|
cleanup
|
90 |
|
many changed
|
91 |
# Create filters |
92 |
my $usage = "Usage: \$dbi->apply_filter(" . |
|
fix bug : filter can't over...
|
93 |
"TABLE, COLUMN1, {in => INFILTER1, out => OUTFILTER1, end => ENDFILTER1}, " . |
94 |
"COLUMN2, {in => INFILTER2, out => OUTFILTER2, end => ENDFILTER2}, ...)"; |
|
many changed
|
95 | |
96 |
for (my $i = 0; $i < @cinfos; $i += 2) { |
|
added auto_filter method
|
97 |
|
many changed
|
98 |
# Column |
99 |
my $column = $cinfos[$i]; |
|
added auto_filter method
|
100 |
|
fix bug : filter can't over...
|
101 |
# Filter info |
102 |
my $finfo = $cinfos[$i + 1] || {}; |
|
103 |
croak $usage unless ref $finfo eq 'HASH'; |
|
104 |
foreach my $ftype (keys %$finfo) { |
|
105 |
croak $usage unless $ftype eq 'in' || $ftype eq 'out' |
|
106 |
|| $ftype eq 'end'; |
|
many changed
|
107 |
} |
108 |
|
|
fix bug : filter can't over...
|
109 |
foreach my $way (qw/in out end/) { |
110 |
my $filter = $finfo->{$way}; |
|
cleanup
|
111 |
|
fix bug : filter can't over...
|
112 |
# State |
113 |
my $state = !exists $finfo->{$way} ? 'not_exists' |
|
114 |
: !defined $filter ? 'not_defined' |
|
115 |
: ref $filter eq 'CODE' ? 'code' |
|
116 |
: 'name'; |
|
117 |
|
|
118 |
next if $state eq 'not_exists'; |
|
119 |
|
|
120 |
# Check filter |
|
121 |
croak qq{Filter "$filter" is not registered} |
|
122 |
if $state eq 'name' |
|
123 |
&& ! exists $self->filters->{$filter}; |
|
124 |
|
|
125 |
# Filter |
|
126 |
my $f = $state eq 'not_defined' ? undef |
|
127 |
: $state eq 'code' ? $filter |
|
128 |
: $self->filters->{$filter}; |
|
129 |
$self->{filter}{$way}{$table}{$column} = $f; |
|
130 |
$self->{filter}{$way}{$table}{"$table.$column"} = $f; |
|
131 |
$self->{filter}{$way}{$table}{"${table}__$column"} = $f; |
|
many changed
|
132 |
} |
added auto_filter method
|
133 |
} |
134 |
|
|
many changed
|
135 |
return $self; |
added auto_filter method
|
136 |
} |
137 | ||
renamed helper to method.
|
138 |
sub method { |
added helper method
|
139 |
my $self = shift; |
140 |
|
|
141 |
# Merge |
|
renamed helper to method.
|
142 |
my $methods = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
143 |
$self->{_methods} = {%{$self->{_methods} || {}}, %$methods}; |
|
added helper method
|
144 |
|
145 |
return $self; |
|
146 |
} |
|
147 | ||
packaging one directory
|
148 |
sub connect { |
cleanup
|
149 |
my $self = ref $_[0] ? shift : shift->new(@_);; |
removed register_format()
|
150 |
|
many changed
|
151 |
# Attributes |
packaging one directory
|
152 |
my $data_source = $self->data_source; |
many changed
|
153 |
croak qq{"data_source" must be specified to connect()"} |
check arguments of connect m...
|
154 |
unless $data_source; |
packaging one directory
|
155 |
my $user = $self->user; |
156 |
my $password = $self->password; |
|
renamed dbi_options to dbi_o...
|
157 |
my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}}; |
added dbi_options attribute
|
158 |
|
update document
|
159 |
# Connect |
select, insert, update, upda...
|
160 |
my $dbh = eval {DBI->connect( |
packaging one directory
|
161 |
$data_source, |
162 |
$user, |
|
163 |
$password, |
|
164 |
{ |
|
add default_dbi_option()
|
165 |
%{$self->default_dbi_option}, |
renamed dbi_options to dbi_o...
|
166 |
%$dbi_option |
packaging one directory
|
167 |
} |
168 |
)}; |
|
169 |
|
|
update document
|
170 |
# Connect error |
packaging one directory
|
171 |
croak $@ if $@; |
172 |
|
|
update document
|
173 |
# Database handle |
packaging one directory
|
174 |
$self->dbh($dbh); |
update document
|
175 |
|
packaging one directory
|
176 |
return $self; |
177 |
} |
|
178 | ||
cleanup
|
179 |
sub create_query { |
180 |
my ($self, $source) = @_; |
|
update document
|
181 |
|
cleanup
|
182 |
# Cache |
183 |
my $cache = $self->cache; |
|
update document
|
184 |
|
cleanup
|
185 |
# Create query |
186 |
my $query; |
|
187 |
if ($cache) { |
|
188 |
|
|
189 |
# Get query |
|
190 |
my $q = $self->cache_method->($self, $source); |
|
191 |
|
|
192 |
# Create query |
|
add table tag
|
193 |
if ($q) { |
194 |
$query = DBIx::Custom::Query->new($q); |
|
195 |
$query->filters($self->filters); |
|
196 |
} |
|
cleanup
|
197 |
} |
198 |
|
|
199 |
unless ($query) { |
|
cleanup insert
|
200 | |
cleanup
|
201 |
# Create SQL object |
202 |
my $builder = $self->query_builder; |
|
203 |
|
|
204 |
# Create query |
|
205 |
$query = $builder->build_query($source); |
|
removed register_format()
|
206 | |
cleanup
|
207 |
# Cache query |
208 |
$self->cache_method->($self, $source, |
|
209 |
{sql => $query->sql, |
|
add table tag
|
210 |
columns => $query->columns, |
211 |
tables => $query->tables}) |
|
cleanup
|
212 |
if $cache; |
cleanup insert
|
213 |
} |
214 |
|
|
cleanup
|
215 |
# Prepare statement handle |
216 |
my $sth; |
|
217 |
eval { $sth = $self->dbh->prepare($query->{sql})}; |
|
renamed DBIx::Custom::TagPro...
|
218 |
$self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@; |
packaging one directory
|
219 |
|
cleanup
|
220 |
# Set statement handle |
221 |
$query->sth($sth); |
|
packaging one directory
|
222 |
|
cleanup
|
223 |
# Set filters |
224 |
$query->filters($self->filters); |
|
225 |
|
|
cleanup
|
226 |
return $query; |
packaging one directory
|
227 |
} |
228 | ||
cleanup
|
229 |
our %VALID_DELETE_ARGS |
added experimental sugar met...
|
230 |
= map { $_ => 1 } qw/table where append filter allow_delete_all query/; |
cleanup update and update_al...
|
231 | |
cleanup
|
232 |
sub delete { |
select, insert, update, upda...
|
233 |
my ($self, %args) = @_; |
cleanup update and update_al...
|
234 |
|
235 |
# Check arguments |
|
select, insert, update, upda...
|
236 |
foreach my $name (keys %args) { |
add tests
|
237 |
croak qq{"$name" is invalid argument} |
cleanup
|
238 |
unless $VALID_DELETE_ARGS{$name}; |
cleanup update and update_al...
|
239 |
} |
240 |
|
|
241 |
# Arguments |
|
select, insert, update, upda...
|
242 |
my $table = $args{table} || ''; |
added table not specified ex...
|
243 |
croak qq{"table" option must be specified} unless $table; |
select, insert, update, upda...
|
244 |
my $where = $args{where} || {}; |
select() where can't receive...
|
245 |
my $append = $args{append}; |
select, insert, update, upda...
|
246 |
my $filter = $args{filter}; |
cleanup
|
247 |
my $allow_delete_all = $args{allow_delete_all}; |
added auto_filter method
|
248 | |
make delete() using where ob...
|
249 |
# Where |
250 |
my $w; |
|
251 |
if (ref $where eq 'HASH') { |
|
252 |
my $clause = ['and']; |
|
253 |
push @$clause, "{= $_}" for keys %$where; |
|
254 |
$w = $self->where; |
|
255 |
$w->clause($clause); |
|
improved delete() and update...
|
256 |
$w->param($where); |
packaging one directory
|
257 |
} |
select() where can't receive...
|
258 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
259 |
$w = $where; |
|
260 |
$where = $w->param; |
|
261 |
} |
|
make delete() using where ob...
|
262 |
croak qq{"where" must be hash refernce or DBIx::Custom::Where object} |
263 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
264 |
|
|
select() where can't receive...
|
265 |
# String where |
266 |
my $swhere = "$w"; |
|
improved delete() and update...
|
267 |
|
make delete() using where ob...
|
268 |
croak qq{"where" must be specified} |
select() where can't receive...
|
269 |
if $swhere eq '' && !$allow_delete_all; |
make delete() using where ob...
|
270 | |
cleanup
|
271 |
# SQL stack |
272 |
my @sql; |
|
273 | ||
274 |
# Delete |
|
275 |
push @sql, "delete from $table $swhere"; |
|
276 |
push @sql, $append if $append; |
|
277 |
|
|
278 |
my $sql = join(' ', @sql); |
|
packaging one directory
|
279 |
|
added experimental sugar met...
|
280 |
# Create query |
cleanup
|
281 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
282 |
return $query if $args{query}; |
283 |
|
|
packaging one directory
|
284 |
# Execute query |
added auto_filter method
|
285 |
my $ret_val = $self->execute( |
added experimental sugar met...
|
286 |
$query, param => $where, filter => $filter, |
renamed auto_filter to apply...
|
287 |
table => $table); |
packaging one directory
|
288 |
|
289 |
return $ret_val; |
|
290 |
} |
|
291 | ||
cleanup
|
292 |
sub delete_all { shift->delete(allow_delete_all => 1, @_) } |
packaging one directory
|
293 | |
add experimental update_at()...
|
294 |
our %VALID_DELETE_AT_ARGS |
295 |
= map { $_ => 1 } qw/table where append filter query |
|
296 |
primary_key param/; |
|
297 | ||
298 |
sub delete_at { |
|
299 |
my ($self, %args) = @_; |
|
300 |
|
|
301 |
# Check arguments |
|
302 |
foreach my $name (keys %args) { |
|
303 |
croak qq{"$name" is invalid argument} |
|
304 |
unless $VALID_DELETE_AT_ARGS{$name}; |
|
305 |
} |
|
306 |
|
|
307 |
# Primary key |
|
308 |
my $primary_keys = delete $args{primary_key}; |
|
309 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
310 |
|
|
311 |
# Where clause |
|
312 |
my $where = {}; |
|
313 |
if (exists $args{where}) { |
|
314 |
my $where_columns = delete $args{where}; |
|
315 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
316 |
|
|
317 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
318 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
319 |
} |
|
320 |
} |
|
321 |
elsif (exists $args{param}) { |
|
322 |
my $param = delete $args{param}; |
|
323 |
|
|
324 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
325 |
$where->{$primary_keys->[$i]} |
|
326 |
= delete $param->{$primary_keys->[$i]}; |
|
327 |
} |
|
328 |
} |
|
329 |
|
|
330 |
return $self->delete(where => $where, %args); |
|
331 |
} |
|
332 | ||
added helper method
|
333 |
sub DESTROY { } |
334 | ||
renamed auto_filter to apply...
|
335 |
our %VALID_EXECUTE_ARGS = map { $_ => 1 } qw/param filter table/; |
refactoring delete and delet...
|
336 | |
cleanup
|
337 |
sub execute{ |
338 |
my ($self, $query, %args) = @_; |
|
refactoring delete and delet...
|
339 |
|
340 |
# Check arguments |
|
select, insert, update, upda...
|
341 |
foreach my $name (keys %args) { |
add tests
|
342 |
croak qq{"$name" is invalid argument} |
cleanup
|
343 |
unless $VALID_EXECUTE_ARGS{$name}; |
refactoring delete and delet...
|
344 |
} |
345 |
|
|
cleanup
|
346 |
my $params = $args{param} || {}; |
packaging one directory
|
347 |
|
cleanup
|
348 |
# First argument is the soruce of SQL |
349 |
$query = $self->create_query($query) |
|
350 |
unless ref $query; |
|
packaging one directory
|
351 |
|
add table tag
|
352 |
# Applied filter |
cleanup
|
353 |
my $filter = {}; |
add table tag
|
354 |
my $tables = $query->tables; |
355 |
my $arg_tables = $args{table} || []; |
|
356 |
$arg_tables = [$arg_tables] |
|
357 |
unless ref $arg_tables eq 'ARRAY'; |
|
358 |
push @$tables, @$arg_tables; |
|
renamed auto_filter to apply...
|
359 |
foreach my $table (@$tables) { |
cleanup
|
360 |
$filter = { |
361 |
%$filter, |
|
362 |
%{$self->{filter}{out}->{$table} || {}} |
|
added auto_filter method
|
363 |
} |
364 |
} |
|
365 |
|
|
cleanup
|
366 |
# Filter argument |
367 |
my $f = $args{filter} || $query->filter || {}; |
|
368 |
foreach my $column (keys %$f) { |
|
369 |
my $fname = $f->{$column}; |
|
renamed auto_filter to apply...
|
370 |
if (!defined $fname) { |
cleanup
|
371 |
$f->{$column} = undef; |
renamed auto_filter to apply...
|
372 |
} |
373 |
elsif (ref $fname ne 'CODE') { |
|
many changed
|
374 |
croak qq{Filter "$fname" is not registered"} |
cleanup
|
375 |
unless exists $self->filters->{$fname}; |
376 |
|
|
cleanup
|
377 |
$f->{$column} = $self->filters->{$fname}; |
cleanup
|
378 |
} |
379 |
} |
|
cleanup
|
380 |
$filter = {%$filter, %$f}; |
packaging one directory
|
381 |
|
added experimental not_exist...
|
382 |
# Bind |
383 |
my $bind = $self->_bind($params, $query->columns, $filter); |
|
cleanup
|
384 |
|
385 |
# Execute |
|
added experimental not_exist...
|
386 |
my $sth = $query->sth; |
cleanup
|
387 |
my $affected; |
added experimental not_exist...
|
388 |
eval {$affected = $sth->execute(@$bind)}; |
renamed DBIx::Custom::TagPro...
|
389 |
$self->_croak($@, qq{. Following SQL is executed. "$query->{sql}"}) if $@; |
cleanup
|
390 |
|
391 |
# Return resultset if select statement is executed |
|
392 |
if ($sth->{NUM_OF_FIELDS}) { |
|
393 |
|
|
fix bug : filter can't over...
|
394 |
# Result in and end filter |
395 |
my $in_filter = {}; |
|
396 |
my $end_filter = {}; |
|
cleanup
|
397 |
foreach my $table (@$tables) { |
398 |
$in_filter = { |
|
399 |
%$in_filter, |
|
400 |
%{$self->{filter}{in}{$table} || {}} |
|
fix bug : filter can't over...
|
401 |
}; |
402 |
$end_filter = { |
|
403 |
%$end_filter, |
|
404 |
%{$self->{filter}{end}{$table} || {}} |
|
405 |
}; |
|
cleanup
|
406 |
} |
407 |
|
|
408 |
# Result |
|
409 |
my $result = $self->result_class->new( |
|
cleanup
|
410 |
sth => $sth, |
411 |
filters => $self->filters, |
|
412 |
filter_check => $self->filter_check, |
|
cleanup
|
413 |
default_filter => $self->{default_in_filter}, |
fix bug : filter can't over...
|
414 |
filter => $in_filter || {}, |
415 |
end_filter => $end_filter || {} |
|
cleanup
|
416 |
); |
417 | ||
418 |
return $result; |
|
419 |
} |
|
420 |
return $affected; |
|
421 |
} |
|
422 | ||
added auto_filter method
|
423 |
our %VALID_INSERT_ARGS = map { $_ => 1 } qw/table param append |
added experimental sugar met...
|
424 |
filter query/; |
cleanup
|
425 |
sub insert { |
426 |
my ($self, %args) = @_; |
|
427 | ||
428 |
# Check arguments |
|
429 |
foreach my $name (keys %args) { |
|
430 |
croak qq{"$name" is invalid argument} |
|
431 |
unless $VALID_INSERT_ARGS{$name}; |
|
packaging one directory
|
432 |
} |
433 |
|
|
cleanup
|
434 |
# Arguments |
added table not specified ex...
|
435 |
my $table = $args{table}; |
436 |
croak qq{"table" option must be specified} unless $table; |
|
cleanup
|
437 |
my $param = $args{param} || {}; |
438 |
my $append = $args{append} || ''; |
|
439 |
my $filter = $args{filter}; |
|
440 |
|
|
select() where can't receive...
|
441 |
# Columns |
442 |
my @columns; |
|
443 |
my $safety = $self->safety_column_name; |
|
444 |
foreach my $column (keys %$param) { |
|
445 |
croak qq{"$column" is not safety column name} |
|
446 |
unless $column =~ /$safety/; |
|
447 |
push @columns, $column; |
|
448 |
} |
|
cleanup
|
449 |
|
cleanup
|
450 |
# SQL stack |
451 |
my @sql; |
|
452 |
|
|
453 |
# Insert |
|
454 |
push @sql, "insert into $table {insert_param ". join(' ', @columns) . '}'; |
|
455 |
push @sql, $append if $append; |
|
456 |
|
|
select() where can't receive...
|
457 |
# SQL |
cleanup
|
458 |
my $sql = join (' ', @sql); |
packaging one directory
|
459 |
|
added experimental sugar met...
|
460 |
# Create query |
cleanup
|
461 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
462 |
return $query if $args{query}; |
463 |
|
|
packaging one directory
|
464 |
# Execute query |
added auto_filter method
|
465 |
my $ret_val = $self->execute( |
added experimental sugar met...
|
466 |
$query, |
added auto_filter method
|
467 |
param => $param, |
468 |
filter => $filter, |
|
renamed auto_filter to apply...
|
469 |
table => $table |
added auto_filter method
|
470 |
); |
packaging one directory
|
471 |
|
472 |
return $ret_val; |
|
473 |
} |
|
474 | ||
pod fix
|
475 |
sub each_column { |
added experimental iterate_a...
|
476 |
my ($self, $cb) = @_; |
477 |
|
|
478 |
# Iterate all tables |
|
479 |
my $sth_tables = $self->dbh->table_info; |
|
480 |
while (my $table_info = $sth_tables->fetchrow_hashref) { |
|
481 |
|
|
482 |
# Table |
|
483 |
my $table = $table_info->{TABLE_NAME}; |
|
484 |
|
|
485 |
# Iterate all columns |
|
486 |
my $sth_columns = $self->dbh->column_info(undef, undef, $table, '%'); |
|
487 |
while (my $column_info = $sth_columns->fetchrow_hashref) { |
|
488 |
my $column = $column_info->{COLUMN_NAME}; |
|
removed experimental txn_sco...
|
489 |
$self->$cb($table, $column, $column_info); |
added experimental iterate_a...
|
490 |
} |
491 |
} |
|
492 |
} |
|
493 | ||
added dbi_options attribute
|
494 |
sub new { |
495 |
my $self = shift->SUPER::new(@_); |
|
496 |
|
|
497 |
# Check attribute names |
|
498 |
my @attrs = keys %$self; |
|
499 |
foreach my $attr (@attrs) { |
|
500 |
croak qq{"$attr" is invalid attribute name} |
|
501 |
unless $self->can($attr); |
|
502 |
} |
|
cleanup
|
503 | |
504 |
$self->register_tag( |
|
505 |
'?' => \&DBIx::Custom::Tag::placeholder, |
|
506 |
'=' => \&DBIx::Custom::Tag::equal, |
|
507 |
'<>' => \&DBIx::Custom::Tag::not_equal, |
|
508 |
'>' => \&DBIx::Custom::Tag::greater_than, |
|
509 |
'<' => \&DBIx::Custom::Tag::lower_than, |
|
510 |
'>=' => \&DBIx::Custom::Tag::greater_than_equal, |
|
511 |
'<=' => \&DBIx::Custom::Tag::lower_than_equal, |
|
512 |
'like' => \&DBIx::Custom::Tag::like, |
|
513 |
'in' => \&DBIx::Custom::Tag::in, |
|
514 |
'insert_param' => \&DBIx::Custom::Tag::insert_param, |
|
515 |
'update_param' => \&DBIx::Custom::Tag::update_param |
|
516 |
); |
|
added dbi_options attribute
|
517 |
|
518 |
return $self; |
|
519 |
} |
|
520 | ||
added experimental not_exist...
|
521 |
sub not_exists { bless {}, 'DBIx::Custom::NotExists' } |
522 | ||
cleanup
|
523 |
sub register_filter { |
524 |
my $invocant = shift; |
|
525 |
|
|
526 |
# Register filter |
|
527 |
my $filters = ref $_[0] eq 'HASH' ? $_[0] : {@_}; |
|
528 |
$invocant->filters({%{$invocant->filters}, %$filters}); |
|
529 |
|
|
530 |
return $invocant; |
|
531 |
} |
|
packaging one directory
|
532 | |
renamed DBIx::Custom::TagPro...
|
533 |
sub register_tag { shift->query_builder->register_tag(@_) } |
added register_tag_processor
|
534 | |
refactoring select
|
535 |
our %VALID_SELECT_ARGS |
add experimental selection o...
|
536 |
= map { $_ => 1 } qw/table column where append relation filter query selection/; |
refactoring select
|
537 | |
packaging one directory
|
538 |
sub select { |
select, insert, update, upda...
|
539 |
my ($self, %args) = @_; |
packaging one directory
|
540 |
|
refactoring select
|
541 |
# Check arguments |
select, insert, update, upda...
|
542 |
foreach my $name (keys %args) { |
add tests
|
543 |
croak qq{"$name" is invalid argument} |
refactoring select
|
544 |
unless $VALID_SELECT_ARGS{$name}; |
545 |
} |
|
packaging one directory
|
546 |
|
refactoring select
|
547 |
# Arguments |
added table not specified ex...
|
548 |
my $table = $args{table}; |
549 |
my $tables = ref $table eq 'ARRAY' ? $table |
|
550 |
: defined $table ? [$table] |
|
551 |
: []; |
|
add experimental selection o...
|
552 |
my $columns = $args{column} || []; |
553 |
my $selection = $args{selection} || ''; |
|
554 |
my $where = $args{where} || {}; |
|
555 |
my $relation = $args{relation}; |
|
556 |
my $append = $args{append}; |
|
557 |
my $filter = $args{filter}; |
|
packaging one directory
|
558 |
|
cleanup
|
559 |
# SQL stack |
560 |
my @sql; |
|
561 |
|
|
562 |
push @sql, 'select'; |
|
packaging one directory
|
563 |
|
add experimental selection o...
|
564 |
if ($selection) { |
565 |
croak qq{Can't contain "where" clause in selection} |
|
566 |
if $selection =~ /\swhere\s/; |
|
567 |
push @sql, $selection; |
|
568 |
} |
|
569 |
else { |
|
570 |
# Column clause |
|
571 |
if (@$columns) { |
|
572 |
foreach my $column (@$columns) { |
|
573 |
push @sql, ($column, ','); |
|
574 |
} |
|
575 |
pop @sql if $sql[-1] eq ','; |
|
576 |
} |
|
577 |
else { push @sql, '*' } |
|
578 |
|
|
579 |
# Table |
|
580 |
croak qq{"table" option must be specified} unless @$tables; |
|
581 |
push @sql, 'from'; |
|
582 |
foreach my $table (@$tables) { |
|
583 |
push @sql, ($table, ','); |
|
packaging one directory
|
584 |
} |
cleanup
|
585 |
pop @sql if $sql[-1] eq ','; |
packaging one directory
|
586 |
} |
587 |
|
|
select() where can't receive...
|
588 |
# Where |
589 |
my $w; |
|
added experimental DBIx::Cus...
|
590 |
if (ref $where eq 'HASH') { |
select() where can't receive...
|
591 |
my $clause = ['and']; |
592 |
push @$clause, "{= $_}" for keys %$where; |
|
593 |
$w = $self->where; |
|
594 |
$w->clause($clause); |
|
595 |
$w->param($where); |
|
added experimental DBIx::Cus...
|
596 |
} |
597 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
|
select() where can't receive...
|
598 |
$w = $where; |
599 |
$where = $w->param; |
|
packaging one directory
|
600 |
} |
601 |
|
|
select() where can't receive...
|
602 |
croak qq{"where" must be hash reference or DBIx::Custom::Where object} |
603 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
604 |
|
|
605 |
# String where |
|
606 |
my $swhere = "$w"; |
|
cleanup
|
607 |
push @sql, $swhere; |
select() where can't receive...
|
608 |
|
added commit method
|
609 |
# Relation |
add experimental DBIx::Custo...
|
610 |
if (!$selection && $relation) { |
cleanup
|
611 |
push @sql, $swhere eq '' ? 'where' : 'and'; |
612 |
foreach my $rcolumn (keys %$relation) { |
|
613 |
push @sql, ("$rcolumn = " . $relation->{$rcolumn}, 'and'); |
|
packaging one directory
|
614 |
} |
615 |
} |
|
cleanup
|
616 |
pop @sql if $sql[-1] eq 'and'; |
added commit method
|
617 |
|
cleanup
|
618 |
# Append statement |
619 |
push @sql, $append if $append; |
|
620 |
|
|
621 |
# SQL |
|
622 |
my $sql = join (' ', @sql); |
|
packaging one directory
|
623 |
|
added experimental sugar met...
|
624 |
# Create query |
cleanup
|
625 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
626 |
return $query if $args{query}; |
627 |
|
|
packaging one directory
|
628 |
# Execute query |
added auto_filter method
|
629 |
my $result = $self->execute( |
select() where can't receive...
|
630 |
$query, param => $where, filter => $filter, |
631 |
table => $tables); |
|
packaging one directory
|
632 |
|
633 |
return $result; |
|
634 |
} |
|
635 | ||
add experimental update_at()...
|
636 |
our %VALID_SELECT_AT_ARGS |
637 |
= map { $_ => 1 } qw/table column where append relation filter query selection |
|
638 |
param primary_key/; |
|
639 | ||
640 |
sub select_at { |
|
641 |
my ($self, %args) = @_; |
|
642 |
|
|
643 |
# Check arguments |
|
644 |
foreach my $name (keys %args) { |
|
645 |
croak qq{"$name" is invalid argument} |
|
646 |
unless $VALID_SELECT_AT_ARGS{$name}; |
|
647 |
} |
|
648 |
|
|
649 |
# Primary key |
|
650 |
my $primary_keys = delete $args{primary_key}; |
|
651 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
652 |
|
|
653 |
# Where clause |
|
654 |
my $where = {}; |
|
655 |
if (exists $args{where}) { |
|
656 |
my $where_columns = delete $args{where}; |
|
657 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
658 |
|
|
659 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
660 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
661 |
} |
|
662 |
} |
|
663 |
elsif (exists $args{param}) { |
|
664 |
my $param = delete $args{param}; |
|
665 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
666 |
$where->{$primary_keys->[$i]} |
|
667 |
= delete $param->{$primary_keys->[$i]}; |
|
668 |
} |
|
669 |
} |
|
670 |
|
|
671 |
return $self->select(where => $where, %args); |
|
672 |
} |
|
673 | ||
add feture. all model class ...
|
674 |
sub model { |
675 |
my ($self, $name, $model) = @_; |
|
removed experimental base_ta...
|
676 |
|
677 |
# Set |
|
add feture. all model class ...
|
678 |
if ($model) { |
add models() attribute
|
679 |
$self->models->{$name} = $model; |
removed experimental base_ta...
|
680 |
return $self; |
681 |
} |
|
682 |
|
|
add feture. all model class ...
|
683 |
# Check model existance |
684 |
croak qq{Model "$name" is not included} |
|
add models() attribute
|
685 |
unless $self->models->{$name}; |
removed experimental base_ta...
|
686 |
|
687 |
# Get |
|
add models() attribute
|
688 |
return $self->models->{$name}; |
removed experimental base_ta...
|
689 |
} |
690 | ||
add feture. all model class ...
|
691 |
sub include_model { |
692 |
my ($self, $name_space, $model_infos) = @_; |
|
remove DBIx::Custom::Model
|
693 |
|
add feture. all model class ...
|
694 |
$name_space ||= ''; |
695 |
unless ($model_infos) { |
|
696 |
# Load name space module |
|
697 |
croak qq{"$name_space" is invalid class name} |
|
698 |
if $name_space =~ /[^\w:]/; |
|
699 |
eval "use $name_space"; |
|
700 |
croak qq{Name space module "$name_space.pm" is needed. $@} if $@; |
|
table object call dbi object...
|
701 |
|
add feture. all model class ...
|
702 |
# Search model modules |
703 |
my $path = $INC{"$name_space.pm"}; |
|
704 |
$path =~ s/\.pm$//; |
|
705 |
opendir my $dh, $path |
|
706 |
or croak qq{Can't open directory "$path": $!}; |
|
707 |
$model_infos = []; |
|
708 |
while (my $module = readdir $dh) { |
|
709 |
push @$model_infos, $module |
|
710 |
if $module =~ s/\.pm$//; |
|
removed experimental base_ta...
|
711 |
} |
add feture. all model class ...
|
712 |
|
713 |
close $dh; |
|
714 |
} |
|
715 |
|
|
716 |
foreach my $model_info (@$model_infos) { |
|
717 |
|
|
718 |
# Model name and class |
|
719 |
my $model_name; |
|
720 |
my $model_class; |
|
721 |
if (ref $model_info eq 'HASH') { |
|
722 |
$model_name = (keys %$model_info)[0]; |
|
723 |
$model_class = $model_info->{$model_name}; |
|
724 |
} |
|
725 |
else { $model_name = $model_class = $model_info } |
|
726 |
my $mclass = "${name_space}::$model_class"; |
|
table object call dbi object...
|
727 |
|
removed experimental base_ta...
|
728 |
# Load |
add feture. all model class ...
|
729 |
croak qq{"$mclass" is invalid class name} |
730 |
if $mclass =~ /[^\w:]/; |
|
731 |
unless ($mclass->can('isa')) { |
|
732 |
eval "use $mclass"; |
|
removed experimental base_ta...
|
733 |
croak $@ if $@; |
734 |
} |
|
table object call dbi object...
|
735 |
|
removed experimental base_ta...
|
736 |
# Instantiate |
add feture. all model class ...
|
737 |
my $model = $mclass->new(dbi => $self); |
738 |
$model->table($model_name) unless $model->table; |
|
removed experimental DBIx::C...
|
739 |
|
removed experimental base_ta...
|
740 |
# Set |
add feture. all model class ...
|
741 |
$self->model($model_name, $model); |
table object call dbi object...
|
742 |
} |
removed experimental base_ta...
|
743 |
return $self; |
remove DBIx::Custom::Model
|
744 |
} |
745 | ||
add experimental setup_model...
|
746 |
sub setup_model { |
747 |
my $self = shift; |
|
748 |
|
|
749 |
$self->each_column( |
|
750 |
sub { |
|
751 |
my ($self, $table, $column, $column_info) = @_; |
|
752 |
|
|
753 |
if (my $model = $self->models->{$table}) { |
|
754 |
push @{$model->columns}, $column; |
|
755 |
} |
|
756 |
} |
|
757 |
); |
|
758 |
} |
|
759 | ||
cleanup
|
760 |
our %VALID_UPDATE_ARGS |
renamed auto_filter to apply...
|
761 |
= map { $_ => 1 } qw/table param |
added experimental sugar met...
|
762 |
where append filter allow_update_all query/; |
cleanup
|
763 | |
764 |
sub update { |
|
765 |
my ($self, %args) = @_; |
|
version 0.0901
|
766 |
|
cleanup
|
767 |
# Check arguments |
768 |
foreach my $name (keys %args) { |
|
769 |
croak qq{"$name" is invalid argument} |
|
770 |
unless $VALID_UPDATE_ARGS{$name}; |
|
removed reconnect method
|
771 |
} |
added cache_method attribute
|
772 |
|
cleanup
|
773 |
# Arguments |
774 |
my $table = $args{table} || ''; |
|
added table not specified ex...
|
775 |
croak qq{"table" option must be specified} unless $table; |
cleanup
|
776 |
my $param = $args{param} || {}; |
777 |
my $where = $args{where} || {}; |
|
select() where can't receive...
|
778 |
my $append = $args{append} || ''; |
cleanup
|
779 |
my $filter = $args{filter}; |
780 |
my $allow_update_all = $args{allow_update_all}; |
|
version 0.0901
|
781 |
|
cleanup
|
782 |
# Update keys |
select() where can't receive...
|
783 |
my @clumns = keys %$param; |
784 | ||
785 |
# Columns |
|
786 |
my @columns; |
|
787 |
my $safety = $self->safety_column_name; |
|
788 |
foreach my $column (keys %$param) { |
|
789 |
croak qq{"$column" is not safety column name} |
|
790 |
unless $column =~ /$safety/; |
|
791 |
push @columns, $column; |
|
792 |
} |
|
793 |
|
|
cleanup
|
794 |
# Update clause |
select() where can't receive...
|
795 |
my $update_clause = '{update_param ' . join(' ', @clumns) . '}'; |
improved delete() and update...
|
796 | |
797 |
# Where |
|
798 |
my $w; |
|
799 |
if (ref $where eq 'HASH') { |
|
800 |
my $clause = ['and']; |
|
801 |
push @$clause, "{= $_}" for keys %$where; |
|
802 |
$w = $self->where; |
|
803 |
$w->clause($clause); |
|
804 |
$w->param($where); |
|
805 |
} |
|
select() where can't receive...
|
806 |
elsif (ref $where eq 'DBIx::Custom::Where') { |
807 |
$w = $where; |
|
808 |
$where = $w->param; |
|
809 |
} |
|
removed experimental registe...
|
810 |
|
improved delete() and update...
|
811 |
croak qq{"where" must be hash refernce or DBIx::Custom::Where object} |
812 |
unless ref $w eq 'DBIx::Custom::Where'; |
|
removed reconnect method
|
813 |
|
select() where can't receive...
|
814 |
# String where |
815 |
my $swhere = "$w"; |
|
improved delete() and update...
|
816 |
|
817 |
croak qq{"where" must be specified} |
|
select() where can't receive...
|
818 |
if "$swhere" eq '' && !$allow_update_all; |
removed reconnect method
|
819 |
|
cleanup
|
820 |
# SQL stack |
821 |
my @sql; |
|
822 |
|
|
823 |
# Update |
|
824 |
push @sql, "update $table $update_clause $swhere"; |
|
825 |
push @sql, $append if $append; |
|
removed reconnect method
|
826 |
|
cleanup
|
827 |
# Rearrange parameters |
improved delete() and update...
|
828 |
foreach my $wkey (keys %$where) { |
removed reconnect method
|
829 |
|
cleanup
|
830 |
if (exists $param->{$wkey}) { |
831 |
$param->{$wkey} = [$param->{$wkey}] |
|
832 |
unless ref $param->{$wkey} eq 'ARRAY'; |
|
833 |
|
|
834 |
push @{$param->{$wkey}}, $where->{$wkey}; |
|
835 |
} |
|
836 |
else { |
|
837 |
$param->{$wkey} = $where->{$wkey}; |
|
838 |
} |
|
removed reconnect method
|
839 |
} |
cleanup
|
840 |
|
cleanup
|
841 |
# SQL |
842 |
my $sql = join(' ', @sql); |
|
843 |
|
|
added experimental sugar met...
|
844 |
# Create query |
cleanup
|
845 |
my $query = $self->create_query($sql); |
added experimental sugar met...
|
846 |
return $query if $args{query}; |
847 |
|
|
cleanup
|
848 |
# Execute query |
added experimental sugar met...
|
849 |
my $ret_val = $self->execute($query, param => $param, |
added auto_filter method
|
850 |
filter => $filter, |
renamed auto_filter to apply...
|
851 |
table => $table); |
cleanup
|
852 |
|
853 |
return $ret_val; |
|
removed reconnect method
|
854 |
} |
855 | ||
cleanup
|
856 |
sub update_all { shift->update(allow_update_all => 1, @_) }; |
857 | ||
add experimental update_at()...
|
858 |
our %VALID_UPDATE_AT_ARGS |
859 |
= map { $_ => 1 } qw/table param |
|
860 |
where append filter query |
|
861 |
primary_key param/; |
|
862 | ||
863 |
sub update_at { |
|
864 |
my ($self, %args) = @_; |
|
865 |
|
|
866 |
# Check arguments |
|
867 |
foreach my $name (keys %args) { |
|
868 |
croak qq{"$name" is invalid argument} |
|
869 |
unless $VALID_UPDATE_AT_ARGS{$name}; |
|
870 |
} |
|
871 |
|
|
872 |
# Primary key |
|
873 |
my $primary_keys = delete $args{primary_key}; |
|
874 |
$primary_keys = [$primary_keys] unless ref $primary_keys; |
|
875 |
|
|
876 |
# Where clause |
|
877 |
my $where = {}; |
|
878 |
my $param = {}; |
|
879 |
|
|
880 |
if (exists $args{where}) { |
|
881 |
my $where_columns = delete $args{where}; |
|
882 |
$where_columns = [$where_columns] unless ref $where_columns; |
|
883 |
|
|
884 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
885 |
$where->{$primary_keys->[$i]} = $where_columns->[$i]; |
|
886 |
} |
|
887 |
} |
|
888 |
elsif (exists $args{param}) { |
|
889 |
$param = delete $args{param}; |
|
890 |
for(my $i = 0; $i < @$primary_keys; $i ++) { |
|
891 |
$where->{$primary_keys->[$i]} |
|
892 |
= delete $param->{$primary_keys->[$i]}; |
|
893 |
} |
|
894 |
} |
|
895 |
|
|
896 |
return $self->update(where => $where, param => $param, %args); |
|
897 |
} |
|
898 | ||
cleanup
|
899 |
sub where { |
select() where can't receive...
|
900 |
my $self = shift; |
901 | ||
902 |
return DBIx::Custom::Where->new( |
|
903 |
query_builder => $self->query_builder, |
|
904 |
safety_column_name => $self->safety_column_name |
|
905 |
); |
|
cleanup
|
906 |
} |
added experimental DBIx::Cus...
|
907 | |
added experimental not_exist...
|
908 |
sub _bind { |
cleanup
|
909 |
my ($self, $params, $columns, $filter) = @_; |
removed reconnect method
|
910 |
|
cleanup
|
911 |
# bind values |
added experimental not_exist...
|
912 |
my @bind; |
add tests
|
913 |
|
removed reconnect method
|
914 |
# Build bind values |
915 |
my $count = {}; |
|
added experimental not_exist...
|
916 |
my $not_exists = {}; |
cleanup
|
917 |
foreach my $column (@$columns) { |
removed reconnect method
|
918 |
|
919 |
# Value |
|
added experimental not_exist...
|
920 |
my $value; |
921 |
if(ref $params->{$column} eq 'ARRAY') { |
|
922 |
my $i = $count->{$column} || 0; |
|
923 |
$i += $not_exists->{$column} || 0; |
|
924 |
my $found; |
|
925 |
for (my $k = $i; $i < @{$params->{$column}}; $k++) { |
|
926 |
if (ref $params->{$column}->[$k] eq 'DBIx::Custom::NotExists') { |
|
927 |
$not_exists->{$column}++; |
|
928 |
} |
|
929 |
else { |
|
930 |
$value = $params->{$column}->[$k]; |
|
931 |
$found = 1; |
|
932 |
last |
|
933 |
} |
|
934 |
} |
|
935 |
next unless $found; |
|
936 |
} |
|
937 |
else { $value = $params->{$column} } |
|
removed reconnect method
|
938 |
|
cleanup
|
939 |
# Filter |
940 |
my $f = $filter->{$column} || $self->{default_out_filter} || ''; |
|
cleanup
|
941 |
|
added experimental not_exist...
|
942 |
push @bind, $f ? $f->($value) : $value; |
removed reconnect method
|
943 |
|
944 |
# Count up |
|
945 |
$count->{$column}++; |
|
946 |
} |
|
947 |
|
|
added experimental not_exist...
|
948 |
return \@bind; |
removed reconnect method
|
949 |
} |
950 | ||
cleanup
|
951 |
sub _croak { |
952 |
my ($self, $error, $append) = @_; |
|
953 |
$append ||= ""; |
|
954 |
|
|
955 |
# Verbose |
|
956 |
if ($Carp::Verbose) { croak $error } |
|
957 |
|
|
958 |
# Not verbose |
|
959 |
else { |
|
960 |
|
|
961 |
# Remove line and module infromation |
|
962 |
my $at_pos = rindex($error, ' at '); |
|
963 |
$error = substr($error, 0, $at_pos); |
|
964 |
$error =~ s/\s+$//; |
|
965 |
|
|
966 |
croak "$error$append"; |
|
967 |
} |
|
968 |
} |
|
969 | ||
cleanup
|
970 |
# DEPRECATED! |
cleanup
|
971 |
__PACKAGE__->attr( |
972 |
dbi_options => sub { {} }, |
|
973 |
filter_check => 1 |
|
974 |
); |
|
renamed dbi_options to dbi_o...
|
975 | |
cleanup
|
976 |
# DEPRECATED! |
cleanup
|
977 |
sub default_bind_filter { |
978 |
my $self = shift; |
|
979 |
|
|
980 |
if (@_) { |
|
981 |
my $fname = $_[0]; |
|
982 |
|
|
983 |
if (@_ && !$fname) { |
|
984 |
$self->{default_out_filter} = undef; |
|
985 |
} |
|
986 |
else { |
|
many changed
|
987 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
988 |
unless exists $self->filters->{$fname}; |
989 |
|
|
990 |
$self->{default_out_filter} = $self->filters->{$fname}; |
|
991 |
} |
|
992 |
return $self; |
|
993 |
} |
|
994 |
|
|
995 |
return $self->{default_out_filter}; |
|
996 |
} |
|
997 | ||
cleanup
|
998 |
# DEPRECATED! |
cleanup
|
999 |
sub default_fetch_filter { |
1000 |
my $self = shift; |
|
1001 |
|
|
1002 |
if (@_) { |
|
many changed
|
1003 |
my $fname = $_[0]; |
1004 | ||
cleanup
|
1005 |
if (@_ && !$fname) { |
1006 |
$self->{default_in_filter} = undef; |
|
1007 |
} |
|
1008 |
else { |
|
many changed
|
1009 |
croak qq{Filter "$fname" is not registered} |
cleanup
|
1010 |
unless exists $self->filters->{$fname}; |
1011 |
|
|
1012 |
$self->{default_in_filter} = $self->filters->{$fname}; |
|
1013 |
} |
|
1014 |
|
|
1015 |
return $self; |
|
1016 |
} |
|
1017 |
|
|
many changed
|
1018 |
return $self->{default_in_filter}; |
cleanup
|
1019 |
} |
1020 | ||
cleanup
|
1021 |
# DEPRECATED! |
renamed DBIx::Custom::TagPro...
|
1022 |
sub register_tag_processor { |
1023 |
return shift->query_builder->register_tag_processor(@_); |
|
1024 |
} |
|
1025 | ||
fixed DBIx::Custom::QueryBui...
|
1026 |
1; |
1027 | ||
removed reconnect method
|
1028 |
=head1 NAME |
1029 | ||
renamed build_query to creat...
|
1030 |
DBIx::Custom - DBI interface, having hash parameter binding and filtering system |
removed reconnect method
|
1031 | |
1032 |
=head1 SYNOPSYS |
|
cleanup
|
1033 | |
renamed build_query to creat...
|
1034 |
use DBIx::Custom; |
renamed update tag to update...
|
1035 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
renamed dbi_options to dbi_o...
|
1036 |
user => 'ken', password => '!LFKD%$&', |
1037 |
dbi_option => {mysql_enable_utf8 => 1}); |
|
cleanup
|
1038 | |
removed reconnect method
|
1039 |
# Insert |
added insert, update, update...
|
1040 |
$dbi->insert(table => 'book', |
renamed update tag to update...
|
1041 |
param => {title => 'Perl', author => 'Ken'}, |
renamed dbi_options to dbi_o...
|
1042 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1043 |
|
1044 |
# Update |
|
added insert, update, update...
|
1045 |
$dbi->update(table => 'book', |
renamed update tag to update...
|
1046 |
param => {title => 'Perl', author => 'Ken'}, |
removed reconnect method
|
1047 |
where => {id => 5}, |
renamed dbi_options to dbi_o...
|
1048 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1049 |
|
1050 |
# Update all |
|
added insert, update, update...
|
1051 |
$dbi->update_all(table => 'book', |
renamed update tag to update...
|
1052 |
param => {title => 'Perl'}, |
renamed dbi_options to dbi_o...
|
1053 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1054 |
|
1055 |
# Delete |
|
added insert, update, update...
|
1056 |
$dbi->delete(table => 'book', |
removed reconnect method
|
1057 |
where => {author => 'Ken'}, |
renamed dbi_options to dbi_o...
|
1058 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1059 |
|
1060 |
# Delete all |
|
added insert, update, update...
|
1061 |
$dbi->delete_all(table => 'book'); |
cleanup
|
1062 | |
removed reconnect method
|
1063 |
# Select |
renamed fetch_rows to fetch_...
|
1064 |
my $result = $dbi->select( |
added insert, update, update...
|
1065 |
table => 'book', |
update document
|
1066 |
column => [qw/author title/], |
1067 |
where => {author => 'Ken'}, |
|
renamed dbi_options to dbi_o...
|
1068 |
relation => {'book.id' => 'rental.book_id'}, |
updated document
|
1069 |
append => 'order by id limit 5', |
renamed dbi_options to dbi_o...
|
1070 |
filter => {title => 'to_something'} |
added commit method
|
1071 |
); |
cleanup
|
1072 | |
renamed build_query to creat...
|
1073 |
# Execute SQL |
added insert, update, update...
|
1074 |
$dbi->execute("select title from book"); |
removed register_format()
|
1075 |
|
renamed build_query to creat...
|
1076 |
# Execute SQL with hash binding and filtering |
added insert, update, update...
|
1077 |
$dbi->execute("select id from book where {= author} and {like title}", |
removed register_format()
|
1078 |
param => {author => 'ken', title => '%Perl%'}, |
renamed dbi_options to dbi_o...
|
1079 |
filter => {title => 'to_something'}); |
removed reconnect method
|
1080 | |
1081 |
# Create query and execute it |
|
renamed build_query to creat...
|
1082 |
my $query = $dbi->create_query( |
added insert, update, update...
|
1083 |
"select id from book where {= author} and {like title}" |
removed reconnect method
|
1084 |
); |
updated document
|
1085 |
$dbi->execute($query, param => {author => 'Ken', title => '%Perl%'}) |
cleanup
|
1086 | |
1087 |
# Get DBI object |
|
1088 |
my $dbh = $dbi->dbh; |
|
1089 | ||
removed register_format()
|
1090 |
# Fetch |
1091 |
while (my $row = $result->fetch) { |
|
1092 |
# ... |
|
1093 |
} |
|
1094 |
|
|
1095 |
# Fetch hash |
|
1096 |
while (my $row = $result->fetch_hash) { |
|
1097 |
|
|
1098 |
} |
|
1099 |
|
|
renamed update tag to update...
|
1100 |
=head1 DESCRIPTIONS |
removed reconnect method
|
1101 | |
renamed build_query to creat...
|
1102 |
L<DBIx::Custom> is one of L<DBI> interface modules, |
1103 |
such as L<DBIx::Class>, L<DBIx::Simple>. |
|
removed reconnect method
|
1104 | |
renamed build_query to creat...
|
1105 |
This module is not O/R mapper. O/R mapper is useful, |
1106 |
but you must learn many syntax of the O/R mapper, |
|
updated document
|
1107 |
which is almost another language. |
1108 |
Created SQL statement is offten not effcient and damage SQL performance. |
|
renamed build_query to creat...
|
1109 |
so you have to execute raw SQL in the end. |
removed reconnect method
|
1110 | |
renamed build_query to creat...
|
1111 |
L<DBIx::Custom> is middle area between L<DBI> and O/R mapper. |
updated document
|
1112 |
L<DBIx::Custom> provide flexible hash parameter binding and filtering system, |
added experimental expand me...
|
1113 |
and suger methods, such as C<insert()>, C<update()>, C<delete()>, C<select()> |
updated document
|
1114 |
to execute SQL easily. |
removed reconnect method
|
1115 | |
updated document
|
1116 |
L<DBIx::Custom> respects SQL. SQL is very complex and not beautiful, |
1117 |
but de-facto standard, |
|
1118 |
so all people learing database know it. |
|
renamed update tag to update...
|
1119 |
If you already know SQL, |
1120 |
you learn a little thing to use L<DBIx::Custom>. |
|
removed reconnect method
|
1121 | |
pod fix
|
1122 |
See L<DBIx::Custom::Guide> for more details. |
1123 | ||
1124 |
=head1 GUIDE |
|
1125 | ||
1126 |
L<DBIx::Custom::Guide> - L<DBIx::Custom> complete guide |
|
1127 | ||
1128 |
=head1 EXAMPLES |
|
1129 | ||
1130 |
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> - Many useful examples |
|
updated document
|
1131 | |
update document
|
1132 |
=head1 ATTRIBUTES |
packaging one directory
|
1133 | |
cleanup
|
1134 |
=head2 C<cache> |
packaging one directory
|
1135 | |
cleanup
|
1136 |
my $cache = $dbi->cache; |
1137 |
$dbi = $dbi->cache(1); |
|
removed DESTROY method(not b...
|
1138 | |
cleanup
|
1139 |
Enable parsed L<DBIx::Custom::Query> object caching. |
1140 |
Default to 1. |
|
packaging one directory
|
1141 | |
removed DBIx::Custom commit ...
|
1142 |
=head2 C<data_source> |
packaging one directory
|
1143 | |
cleanup
|
1144 |
my $data_source = $dbi->data_source; |
cleanup
|
1145 |
$dbi = $dbi->data_source("DBI:mysql:database=dbname"); |
removed DESTROY method(not b...
|
1146 | |
cleanup
|
1147 |
Data source. |
1148 |
C<connect()> method use this value to connect the database. |
|
removed DESTROY method(not b...
|
1149 | |
removed DBIx::Custom commit ...
|
1150 |
=head2 C<dbh> |
packaging one directory
|
1151 | |
cleanup
|
1152 |
my $dbh = $dbi->dbh; |
1153 |
$dbi = $dbi->dbh($dbh); |
|
packaging one directory
|
1154 | |
cleanup
|
1155 |
L<DBI> object. You can call all methods of L<DBI>. |
packaging one directory
|
1156 | |
renamed dbi_options to dbi_o...
|
1157 |
=head2 C<dbi_option> |
added dbi_options attribute
|
1158 | |
renamed dbi_options to dbi_o...
|
1159 |
my $dbi_option = $dbi->dbi_option; |
1160 |
$dbi = $dbi->dbi_option($dbi_option); |
|
added dbi_options attribute
|
1161 | |
1162 |
DBI options. |
|
add default_dbi_option()
|
1163 | |
1164 |
Each option specified can ovewrite C<default_dbi_option>. |
|
1165 | ||
1166 |
C<connect()> method use this value to connect the database. |
|
1167 | ||
1168 | ||
1169 |
=head2 C<default_dbi_option> |
|
1170 | ||
1171 |
my $default_dbi_option = $dbi->default_dbi_option; |
|
1172 |
$dbi = $dbi->default_dbi_option($default_dbi_option); |
|
1173 | ||
1174 |
DBI default options. |
|
1175 | ||
1176 |
RaiseError => 1, |
|
1177 |
PrintError => 0, |
|
1178 |
AutoCommit => 1, |
|
1179 | ||
added dbi_options attribute
|
1180 |
C<connect()> method use this value to connect the database. |
1181 | ||
cleanup
|
1182 |
Default filter when row is fetched. |
packaging one directory
|
1183 | |
cleanup
|
1184 |
=head2 C<filters> |
bind_filter argument is chan...
|
1185 | |
cleanup
|
1186 |
my $filters = $dbi->filters; |
1187 |
$dbi = $dbi->filters(\%filters); |
|
packaging one directory
|
1188 | |
add models() attribute
|
1189 |
Filters |
1190 | ||
1191 |
=head2 C<(experimental) models> |
|
1192 | ||
1193 |
my $models = $dbi->models; |
|
1194 |
$dbi = $dbi->models(\%models); |
|
1195 | ||
1196 |
Models |
|
1197 | ||
cleanup
|
1198 |
=head2 C<password> |
1199 | ||
1200 |
my $password = $dbi->password; |
|
1201 |
$dbi = $dbi->password('lkj&le`@s'); |
|
1202 | ||
1203 |
Password. |
|
1204 |
C<connect()> method use this value to connect the database. |
|
update document
|
1205 | |
renamed update tag to update...
|
1206 |
=head2 C<query_builder> |
added commit method
|
1207 | |
renamed update tag to update...
|
1208 |
my $sql_class = $dbi->query_builder; |
1209 |
$dbi = $dbi->query_builder(DBIx::Custom::QueryBuilder->new); |
|
added commit method
|
1210 | |
renamed update tag to update...
|
1211 |
SQL builder. C<query_builder()> must be |
renamed build_query to creat...
|
1212 |
the instance of L<DBIx::Custom::QueryBuilder> subclass. |
1213 |
Default to L<DBIx::Custom::QueryBuilder> object. |
|
cleanup
|
1214 | |
cleanup
|
1215 |
=head2 C<result_class> |
cleanup
|
1216 | |
cleanup
|
1217 |
my $result_class = $dbi->result_class; |
1218 |
$dbi = $dbi->result_class('DBIx::Custom::Result'); |
|
cleanup
|
1219 | |
cleanup
|
1220 |
Result class for select statement. |
1221 |
Default to L<DBIx::Custom::Result>. |
|
cleanup
|
1222 | |
update pod
|
1223 |
=head2 C<(experimental) safety_column_name> |
1224 | ||
1225 |
my $safety_column_name = $self->safety_column_name; |
|
1226 |
$dbi = $self->safety_column_name($name); |
|
1227 | ||
1228 |
Safety column name regex. |
|
1229 |
Default is qr/^[\w\.]*$/ |
|
1230 | ||
cleanup
|
1231 |
=head2 C<user> |
cleanup
|
1232 | |
cleanup
|
1233 |
my $user = $dbi->user; |
1234 |
$dbi = $dbi->user('Ken'); |
|
cleanup
|
1235 | |
cleanup
|
1236 |
User name. |
1237 |
C<connect()> method use this value to connect the database. |
|
update pod
|
1238 | |
cleanup
|
1239 |
=head1 METHODS |
added commit method
|
1240 | |
cleanup
|
1241 |
L<DBIx::Custom> inherits all methods from L<Object::Simple> |
autoload DBI method
|
1242 |
and use all method of L<DBI> |
cleanup
|
1243 |
and implements the following new ones. |
added check_filter attribute
|
1244 | |
cleanup
|
1245 |
=head2 C<(experimental) apply_filter> |
added auto_filter method
|
1246 | |
renamed auto_filter to apply...
|
1247 |
$dbi->apply_filter( |
added auto_filter method
|
1248 |
$table, |
fix bug : filter can't over...
|
1249 |
$column1 => {in => $infilter1, out => $outfilter1, end => $endfilter1} |
1250 |
$column2 => {in => $infilter2, out => $outfilter2, end =. $endfilter2} |
|
renamed auto_filter to apply...
|
1251 |
..., |
added auto_filter method
|
1252 |
); |
1253 | ||
renamed auto_filter to apply...
|
1254 |
C<apply_filter> is automatically filter for columns of table. |
added auto_filter method
|
1255 |
This have effect C<insert>, C<update>, C<delete>. C<select> |
cleanup
|
1256 |
and L<DBIx::Custom::Result> object. but this has'nt C<execute> method. |
1257 | ||
cleanup
|
1258 |
If you want to have effect C<execute()> method, use C<table> |
cleanup
|
1259 |
arguments. |
added auto_filter method
|
1260 | |
cleanup
|
1261 |
$result = $dbi->execute( |
1262 |
"select * from table1 where {= key1} and {= key2};", |
|
1263 |
param => {key1 => 1, key2 => 2}, |
|
renamed auto_filter to apply...
|
1264 |
table => ['table1'] |
cleanup
|
1265 |
); |
fix bug : filter can't over...
|
1266 | |
1267 |
You can use three name as column name. |
|
1268 | ||
1269 |
1. column : author |
|
1270 |
2. table.column : book.author |
|
1271 |
3. table__column : book__author |
|
1272 | ||
removed DBIx::Custom commit ...
|
1273 |
=head2 C<connect> |
packaging one directory
|
1274 | |
cleanup
|
1275 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
update document
|
1276 |
user => 'ken', password => '!LFKD%$&'); |
bind_filter argument is chan...
|
1277 | |
cleanup
|
1278 |
Create a new L<DBIx::Custom> object and connect to the database. |
renamed build_query to creat...
|
1279 |
L<DBIx::Custom> is a wrapper of L<DBI>. |
cleanup
|
1280 |
C<AutoCommit> and C<RaiseError> options are true, |
renamed build_query to creat...
|
1281 |
and C<PrintError> option is false by default. |
packaging one directory
|
1282 | |
cleanup
|
1283 |
=head2 C<create_query> |
1284 |
|
|
1285 |
my $query = $dbi->create_query( |
|
added insert, update, update...
|
1286 |
"select * from book where {= author} and {like title};" |
cleanup
|
1287 |
); |
update document
|
1288 | |
cleanup
|
1289 |
Create the instance of L<DBIx::Custom::Query> from the source of SQL. |
1290 |
If you want to get high performance, |
|
1291 |
use C<create_query()> method and execute it by C<execute()> method |
|
1292 |
instead of suger methods. |
|
bind_filter argument is chan...
|
1293 | |
cleanup
|
1294 |
$dbi->execute($query, {author => 'Ken', title => '%Perl%'}); |
version 0.0901
|
1295 | |
cleanup
|
1296 |
=head2 C<execute> |
packaging one directory
|
1297 | |
cleanup
|
1298 |
my $result = $dbi->execute($query, param => $params, filter => \%filter); |
1299 |
my $result = $dbi->execute($source, param => $params, filter => \%filter); |
|
update document
|
1300 | |
cleanup
|
1301 |
Execute query or the source of SQL. |
1302 |
Query is L<DBIx::Custom::Query> object. |
|
1303 |
Return value is L<DBIx::Custom::Result> if select statement is executed, |
|
1304 |
or the count of affected rows if insert, update, delete statement is executed. |
|
version 0.0901
|
1305 | |
removed DBIx::Custom commit ...
|
1306 |
=head2 C<delete> |
packaging one directory
|
1307 | |
cleanup
|
1308 |
$dbi->delete(table => $table, |
1309 |
where => \%where, |
|
1310 |
append => $append, |
|
added experimental sugar met...
|
1311 |
filter => \%filter, |
1312 |
query => 1); |
|
bind_filter argument is chan...
|
1313 | |
renamed build_query to creat...
|
1314 |
Execute delete statement. |
1315 |
C<delete> method have C<table>, C<where>, C<append>, and C<filter> arguments. |
|
1316 |
C<table> is a table name. |
|
1317 |
C<where> is where clause. this must be hash reference. |
|
1318 |
C<append> is a string added at the end of the SQL statement. |
|
1319 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1320 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1321 |
default to 0. This is experimental. |
|
cleanup
|
1322 |
Return value of C<delete()> is the count of affected rows. |
renamed build_query to creat...
|
1323 | |
removed DBIx::Custom commit ...
|
1324 |
=head2 C<delete_all> |
packaging one directory
|
1325 | |
cleanup
|
1326 |
$dbi->delete_all(table => $table); |
packaging one directory
|
1327 | |
renamed build_query to creat...
|
1328 |
Execute delete statement to delete all rows. |
1329 |
Arguments is same as C<delete> method, |
|
1330 |
except that C<delete_all> don't have C<where> argument. |
|
cleanup
|
1331 |
Return value of C<delete_all()> is the count of affected rows. |
bind_filter argument is chan...
|
1332 | |
add experimental update_at()...
|
1333 |
=head3 C<delete_at()> |
1334 | ||
1335 |
To delete row by using primary key, use C<delete_at()> |
|
1336 | ||
1337 |
$dbi->delete_at( |
|
1338 |
table => 'book', |
|
1339 |
primary_key => ['id'], |
|
1340 |
where => ['123'] |
|
1341 |
); |
|
1342 | ||
1343 |
In this example, row which id column is 123 is deleted. |
|
1344 |
NOTE that you must pass array reference as C<where>. |
|
1345 | ||
1346 |
You can also write arguments like this. |
|
1347 | ||
1348 |
$dbi->delete_at( |
|
1349 |
table => 'book', |
|
1350 |
primary_key => ['id'], |
|
1351 |
param => {id => '123'} |
|
1352 |
); |
|
1353 | ||
cleanup
|
1354 |
=head2 C<insert> |
1355 | ||
1356 |
$dbi->insert(table => $table, |
|
1357 |
param => \%param, |
|
1358 |
append => $append, |
|
added experimental sugar met...
|
1359 |
filter => \%filter, |
1360 |
query => 1); |
|
cleanup
|
1361 | |
1362 |
Execute insert statement. |
|
1363 |
C<insert> method have C<table>, C<param>, C<append> |
|
1364 |
and C<filter> arguments. |
|
1365 |
C<table> is a table name. |
|
1366 |
C<param> is the pairs of column name value. this must be hash reference. |
|
1367 |
C<append> is a string added at the end of the SQL statement. |
|
1368 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1369 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1370 |
default to 0. This is experimental. |
|
cleanup
|
1371 |
This is overwrites C<default_bind_filter>. |
1372 |
Return value of C<insert()> is the count of affected rows. |
|
1373 | ||
pod fix
|
1374 |
=head2 C<(experimental) each_column> |
added experimental iterate_a...
|
1375 | |
pod fix
|
1376 |
$dbi->each_column( |
added experimental iterate_a...
|
1377 |
sub { |
add experimental setup_model...
|
1378 |
my ($self, $table, $column, $column_info) = @_; |
added experimental iterate_a...
|
1379 |
|
add experimental setup_model...
|
1380 |
my $type = $column_info->{TYPE_NAME}; |
pod fix
|
1381 |
|
1382 |
if ($type eq 'DATE') { |
|
1383 |
# ... |
|
1384 |
} |
|
added experimental iterate_a...
|
1385 |
} |
1386 |
); |
|
pod fix
|
1387 |
Get column informations from database. |
1388 |
Argument is callback. |
|
1389 |
You can do anything in callback. |
|
added experimental not_exist...
|
1390 |
Callback receive four arguments, dbi object, table name, |
add experimental setup_model...
|
1391 |
column name and column information. |
added experimental not_exist...
|
1392 | |
add feture. all model class ...
|
1393 |
=head2 C<(experimental) include_model> |
removed experimental base_ta...
|
1394 | |
add feture. all model class ...
|
1395 |
$dbi->include_model( |
1396 |
'MyModel' => [ |
|
removed experimental base_ta...
|
1397 |
'book', 'person', 'company' |
1398 |
] |
|
1399 |
); |
|
1400 | ||
add feture. all model class ...
|
1401 |
Include models. First argument is name space. |
removed experimental base_ta...
|
1402 |
Second argument is array reference of class base names. |
1403 | ||
add feture. all model class ...
|
1404 |
If you don't specify second argument, All models under name space is |
1405 |
included. |
|
1406 | ||
1407 |
$dbi->include_model('MyModel'); |
|
1408 | ||
1409 |
Note that in this case name spece module is needed. |
|
1410 | ||
1411 |
# MyModel.pm |
|
1412 |
package MyModel; |
|
1413 |
|
|
1414 |
use base 'DBIx::Custom::Model'; |
|
1415 | ||
1416 |
The following model is instantiated and included. |
|
removed experimental base_ta...
|
1417 | |
add feture. all model class ...
|
1418 |
MyModel::book |
1419 |
MyModel::person |
|
1420 |
MyModel::company |
|
removed experimental base_ta...
|
1421 | |
add feture. all model class ...
|
1422 |
You can get these instance by C<model()>. |
removed experimental base_ta...
|
1423 | |
add feture. all model class ...
|
1424 |
my $book_model = $dbi->model('book'); |
removed experimental base_ta...
|
1425 | |
add feture. all model class ...
|
1426 |
If you want to other name as model class, |
removed experimental base_ta...
|
1427 |
you can do like this. |
1428 | ||
add feture. all model class ...
|
1429 |
$dbi->include_model( |
1430 |
'MyModel' => [ |
|
removed experimental base_ta...
|
1431 |
{'book' => 'Book'}, |
1432 |
{'person' => 'Person'} |
|
1433 |
] |
|
1434 |
); |
|
1435 | ||
added experimental not_exist...
|
1436 |
=head2 C<(experimental) method> |
1437 | ||
1438 |
$dbi->method( |
|
1439 |
update_or_insert => sub { |
|
1440 |
my $self = shift; |
|
1441 |
# do something |
|
1442 |
}, |
|
1443 |
find_or_create => sub { |
|
1444 |
my $self = shift; |
|
1445 |
# do something |
|
1446 |
} |
|
1447 |
); |
|
1448 | ||
1449 |
Register method. These method is called from L<DBIx::Custom> object directory. |
|
1450 | ||
1451 |
$dbi->update_or_insert; |
|
1452 |
$dbi->find_or_create; |
|
1453 | ||
1454 |
=head2 C<new> |
|
1455 | ||
1456 |
my $dbi = DBIx::Custom->connect(data_source => "dbi:mysql:database=dbname", |
|
1457 |
user => 'ken', password => '!LFKD%$&'); |
|
1458 | ||
1459 |
Create a new L<DBIx::Custom> object. |
|
1460 | ||
1461 |
=head2 C<(experimental) not_exists> |
|
1462 | ||
1463 |
my $not_exists = $dbi->not_exists; |
|
1464 | ||
1465 |
Get DBIx::Custom::NotExists object. |
|
experimental extended select...
|
1466 | |
cleanup
|
1467 |
=head2 C<register_filter> |
1468 | ||
1469 |
$dbi->register_filter(%filters); |
|
1470 |
$dbi->register_filter(\%filters); |
|
1471 |
|
|
1472 |
Register filter. Registered filters is available in the following attributes |
|
1473 |
or arguments. |
|
1474 | ||
1475 |
=over 4 |
|
1476 | ||
1477 |
=item * |
|
1478 | ||
1479 |
C<filter> argument of C<insert()>, C<update()>, |
|
1480 |
C<update_all()>, C<delete()>, C<delete_all()>, C<select()> |
|
1481 |
methods |
|
1482 | ||
1483 |
=item * |
|
1484 | ||
1485 |
C<execute()> method |
|
1486 | ||
1487 |
=item * |
|
1488 | ||
1489 |
C<default_filter> and C<filter> of C<DBIx::Custom::Query> |
|
1490 | ||
1491 |
=item * |
|
1492 | ||
1493 |
C<default_filter> and C<filter> of C<DBIx::Custom::Result> |
|
1494 | ||
1495 |
=back |
|
1496 | ||
renamed DBIx::Custom::TagPro...
|
1497 |
=head2 C<register_tag> |
added register_tag_processor
|
1498 | |
renamed DBIx::Custom::TagPro...
|
1499 |
$dbi->register_tag( |
added register_tag_processor
|
1500 |
limit => sub { |
1501 |
...; |
|
1502 |
} |
|
1503 |
); |
|
1504 | ||
cleanup
|
1505 |
Register tag. |
added register_tag_processor
|
1506 | |
added auto_filter method
|
1507 |
=head2 C<rollback> |
cleanup
|
1508 | |
1509 |
$dbi->rollback; |
|
1510 | ||
1511 |
Rollback transaction. |
|
1512 |
This is same as L<DBI>'s C<rollback>. |
|
1513 | ||
removed DBIx::Custom commit ...
|
1514 |
=head2 C<select> |
packaging one directory
|
1515 |
|
cleanup
|
1516 |
my $result = $dbi->select(table => $table, |
1517 |
column => [@column], |
|
1518 |
where => \%where, |
|
1519 |
append => $append, |
|
1520 |
relation => \%relation, |
|
added experimental sugar met...
|
1521 |
filter => \%filter, |
add experimental selection o...
|
1522 |
query => 1, |
1523 |
selection => $selection); |
|
update document
|
1524 | |
renamed build_query to creat...
|
1525 |
Execute select statement. |
cleanup
|
1526 |
C<select> method have C<table>, C<column>, C<where>, C<append>, |
renamed build_query to creat...
|
1527 |
C<relation> and C<filter> arguments. |
1528 |
C<table> is a table name. |
|
cleanup
|
1529 |
C<where> is where clause. this is normally hash reference. |
renamed build_query to creat...
|
1530 |
C<append> is a string added at the end of the SQL statement. |
1531 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1532 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1533 |
default to 0. This is experimental. |
|
add experimental selection o...
|
1534 |
C<selection> is string of column name and tables. This is experimental |
1535 | ||
1536 |
selection => 'name, location.name as location_name ' . |
|
1537 |
'from company inner join location' |
|
update document
|
1538 | |
cleanup
|
1539 |
First element is a string. it contains tags, |
1540 |
such as "{= title} or {like author}". |
|
1541 |
Second element is paramters. |
|
1542 | ||
add experimental update_at()...
|
1543 |
=head3 C<select_at()> |
1544 | ||
1545 |
To select row by using primary key, use C<select_at()>. |
|
1546 | ||
1547 |
$dbi->select_at(table => 'book', primary_key => ['id'], where => ['123']); |
|
1548 | ||
1549 |
In this example, row which id colunm is 123 is selected. |
|
1550 |
NOTE that you must pass array reference as C<where>. |
|
1551 | ||
cleanup
|
1552 |
=head2 C<update> |
removed reconnect method
|
1553 | |
cleanup
|
1554 |
$dbi->update(table => $table, |
1555 |
param => \%params, |
|
1556 |
where => \%where, |
|
1557 |
append => $append, |
|
added experimental sugar met...
|
1558 |
filter => \%filter, |
1559 |
query => 1) |
|
removed reconnect method
|
1560 | |
cleanup
|
1561 |
Execute update statement. |
1562 |
C<update> method have C<table>, C<param>, C<where>, C<append> |
|
1563 |
and C<filter> arguments. |
|
1564 |
C<table> is a table name. |
|
1565 |
C<param> is column-value pairs. this must be hash reference. |
|
1566 |
C<where> is where clause. this must be hash reference. |
|
1567 |
C<append> is a string added at the end of the SQL statement. |
|
1568 |
C<filter> is filters when parameter binding is executed. |
|
added experimental sugar met...
|
1569 |
C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
1570 |
default to 0. This is experimental. |
|
cleanup
|
1571 |
This is overwrites C<default_bind_filter>. |
1572 |
Return value of C<update()> is the count of affected rows. |
|
removed reconnect method
|
1573 | |
add feture. all model class ...
|
1574 |
=head2 C<(experimental) model> |
remove DBIx::Custom::Model
|
1575 | |
add feture. all model class ...
|
1576 |
$dbi->model('book')->method( |
remove DBIx::Custom::Model
|
1577 |
insert => sub { ... }, |
1578 |
update => sub { ... } |
|
1579 |
); |
|
1580 |
|
|
add feture. all model class ...
|
1581 |
my $model = $dbi->model('book'); |
remove DBIx::Custom::Model
|
1582 | |
add feture. all model class ...
|
1583 |
Set and get a L<DBIx::Custom::Model> object, |
remove DBIx::Custom::Model
|
1584 | |
add experimental setup_model...
|
1585 |
=head2 C<(experimental) setup_model> |
1586 | ||
1587 |
$dbi->setup_model; |
|
1588 | ||
1589 |
Setup all model objects. |
|
1590 |
C<columns> and C<primary_key> is automatically set. |
|
1591 | ||
cleanup
|
1592 |
=head2 C<update_all> |
renamed build_query to creat...
|
1593 | |
cleanup
|
1594 |
$dbi->update_all(table => $table, |
1595 |
param => \%params, |
|
1596 |
filter => \%filter, |
|
1597 |
append => $append); |
|
renamed build_query to creat...
|
1598 | |
cleanup
|
1599 |
Execute update statement to update all rows. |
1600 |
Arguments is same as C<update> method, |
|
1601 |
except that C<update_all> don't have C<where> argument. |
|
1602 |
Return value of C<update_all()> is the count of affected rows. |
|
removed DBIx::Custom commit ...
|
1603 | |
add experimental update_at()...
|
1604 |
=head3 C<update_at()> |
1605 | ||
1606 |
To update row by using primary key, use C<update_at()> |
|
1607 | ||
1608 |
$dbi->update_at( |
|
1609 |
table => 'book', |
|
1610 |
primary_key => ['id'], |
|
1611 |
where => ['123'], |
|
1612 |
param => {name => 'Ken'} |
|
1613 |
); |
|
1614 | ||
1615 |
In this example, row which id column is 123 is updated. |
|
1616 |
NOTE that you must pass array reference as C<where>. |
|
1617 |
If C<param> contains primary key, |
|
1618 |
the key and value is delete from C<param>. |
|
1619 | ||
fix tests
|
1620 |
=head2 C<(experimental) where> |
1621 | ||
1622 |
my $where = $dbi->where; |
|
1623 | ||
1624 |
Create a new L<DBIx::Custom::Where> object. |
|
1625 | ||
cleanup
|
1626 |
=head2 C<cache_method> |
cleanup
|
1627 | |
1628 |
$dbi = $dbi->cache_method(\&cache_method); |
|
1629 |
$cache_method = $dbi->cache_method |
|
1630 | ||
1631 |
Method to set and get caches. |
|
1632 | ||
cleanup
|
1633 |
=head1 Tags |
1634 | ||
1635 |
The following tags is available. |
|
1636 | ||
add experimental selection o...
|
1637 |
=head2 C<(experimental) table> |
add table tag
|
1638 | |
1639 |
Table tag |
|
1640 | ||
1641 |
{table TABLE} -> TABLE |
|
1642 | ||
1643 |
This is used to teach what is applied table to C<execute()>. |
|
1644 | ||
cleanup
|
1645 |
=head2 C<?> |
1646 | ||
1647 |
Placeholder tag. |
|
1648 | ||
1649 |
{? NAME} -> ? |
|
1650 | ||
1651 |
=head2 C<=> |
|
1652 | ||
1653 |
Equal tag. |
|
1654 | ||
1655 |
{= NAME} -> NAME = ? |
|
1656 | ||
1657 |
=head2 C<E<lt>E<gt>> |
|
1658 | ||
1659 |
Not equal tag. |
|
1660 | ||
1661 |
{<> NAME} -> NAME <> ? |
|
1662 | ||
1663 |
=head2 C<E<lt>> |
|
1664 | ||
1665 |
Lower than tag |
|
1666 | ||
1667 |
{< NAME} -> NAME < ? |
|
1668 | ||
1669 |
=head2 C<E<gt>> |
|
1670 | ||
1671 |
Greater than tag |
|
1672 | ||
1673 |
{> NAME} -> NAME > ? |
|
1674 | ||
1675 |
=head2 C<E<gt>=> |
|
1676 | ||
1677 |
Greater than or equal tag |
|
1678 | ||
1679 |
{>= NAME} -> NAME >= ? |
|
1680 | ||
1681 |
=head2 C<E<lt>=> |
|
1682 | ||
1683 |
Lower than or equal tag |
|
1684 | ||
1685 |
{<= NAME} -> NAME <= ? |
|
1686 | ||
1687 |
=head2 C<like> |
|
1688 | ||
1689 |
Like tag |
|
1690 | ||
1691 |
{like NAME} -> NAME like ? |
|
1692 | ||
1693 |
=head2 C<in> |
|
1694 | ||
1695 |
In tag. |
|
1696 | ||
1697 |
{in NAME COUNT} -> NAME in [?, ?, ..] |
|
1698 | ||
1699 |
=head2 C<insert_param> |
|
1700 | ||
1701 |
Insert parameter tag. |
|
1702 | ||
1703 |
{insert_param NAME1 NAME2} -> (NAME1, NAME2) values (?, ?) |
|
1704 | ||
1705 |
=head2 C<update_param> |
|
1706 | ||
1707 |
Updata parameter tag. |
|
1708 | ||
1709 |
{update_param NAME1 NAME2} -> set NAME1 = ?, NAME2 = ? |
|
1710 | ||
DBIx::Custom is now stable
|
1711 |
=head1 STABILITY |
1712 | ||
cleanup
|
1713 |
L<DBIx::Custom> is stable. APIs keep backword compatible |
1714 |
except experimental one in the feature. |
|
DBIx::Custom is now stable
|
1715 | |
removed DESTROY method(not b...
|
1716 |
=head1 BUGS |
1717 | ||
renamed build_query to creat...
|
1718 |
Please tell me bugs if found. |
removed DESTROY method(not b...
|
1719 | |
1720 |
C<< <kimoto.yuki at gmail.com> >> |
|
1721 | ||
1722 |
L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
1723 | ||
removed reconnect method
|
1724 |
=head1 AUTHOR |
1725 | ||
1726 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
version 0.0901
|
1727 | |
packaging one directory
|
1728 |
=head1 COPYRIGHT & LICENSE |
1729 | ||
cleanup
|
1730 |
Copyright 2009-2011 Yuki Kimoto, all rights reserved. |
packaging one directory
|
1731 | |
1732 |
This program is free software; you can redistribute it and/or modify it |
|
1733 |
under the same terms as Perl itself. |
|
1734 | ||
1735 |
=cut |
|
added cache_method attribute
|
1736 | |
1737 |