line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Vue::Crud; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
67320
|
use 5.012; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
7
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
8
|
1
|
|
|
1
|
|
482
|
use parent 'Exporter'; |
|
1
|
|
|
|
|
274
|
|
|
1
|
|
|
|
|
5
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
11
|
|
|
|
|
|
|
# Mojo DBI 版本信息 |
12
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
13
|
|
|
|
|
|
|
our $VERSION = '0.0.6'; |
14
|
|
|
|
|
|
|
our @EXPORT = qw "vue_crud_get vue_crud_query"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
17
|
|
|
|
|
|
|
# 导出函数到外部,用来适配 VUE CRUD 数据结构 -- 模糊查询 postgresql |
18
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
19
|
|
|
|
|
|
|
sub vue_crud_query { |
20
|
|
|
|
|
|
|
# 接收外部入参 - 前端查询变量 和 查询对象 |
21
|
0
|
|
|
0
|
0
|
|
my $params = shift; |
22
|
0
|
|
|
|
|
|
my $table = shift; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# 截取前端哈希长度 |
25
|
0
|
|
|
|
|
|
my $length = scalar( keys %{$params} ); |
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# 获取前端入参 |
28
|
0
|
|
0
|
|
|
|
my $page = $params->{"page"} || 0; |
29
|
0
|
|
0
|
|
|
|
my $size = $params->{"size"} || 10; |
30
|
0
|
|
0
|
|
|
|
my $sort = $params->{"sort"} || "id desc"; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# 提取 query 字段变量 |
33
|
0
|
|
|
|
|
|
my $time = $params->{"create_time"}; |
34
|
0
|
|
|
|
|
|
my @query = grep { !/page|size|sort|create_time/ } ( keys %{$params} ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
my $query_str = $params->{ $query[0] } if @query; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# 处理排序规则 |
38
|
0
|
0
|
|
|
|
|
$sort = join( " ", split( /,/, $sort ) ) if ( $sort =~ /,/ ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# 计算数据偏移量 |
41
|
0
|
|
|
|
|
|
my $offset = $page * $size; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# 初始化 SQL 语句变量 |
44
|
0
|
|
|
|
|
|
my $query_attr = $query[0] . "\\:\\:varchar"; |
45
|
0
|
|
|
|
|
|
my $sql_str = "SELECT * FROM $table"; |
46
|
0
|
|
|
|
|
|
my $count_str = "SELECT count(*) AS count FROM $table"; |
47
|
0
|
|
|
|
|
|
my $order_str = " ORDER BY $sort OFFSET $offset LIMIT $size"; |
48
|
0
|
0
|
|
|
|
|
my $name_str = " WHERE $query_attr LIKE \'%$query_str%\'" if defined $query_str; |
49
|
0
|
0
|
|
|
|
|
my $time_str = " create_time BETWEEN \'$time->[0]\' AND \'$time->[1]\'" if $time; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# 对数据进行判断 |
52
|
0
|
|
|
|
|
|
my ( $rev, $ret, $cnt ); |
53
|
0
|
0
|
|
|
|
|
if ( $length == 3 ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$rev = $sql_str . $order_str; |
55
|
0
|
|
|
|
|
|
$cnt = $count_str; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
elsif ( $length == 4 ) { |
58
|
0
|
0
|
|
|
|
|
if ($name_str) { |
|
|
0
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$rev = $sql_str . $name_str . $order_str; |
60
|
0
|
|
|
|
|
|
$cnt = $count_str . $name_str; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
elsif ($time_str) { |
63
|
0
|
|
|
|
|
|
$rev = $sql_str . " WHERE" . $time_str . $order_str; |
64
|
0
|
|
|
|
|
|
$cnt = $count_str . " WHERE" . $time_str; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
elsif ( $length == 5 ) { |
68
|
0
|
|
|
|
|
|
$rev = $sql_str . $name_str . " AND" . $time_str . $order_str; |
69
|
0
|
|
|
|
|
|
$cnt = $count_str . $name_str . " AND" . $time_str; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# 返回计算结果 |
73
|
0
|
|
|
|
|
|
push @{$ret}, $rev; |
|
0
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
push @{$ret}, $cnt; |
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $ret; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
80
|
|
|
|
|
|
|
# 导出函数到外部,用来适配 VUE CRUD 数据结构 -- 精确匹配 postgresql |
81
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
82
|
|
|
|
|
|
|
sub vue_crud_get { |
83
|
|
|
|
|
|
|
# 接收外部入参 - 前端查询变量 和 查询对象 |
84
|
0
|
|
|
0
|
0
|
|
my $params = shift; |
85
|
0
|
|
|
|
|
|
my $table = shift; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# 截取前端哈希长度 |
88
|
0
|
|
|
|
|
|
my $length = scalar( keys %{$params} ); |
|
0
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# 获取前端入参 |
91
|
0
|
|
0
|
|
|
|
my $page = $params->{"page"} || 0; |
92
|
0
|
|
0
|
|
|
|
my $size = $params->{"size"} || 10; |
93
|
0
|
|
0
|
|
|
|
my $sort = $params->{"sort"} || "id desc"; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# 提取 query 字段变量 |
96
|
0
|
|
|
|
|
|
my $time = $params->{"create_time"}; |
97
|
0
|
|
|
|
|
|
my @query = grep { !/page|size|sort|create_time/ } ( keys %{$params} ); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
98
|
0
|
0
|
|
|
|
|
my $query_str = $params->{ $query[0] } if @query; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# 处理排序规则 |
101
|
0
|
0
|
|
|
|
|
$sort = join( " ", split( /,/, $sort ) ) if ( $sort =~ /,/ ); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# 计算数据偏移量 |
104
|
0
|
|
|
|
|
|
my $offset = $page * $size; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# 初始化 SQL 语句变量 |
107
|
0
|
|
|
|
|
|
my $sql_str = "SELECT * FROM $table"; |
108
|
0
|
|
|
|
|
|
my $count_str = "SELECT count(*) AS count FROM $table"; |
109
|
0
|
|
|
|
|
|
my $order_str = " ORDER BY $sort OFFSET $offset LIMIT $size"; |
110
|
0
|
0
|
|
|
|
|
my $name_str = " WHERE $query[0] = $query_str" if defined $query_str; |
111
|
0
|
0
|
|
|
|
|
my $time_str = " create_time BETWEEN \'$time->[0]\' AND \'$time->[1]\'" if $time; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# 对数据进行判断 |
114
|
0
|
|
|
|
|
|
my ( $rev, $ret, $cnt ); |
115
|
0
|
0
|
|
|
|
|
if ( $length == 3 ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$rev = $sql_str . $order_str; |
117
|
0
|
|
|
|
|
|
$cnt = $count_str; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
elsif ( $length == 4 ) { |
120
|
0
|
0
|
|
|
|
|
if ($name_str) { |
|
|
0
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$rev = $sql_str . $name_str . $order_str; |
122
|
0
|
|
|
|
|
|
$cnt = $count_str . $name_str; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
elsif ($time_str) { |
125
|
0
|
|
|
|
|
|
$rev = $sql_str . " WHERE" . $time_str . $order_str; |
126
|
0
|
|
|
|
|
|
$cnt = $count_str . " WHERE" . $time_str; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
elsif ( $length == 5 ) { |
130
|
0
|
|
|
|
|
|
$rev = $sql_str . $name_str . " AND" . $time_str . $order_str; |
131
|
0
|
|
|
|
|
|
$cnt = $count_str . $name_str . " AND" . $time_str; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# 返回计算结果 |
135
|
0
|
|
|
|
|
|
push @{$ret}, $rev; |
|
0
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
push @{$ret}, $cnt; |
|
0
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
return $ret; |
139
|
0
|
|
|
|
|
|
return $ret; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |