CouchLike/Pg.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 42 CC 4 SCAR 18.3
CC
4
Cov
0%
_offset_limit_sql
12.0
create_table
6.0
_start_with
2.0
CRAP 6.2
1 package DBIx::CouchLike::Pg;
2  
3 use strict;
4 use warnings;
5 use base qw/ DBIx::CouchLike /;
6  
7 my @sql_format = (
8 q|CREATE TABLE %s_data (id text not null primary key, value text)|,
9 q|CREATE TABLE %s_map (design_id text not null, id text not null, key text not null, value text )|,
10 q|CREATE INDEX %s_map_idx ON %s_map (design_id, key)|,
11 );
12  
13 my @sql_format_v = (
14 q|CREATE TABLE %s_data (id text not null primary key, value text, version integer not null default 0)|,
15 q|CREATE TABLE %s_map (design_id text not null, id text not null, key text not null, value text )|,
16 q|CREATE INDEX %s_map_idx ON %s_map (design_id, key)|,
17 );
18  
19 sub create_table {
20 my $class = shift;
21 my $dbh = shift;
22 my $name = shift;
23 my $v = shift;
24 for my $f ( $v ? @sql_format_v : @sql_format ) {
25 $dbh->do( sprintf $f, $name, $name );
26 }
27 }
28  
29 sub _start_with {
30 my ( $self, $key, $value ) = @_;
31 return ( " $key ~ ? ", "^" . $value );
32 }
33  
34 sub _offset_limit_sql {
35 my ( $self, $sql, $query, $param ) = @_;
36  
37 if ( defined $query->{offset} ) {
38 $sql .= q{ OFFSET ? };
39 push @$param, $query->{offset};
40 }
41 if ( defined $query->{limit} ) {
42 $sql .= q{ LIMIT ? };
43 push @$param, $query->{limit};
44 }
45 return $sql;
46 }
47  
48 1;