File Coverage

blib/lib/Otogiri.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 27 27 100.0


line stmt bran cond sub pod time code
1             package Otogiri;
2 11     11   1244927 use 5.008005;
  11         36  
3 11     11   74 use strict;
  11         19  
  11         343  
4 11     11   56 use warnings;
  11         17  
  11         738  
5              
6             our $VERSION = "0.24";
7              
8 11     11   4214 use parent 'Exporter';
  11         2785  
  11         84  
9 11     11   7021 use SQL::QueryMaker;
  11         38044  
  11         1132  
10 11     11   6406 use DBIx::Otogiri;
  11         37  
  11         1239  
11              
12             our @EXPORT = map {"sql_$_"} qw/
13             eq like lt gt le ge
14             is_null is_not_null
15             between not_between
16             in not_in
17             and or not
18             op raw
19             /;
20              
21             sub new {
22 12     12 1 1606094 my ($class, %opts) = @_;
23 12         131 DBIx::Otogiri->new(%opts);
24             }
25              
26             1;
27             __END__
28              
29             =encoding utf-8
30              
31             =head1 NAME
32              
33             Otogiri - A lightweight medicine for using database
34              
35             =head1 SYNOPSIS
36              
37             use Otogiri;
38             my $db = Otogiri->new(connect_info => ['dbi:SQLite:...', '', '']);
39              
40             # or use with DBURL
41             my $db = Otogiri->new(dburl => 'sqlite://...');
42            
43             $db->insert(book => {title => 'mybook1', author => 'me', ...});
44              
45             my $book_id = $db->last_insert_id;
46             my $row = $db->single(book => {id => $book_id});
47              
48             print 'Title: '. $row->{title}. "\n";
49            
50             my @rows = $db->select(book => sql_ge(price => 500));
51            
52             # or non-strict mode
53             my @rows = $db->select(book => {price => {'>=' => 500}});
54              
55             for my $r (@rows) {
56             printf "Title: %s \nPrice: %s yen\n", $r->{title}, $r->{price};
57             }
58            
59             # or using iterator
60             my $iter = $db->select(book => {price => {'>=' => 500}});
61             while (my $row = $iter->next) {
62             printf "Title: %s \nPrice: %s yen\n", $row->{title}, $row->{price};
63             }
64              
65             # If you using perl 5.38 or later, you can use class feature.
66             class Book {
67             field $id :param;
68             field $title :param;
69             field $author :param;
70             field $price :param;
71             field $created_at :param;
72             field $updated_at :param;
73              
74             method title {
75             return $title;
76             }
77             };
78             my $book = $db->row_class('Book')->single(book => {id => 1}); # $book is Book object.
79             say $book->title; # => say book title.
80            
81             my $hash = $db->no_row_class->single(book => {id => 1}); # $hash is HASH reference.
82             say $hash->{title}; # => say book title.
83            
84             $db->update(book => [author => 'oreore'], {author => 'me'});
85            
86             $db->delete(book => {author => 'me'});
87            
88             # using transaction
89             do {
90             my $txn = $db->txn_scope;
91             $db->insert(book => ...);
92             $db->insert(store => ...);
93             $txn->commit;
94             };
95              
96             =head1 DESCRIPTION
97              
98             Otogiri is a thing that like as ORM. A slogan is "Schema-less, Fat-less".
99              
100             =head1 ATTRIBUTES
101              
102             Please see ATTRIBUTES section of L<DBIx::Otogiri> documentation.
103              
104             =head1 METHODS
105              
106             =head2 new
107              
108             my $db = Otogiri->new( connect_info => [$dsn, $dbuser, $dbpass] );
109              
110             Instantiate and connect to db. Then, it returns L<DBIx::Otogiri> object.
111              
112             =head1 EXPORT FUNCTIONS
113              
114             Otogiri exports each SQL::QueryMaker::sql_* functions. (ex. sql_ge(), sql_like() and more...)
115              
116             For more information, please see FUNCTIONS section of L<SQL::QueryMaker>'s documentation.
117              
118             =head1 INFORMATION ABOUT INCOMPATIBILITY
119              
120             =head2 version 0.11
121              
122             An insert() method is removed, and it was become a synonym of fast_insert() method.
123              
124             If you want to use previous style insert() method, please try L<Otogiri::Plugin::InsertAndFetch> .
125              
126             =head1 LICENSE
127              
128             Copyright (C) ytnobody.
129              
130             This library is free software; you can redistribute it and/or modify
131             it under the same terms as Perl itself.
132              
133             =head1 AUTHOR
134              
135             ytnobody E<lt>ytnobody@gmail.comE<gt>
136              
137             =head1 SEE ALSO
138              
139             L<DBIx::Otogiri>
140              
141             L<DBIx::Sunny>
142              
143             L<SQL::Maker>
144              
145             L<SQL::QueryMaker>
146              
147             =cut
148