Newer Older
138 lines | 3.206kb
packing
yuki-kimoto authored on 2009-11-12
1
package DBIx::Custom::SQLite;
2
use base 'DBIx::Custom::Basic';
3

            
4
use warnings;
5
use strict;
6
use Carp 'croak';
7

            
rename fetch_all_hash to fet...
yuki-kimoto authored on 2009-11-15
8
our $VERSION = '0.0201';
packing
yuki-kimoto authored on 2009-11-12
9

            
10
my $class = __PACKAGE__;
11

            
12
$class->add_format(
13
    datetime => $class->formats->{SQL99_datetime},
14
    date     => $class->formats->{SQL99_date},
15
    time     => $class->formats->{SQL99_time},
16
);
17

            
18
sub connect {
19
    my $self = shift;
20
    
21
    if (!$self->data_source && (my $database = $self->database)) {
22
        $self->data_source("dbi:SQLite:dbname=$database");
23
    }
24
    
25
    return $self->SUPER::connect;
26
}
27

            
28
sub connect_memory {
29
    my $self = shift;
30
    
31
    # Data source for memory database
32
    $self->data_source('dbi:SQLite:dbname=:memory:');
33
    
34
    # Already connected
35
    croak("Already connected") if $self->connected;
36
    
37
    # Connect
38
    $self->connect;
39
    
40
    return $self;
41
}
42

            
43
sub reconnect_memory {
44
    my $self = shift;
45

            
46
    # Data source for memory database
47
    $self->data_source('dbi:SQLite:dbname=:memory:');
48
    
49
    # Reconnect
50
    $self->reconnect;
51
    
52
    return $self;
53
}
54

            
55

            
56
=head1 NAME
57

            
58
DBIx::Custom::SQLite - DBIx::Custom SQLite implementation
59

            
Various change
yuki-kimoto authored on 2009-11-12
60
=head1 Version
packing
yuki-kimoto authored on 2009-11-12
61

            
rename fetch_all_hash to fet...
yuki-kimoto authored on 2009-11-15
62
Version 0.0201
packing
yuki-kimoto authored on 2009-11-12
63

            
Various change
yuki-kimoto authored on 2009-11-12
64
=head1 Synopsys
packing
yuki-kimoto authored on 2009-11-12
65

            
66
    use DBIx::Custom::SQLite;
67
    
68
    # New
69
    my $dbi = DBIx::Custom::SQLite->new(user => 'taro', $password => 'kliej&@K',
70
                                       database => 'sample.db');
71
    
72
    # Insert 
73
    $dbi->insert('books', {title => 'perl', author => 'taro'});
74
    
75
    # Update 
76
    # same as 'update books set (title = 'aaa', author = 'ken') where id = 5;
77
    $dbi->update('books', {title => 'aaa', author => 'ken'}, {id => 5});
78
    
79
    # Delete
80
    $dbi->delete('books', {author => 'taro'});
81
    
82
    # select * from books;
83
    $dbi->select('books');
84
    
85
    # select * from books where ahthor = 'taro'; 
86
    $dbi->select('books', {author => 'taro'}); 
87
    
88
    # select author, title from books where author = 'taro'
89
    $dbi->select('books', [qw/author title/], {author => 'taro'});
90
    
91
    # select author, title from books where author = 'taro' order by id limit 1;
92
    $dbi->select('books', [qw/author title/], {author => 'taro'},
93
                 'order by id limit 1');
94

            
Various change
yuki-kimoto authored on 2009-11-12
95
=head1 See DBIx::Custom and DBI::Custom::Basic documentation
96

            
97
This class is L<DBIx::Custom::Basic> subclass.
98
and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass
99

            
100
You can use all methods of L<DBIx::Custom::Basic> and <DBIx::Custom>
101
Please see L<DBIx::Custom::Basic> and <DBIx::Custom> documentation
packing
yuki-kimoto authored on 2009-11-12
102

            
Various change
yuki-kimoto authored on 2009-11-12
103
=head1 Object methods
packing
yuki-kimoto authored on 2009-11-12
104

            
105
=head2 connect
106

            
Various change
yuki-kimoto authored on 2009-11-12
107
This override L<DBIx::Custom> connect.
108

            
109
    # Connect to database
110
    $dbi->connect;
111

            
112
If database attribute is set, automatically data source is created and connect
packing
yuki-kimoto authored on 2009-11-12
113

            
114
=head2 connect_memory
115

            
116
    # Connect memory database
117
    $self = $dbi->connect_memory;
118

            
119
=head2 reconnect_memory
120

            
121
    # Reconnect memory database
122
    $self = $dbi->reconnect_memory;
123

            
Various change
yuki-kimoto authored on 2009-11-12
124
=head1 Author
packing
yuki-kimoto authored on 2009-11-12
125

            
126
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
127

            
128
Github L<http://github.com/yuki-kimoto>
129

            
Various change
yuki-kimoto authored on 2009-11-12
130
I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom>
131

            
132
=head1 Copyright & lisence
packing
yuki-kimoto authored on 2009-11-12
133

            
134
Copyright 2009 Yuki Kimoto, all rights reserved.
135

            
136
This program is free software; you can redistribute it and/or modify it
137
under the same terms as Perl itself.
138