line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# mix-in - set package to PG |
2
|
|
|
|
|
|
|
package Class::ReluctantORM::Driver::PostgreSQL; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
6
|
1
|
|
|
1
|
|
6
|
use Class::ReluctantORM::SQL::Aliases; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
101
|
|
7
|
1
|
|
|
1
|
|
660
|
use Class::ReluctantORM::SQL::Function; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
12
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Class::ReluctantORM::Driver::PostgreSQL::Functions - SQL function rendering library |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Provides a set of Functions, and how to render them, for the PostgreSQL driver. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our %FUNCTION_RENDERERS; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @UNARY = ( |
22
|
|
|
|
|
|
|
'NOT', |
23
|
|
|
|
|
|
|
'EXISTS', |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
foreach my $op (@UNARY) { |
26
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{$op} = sub { |
27
|
|
|
|
|
|
|
my $arg = shift; |
28
|
|
|
|
|
|
|
return '(' . $op . ' ' . $arg . ')'; |
29
|
|
|
|
|
|
|
}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
our @INFIX_BINARY = ( |
33
|
|
|
|
|
|
|
'AND', |
34
|
|
|
|
|
|
|
'OR', |
35
|
|
|
|
|
|
|
'=', |
36
|
|
|
|
|
|
|
'<>', |
37
|
|
|
|
|
|
|
'>', |
38
|
|
|
|
|
|
|
'<', |
39
|
|
|
|
|
|
|
'>=', |
40
|
|
|
|
|
|
|
'<=', |
41
|
|
|
|
|
|
|
'IS', |
42
|
|
|
|
|
|
|
'IS NOT', |
43
|
|
|
|
|
|
|
'LIKE', |
44
|
|
|
|
|
|
|
'ILIKE', |
45
|
|
|
|
|
|
|
'IN', # Custom, see below |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
foreach my $op (@INFIX_BINARY) { |
48
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{$op} = sub { |
49
|
|
|
|
|
|
|
my @args = @_; |
50
|
|
|
|
|
|
|
return '(' . $args[0] . " $op " . $args[1] . ')'; |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
our @PREFIX_N_ARY = ( |
57
|
|
|
|
|
|
|
'REPLACE', |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Aggregates are in this catagory, generally |
60
|
|
|
|
|
|
|
'SUM', |
61
|
|
|
|
|
|
|
'MAX', |
62
|
|
|
|
|
|
|
'MIN', |
63
|
|
|
|
|
|
|
'STDDEV', |
64
|
|
|
|
|
|
|
'COUNT', |
65
|
|
|
|
|
|
|
'AVG', |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
foreach my $op (@PREFIX_N_ARY) { |
68
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{$op} = sub { |
69
|
|
|
|
|
|
|
my @args = @_; |
70
|
|
|
|
|
|
|
return "$op(" . join(',', @args) . ')'; |
71
|
|
|
|
|
|
|
}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Completely wierd things go here |
76
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{KEY_COMPOSITOR_OUTSIDE_SUBQUERY} = sub { |
77
|
|
|
|
|
|
|
# This gets passed a list of FK or PK columns (Which have already been rendered) |
78
|
|
|
|
|
|
|
# If only one, should simply return that column |
79
|
|
|
|
|
|
|
my @cols = @_; |
80
|
|
|
|
|
|
|
if (@cols == 1) { |
81
|
|
|
|
|
|
|
return $cols[0]; |
82
|
|
|
|
|
|
|
} else { |
83
|
|
|
|
|
|
|
return '(' . join(',',@cols) . ')'; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
}; |
86
|
|
|
|
|
|
|
$FUNCTION_RENDERERS{KEY_COMPOSITOR_INSIDE_SUBQUERY} = sub { |
87
|
|
|
|
|
|
|
# This gets passed a list of FK or PK columns (Which have already been rendered) |
88
|
|
|
|
|
|
|
# Just return these as a unparanthesized list |
89
|
|
|
|
|
|
|
my @cols = @_; |
90
|
|
|
|
|
|
|
return join(',',@cols); |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my @CUSTOM_FUNCTIONS = ( |
94
|
|
|
|
|
|
|
{ name => 'IN', min_inputs => 2, max_inputs => 2 }, |
95
|
|
|
|
|
|
|
); |
96
|
|
|
|
|
|
|
foreach my $def (@CUSTOM_FUNCTIONS) { |
97
|
|
|
|
|
|
|
my $name = $def->{name}; |
98
|
|
|
|
|
|
|
unless (Function->is_registered($name)) { |
99
|
|
|
|
|
|
|
Function->register(%$def); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |