line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Sandy::DB; |
2
|
|
|
|
|
|
|
# ABSTRACT: Singleton class to manage database |
3
|
|
|
|
|
|
|
|
4
|
6
|
|
|
6
|
|
42
|
use App::Sandy::Base; |
|
6
|
|
|
|
|
152
|
|
|
6
|
|
|
|
|
48
|
|
5
|
6
|
|
|
6
|
|
2447
|
use App::Sandy::DB::Schema; |
|
6
|
|
|
|
|
23
|
|
|
6
|
|
|
|
|
255
|
|
6
|
6
|
|
|
6
|
|
3204
|
use MooseX::Singleton; |
|
6
|
|
|
|
|
183885
|
|
|
6
|
|
|
|
|
29
|
|
7
|
6
|
|
|
6
|
|
230431
|
use Path::Class 'file'; |
|
6
|
|
|
|
|
180461
|
|
|
6
|
|
|
|
|
1942
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.22'; # VERSION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'schema' => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => 'App::Sandy::DB::Schema', |
14
|
|
|
|
|
|
|
builder => '_build_schema', |
15
|
|
|
|
|
|
|
lazy_build => 1, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _build_schema { |
19
|
0
|
|
|
0
|
|
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Hardcoded paths for database |
22
|
0
|
|
|
|
|
|
my $DB = 'db.sqlite3'; |
23
|
0
|
|
|
|
|
|
my @DB_PATH = ( |
24
|
|
|
|
|
|
|
file(__FILE__)->dir->parent->parent->parent->file('share', 'assets'), |
25
|
|
|
|
|
|
|
file(__FILE__)->dir->parent->parent->file('auto', 'share', 'dist', 'App-Sandy') |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# The chosen one |
29
|
0
|
|
|
|
|
|
my $db; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
for my $path (@DB_PATH) { |
32
|
|
|
|
|
|
|
# The chosen one |
33
|
0
|
|
|
|
|
|
my $file = file($path, $DB); |
34
|
0
|
0
|
|
|
|
|
if (-f $file) { |
35
|
0
|
|
|
|
|
|
$db = $file; |
36
|
0
|
|
|
|
|
|
last; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
die "$DB not found in @DB_PATH" unless defined $db; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
return App::Sandy::DB::Schema->connect( |
43
|
|
|
|
|
|
|
"dbi:SQLite:$db", |
44
|
|
|
|
|
|
|
"", |
45
|
|
|
|
|
|
|
"", |
46
|
|
|
|
|
|
|
{ |
47
|
|
|
|
|
|
|
RaiseError => 1, |
48
|
|
|
|
|
|
|
PrintError => 0, |
49
|
|
|
|
|
|
|
on_connect_do => 'PRAGMA foreign_keys = ON' |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
__END__ |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=pod |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=encoding UTF-8 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 NAME |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
App::Sandy::DB - Singleton class to manage database |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 VERSION |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
version 0.22 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 AUTHORS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=over 4 |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item * |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Thiago L. A. Miller <tmiller@mochsl.org.br> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item * |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
J. Leonel Buzzo <lbuzzo@mochsl.org.br> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=item * |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Felipe R. C. dos Santos <fsantos@mochsl.org.br> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item * |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Helena B. Conceição <hconceicao@mochsl.org.br> |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item * |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Gabriela Guardia <gguardia@mochsl.org.br> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=item * |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Fernanda Orpinelli <forpinelli@mochsl.org.br> |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item * |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Pedro A. F. Galante <pgalante@mochsl.org.br> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=back |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This software is Copyright (c) 2018 by Teaching and Research Institute from SÃrio-Libanês Hospital. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is free software, licensed under: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |