RDF/Trine/Store/DBI/Pg.pm

filter: Statementstmt 34.4% 20 / 58 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 100% 2 / 2 totaltotal 32.5% 28 / 86 CC 9 SCAR 38.2
CC
9
Cov
27%
init
90.0
_config_meta
2.0
new_with_config
2.0
CRAP 45.7
« RDF/Trine/Parser/Turtle/Lexer.pm ↑ Summary RDF/Trine/Node/Literal.pm »
1 =head1 NAME
2  
3 RDF::Trine::Store::DBI::Pg - PostgreSQL subclass of DBI store
4  
5 =head1 VERSION
6  
7 This document describes RDF::Trine::Store::DBI::Pg version 1.019
8  
9 =head1 SYNOPSIS
10  
11 use RDF::Trine::Store::DBI::Pg;
12  
13 =head1 DESCRIPTION
14  
15 =cut
16  
17 package RDF::Trine::Store::DBI::Pg;
18  
19 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 68 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 68 ▶use base qw(RDF::Trine::Store::DBI);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 68 ▶use Scalar::Util qw(blessed reftype refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 68 our $VERSION;
27 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
28 68 $VERSION = "1.019";
29 68 my $class = __PACKAGE__;
30 68 $RDF::Trine::Store::STORE_CLASSES{ $class } = $VERSION;
31 }
32  
33 0 ▶sub _config_meta {
Subroutine _config_meta: not called CC=1 SCAR=6.9
34 return {
35 0 required_keys => [qw(dsn username password name)],
36 fields => {
37 name => { description => 'Model Name', type => 'string' },
38 dsn => { description => 'DSN', type => 'string', template => 'DBI:Pg:dbname=[%database%]' },
39 database => { description => 'Database Name', type => 'string' },
40 username => { description => 'Username', type => 'string' },
41 password => { description => 'Password', type => 'password' },
42 driver => { description => 'Driver', type => 'string', value => 'Pg' },
43 },
44 }
45 }
46  
47 =head1 METHODS
48  
49 Beyond the methods documented below, this class inherits methods from the
50 L<RDF::Trine::Store::DBI> class.
51  
52 =over 4
53  
54 =cut
55  
56 =item C<< new_with_config ( \%config ) >>
57  
58 Returns a new RDF::Trine::Store object based on the supplied configuration hashref.
59  
60 =cut
61  
62 0 ▶sub new_with_config {
Subroutine new_with_config: not called CC=1 SCAR=6.9
Pod documented
63 0 my $proto = shift;
64 0 my $config = shift;
65 0 $config->{storetype} = 'DBI::Pg';
66 0 return $proto->SUPER::new_with_config( $config );
67 }
68  
69 0 ▶sub _column_name {
Subroutine _column_name: not called CC=1 SCAR=6.9
70 0 my $self = shift;
71 0 my @args = @_;
72 0 my $col = lc(join('_', @args));
73 0 return $col;
74 }
75  
76 =item C<< init >>
77  
78 Creates the necessary tables in the underlying database.
79  
80 =cut
81  
82 0 ▶sub init {
Subroutine init: not called CC=9 SCAR=45.0
Pod documented
83 0 my $self = shift;
84 0 my $dbh = $self->dbh;
85 0 my $name = $self->model_name;
86 0 my $id = RDF::Trine::Store::DBI::_mysql_hash( $name );
87 0 my $l = Log::Log4perl->get_logger("rdf.trine.store.dbi");
88
89 0 local($dbh->{AutoCommit}) = 0;
90 0 ▶ unless ($self->_table_exists("literals")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_table_exists("literals")) 0 0 0
91 0 ▶ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return };
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do("\t\t\tCREATE TABLE literals (\n\t\t\t\tID NUMERIC(20) PRIMARY KEY,\n\t\t\t\tValue text NOT NULL,\n\t\t\t\tLanguage text NOT NULL DEFAULT '',\n\t\t\t\tDatatype text NOT NULL DEFAULT ''\n\t\t\t);\n") or do { $l->trace($dbh->errstr); $dbh->rollback; return } 0 0 0
92 CREATE TABLE literals (
93 ID NUMERIC(20) PRIMARY KEY,
94 Value text NOT NULL,
95 Language text NOT NULL DEFAULT '',
96 Datatype text NOT NULL DEFAULT ''
97 );
98 END
99 0 ▶ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return };
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do("\t\t\tCREATE TABLE resources (\n\t\t\t\tID NUMERIC(20) PRIMARY KEY,\n\t\t\t\tURI text NOT NULL\n\t\t\t);\n") or do { $l->trace($dbh->errstr); $dbh->rollback; return } 0 0 0
100 CREATE TABLE resources (
101 ID NUMERIC(20) PRIMARY KEY,
102 URI text NOT NULL
103 );
104 END
105 0 ▶ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return };
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do("\t\t\tCREATE TABLE bnodes (\n\t\t\t\tID NUMERIC(20) PRIMARY KEY,\n\t\t\t\tName text NOT NULL\n\t\t\t);\n") or do { $l->trace($dbh->errstr); $dbh->rollback; return } 0 0 0
106 CREATE TABLE bnodes (
107 ID NUMERIC(20) PRIMARY KEY,
108 Name text NOT NULL
109 );
110 END
111 0 ▶ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); $dbh->rollback; return };
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do("\t\t\tCREATE TABLE models (\n\t\t\t\tID NUMERIC(20) PRIMARY KEY,\n\t\t\t\tName text NOT NULL\n\t\t\t);\n") or do { $l->trace($dbh->errstr); $dbh->rollback; return } 0 0 0
112 CREATE TABLE models (
113 ID NUMERIC(20) PRIMARY KEY,
114 Name text NOT NULL
115 );
116 END
117
118 0 ▶ $dbh->commit or warn $dbh->errstr;
Branch: 1 branch
BranchTrueFalseTotal
$dbh->commit or warn $dbh->errstr 0 0 0
119 }
120
121 0 ▶ unless ($self->_table_exists("statements${id}")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_table_exists("statements$id")) 0 0 0
122 0 ▶ $dbh->do( <<"END" ) || do { $l->trace( $dbh->errstr ); return };
Branch: 1 branch
BranchTrueFalseTotal
$dbh->do("\t\t\tCREATE TABLE statements$id (\n\t\t\t\tSubject NUMERIC(20) NOT NULL,\n\t\t\t\tPredicate NUMERIC(20) NOT NULL,\n\t\t\t\tObject NUMERIC(20) NOT NULL,\n\t\t\t\tContext NUMERIC(20) NOT NULL DEFAULT 0,\n\t\t\t\tPRIMARY KEY (Subject, Predicate, Object, Context)\n\t\t\t);\n") or do { $l->trace($dbh->errstr); return } 0 0 0
123 CREATE TABLE statements${id} (
124 Subject NUMERIC(20) NOT NULL,
125 Predicate NUMERIC(20) NOT NULL,
126 Object NUMERIC(20) NOT NULL,
127 Context NUMERIC(20) NOT NULL DEFAULT 0,
128 PRIMARY KEY (Subject, Predicate, Object, Context)
129 );
130 END
131 # $dbh->do( "DELETE FROM Models WHERE ID = ${id}") || do { $l->trace( $dbh->errstr ); $dbh->rollback; return };
132 0 $dbh->do( "INSERT INTO Models (ID, Name) VALUES (${id}, ?)", undef, $name );
133 }
134
135 }
136  
137  
138 68 1; # Magic true value required at end of module
139 __END__
« RDF/Trine/Parser/Turtle/Lexer.pm ↑ Summary RDF/Trine/Node/Literal.pm »