packing
|
1 |
package DBIx::Custom::MySQL; |
2 |
use base 'DBIx::Custom::Basic'; |
|
3 | ||
4 |
use warnings; |
|
5 |
use strict; |
|
6 |
our $VERSION = '0.0101'; |
|
7 | ||
8 |
my $class = __PACKAGE__; |
|
9 | ||
10 |
$class->add_format( |
|
11 |
datetime => $class->formats->{SQL99_datetime}, |
|
12 |
date => $class->formats->{SQL99_date}, |
|
13 |
time => $class->formats->{SQL99_time}, |
|
14 |
); |
|
15 | ||
16 | ||
17 |
sub connect { |
|
18 |
my $self = shift; |
|
19 |
|
|
20 |
if (!$self->data_source && (my $database = $self->database)) { |
|
21 |
$self->data_source("dbi:mysql:dbname=$database"); |
|
22 |
} |
|
23 |
|
|
24 |
return $self->SUPER::connect; |
|
25 |
} |
|
26 | ||
27 |
=head1 NAME |
|
28 | ||
29 |
DBIx::Custom::MySQL - DBIx::Custom MySQL implementation |
|
30 | ||
31 |
=head1 VERSION |
|
32 | ||
33 |
Version 0.0101 |
|
34 | ||
35 |
=head1 SYNOPSIS |
|
36 | ||
37 |
# New |
|
38 |
my $dbi = DBIx::Custom::MySQL->new(user => 'taro', $password => 'kliej&@K', |
|
39 |
database => 'sample_db'); |
|
40 |
# Insert |
|
41 |
$dbi->insert('books', {title => 'perl', author => 'taro'}); |
|
42 |
|
|
43 |
# Update |
|
44 |
# same as 'update books set (title = 'aaa', author = 'ken') where id = 5; |
|
45 |
$dbi->update('books', {title => 'aaa', author => 'ken'}, {id => 5}); |
|
46 |
|
|
47 |
# Delete |
|
48 |
$dbi->delete('books', {author => 'taro'}); |
|
49 |
|
|
50 |
# select * from books; |
|
51 |
$dbi->select('books'); |
|
52 |
|
|
53 |
# select * from books where ahthor = 'taro'; |
|
54 |
$dbi->select('books', {author => 'taro'}); |
|
55 | ||
56 |
=head1 CAUTION |
|
57 | ||
58 |
This module automatically encode_utf8 or decode_utf8 |
|
59 |
If you do not want to this, you set |
|
60 |
|
|
61 |
$dbi->bind_filter(undef); |
|
62 |
$dbi->fetch_filter(undef); |
|
63 | ||
64 |
=head1 OBJECT METHOD |
|
65 | ||
66 |
=head2 connect |
|
67 | ||
68 |
This method override DBIx::Custom::connect |
|
69 |
|
|
70 |
If database is set, automatically data source is created and connect |
|
71 | ||
72 |
=head1 AUTHOR |
|
73 | ||
74 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
75 | ||
76 |
Github L<http://github.com/yuki-kimoto> |
|
77 | ||
78 |
=head1 COPYRIGHT & LICENSE |
|
79 | ||
80 |
Copyright 2009 Yuki Kimoto, all rights reserved. |
|
81 | ||
82 |
This program is free software; you can redistribute it and/or modify it |
|
83 |
under the same terms as Perl itself. |
|
84 | ||
85 |