pattern_query_helper 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/pattern_query_helper.rb +36 -36
- data/lib/pattern_query_helper/filtering.rb +2 -2
- data/lib/pattern_query_helper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a793c720df496cc279d3d86683056cc0193cd9ce
|
4
|
+
data.tar.gz: 89b26c1e5e760a05d22f8cd99cc4027bf63c6bd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '021168529aaef384c4c32c5d632aebf035a015f15f5f3d7f28fd25225c3829f4b97c41b9ec9b280d203c6dee71e95c3ffd505aad470bb7e84f1b77857df2d131'
|
7
|
+
data.tar.gz: 4193cdd182b61699046e1fd1108eb12815246022aae9eef75a89e0a347625633c06e2cf369bcc5a6dd78142ab7d17017625b2100b975600d6945f9f0f68c4932
|
data/Gemfile.lock
CHANGED
data/lib/pattern_query_helper.rb
CHANGED
@@ -7,23 +7,23 @@ require "pattern_query_helper/sql"
|
|
7
7
|
|
8
8
|
module PatternQueryHelper
|
9
9
|
def self.paginated_sql_query(model, query, query_params, url_params)
|
10
|
-
parse_params(url_params)
|
10
|
+
query_helpers = parse_params(url_params)
|
11
11
|
|
12
12
|
query_config = {
|
13
13
|
model: model,
|
14
14
|
query: query,
|
15
15
|
query_params: query_params,
|
16
|
-
page:
|
17
|
-
per_page:
|
18
|
-
filter_string:
|
19
|
-
filter_params:
|
20
|
-
sort_string:
|
16
|
+
page: query_helpers[:pagination][:page],
|
17
|
+
per_page: query_helpers[:pagination][:per_page],
|
18
|
+
filter_string: query_helpers[:filters][:filter_string],
|
19
|
+
filter_params: query_helpers[:filters][:filter_params],
|
20
|
+
sort_string: query_helpers[:sorting],
|
21
21
|
}
|
22
22
|
|
23
23
|
data = PatternQueryHelper::Sql.sql_query(query_config)
|
24
|
-
data = PatternQueryHelper::Associations.load_associations(data,
|
24
|
+
data = PatternQueryHelper::Associations.load_associations(data, query_helpers[:associations])
|
25
25
|
count = PatternQueryHelper::Sql.sql_query_count(query_config)
|
26
|
-
pagination = PatternQueryHelper::Pagination.create_pagination_payload(count,
|
26
|
+
pagination = PatternQueryHelper::Pagination.create_pagination_payload(count, query_helpers[:pagination])
|
27
27
|
|
28
28
|
{
|
29
29
|
pagination: pagination,
|
@@ -32,19 +32,19 @@ module PatternQueryHelper
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def self.sql_query(model, query, query_params, url_params)
|
35
|
-
parse_params(url_params)
|
35
|
+
query_helpers = parse_params(url_params)
|
36
36
|
|
37
37
|
query_config = {
|
38
38
|
model: model,
|
39
39
|
query: query,
|
40
40
|
query_params: query_params,
|
41
|
-
filter_string:
|
42
|
-
filter_params:
|
43
|
-
sort_string:
|
41
|
+
filter_string: query_helpers[:filters][:filter_string],
|
42
|
+
filter_params: query_helpers[:filters][:filter_params],
|
43
|
+
sort_string: query_helpers[:sorting],
|
44
44
|
}
|
45
45
|
|
46
46
|
data = PatternQueryHelper::Sql.sql_query(query_config)
|
47
|
-
data = PatternQueryHelper::Associations.load_associations(data,
|
47
|
+
data = PatternQueryHelper::Associations.load_associations(data, query_helpers[:associations])
|
48
48
|
|
49
49
|
{
|
50
50
|
data: data
|
@@ -52,19 +52,19 @@ module PatternQueryHelper
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def self.single_record_sql_query(model, query, query_params, url_params)
|
55
|
-
parse_params(url_params)
|
55
|
+
query_helpers = parse_params(url_params)
|
56
56
|
|
57
57
|
query_config = {
|
58
58
|
model: model,
|
59
59
|
query: query,
|
60
60
|
query_params: query_params,
|
61
|
-
filter_string:
|
62
|
-
filter_params:
|
63
|
-
sort_string:
|
61
|
+
filter_string: query_helpers[:filters][:filter_string],
|
62
|
+
filter_params: query_helpers[:filters][:filter_params],
|
63
|
+
sort_string: query_helpers[:sorting],
|
64
64
|
}
|
65
65
|
|
66
66
|
data = PatternQueryHelper::Sql.single_record_query(query_config)
|
67
|
-
data = PatternQueryHelper::Associations.load_associations(data,
|
67
|
+
data = PatternQueryHelper::Associations.load_associations(data, query_helpers[:associations])
|
68
68
|
|
69
69
|
{
|
70
70
|
data: data
|
@@ -72,22 +72,22 @@ module PatternQueryHelper
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def self.active_record_query(active_record_call, url_params)
|
75
|
-
parse_params(url_params)
|
76
|
-
filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call,
|
77
|
-
sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call,
|
78
|
-
with_associations = PatternQueryHelper::Associations.load_associations(sorted_query,
|
75
|
+
query_helpers = parse_params(url_params)
|
76
|
+
filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call, query_helpers[:filters])
|
77
|
+
sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call, query_helpers[:sorting])
|
78
|
+
with_associations = PatternQueryHelper::Associations.load_associations(sorted_query, query_helpers[:associations])
|
79
79
|
{
|
80
80
|
data: with_associations
|
81
81
|
}
|
82
82
|
end
|
83
83
|
|
84
84
|
def self.paginated_active_record_query(active_record_call, url_params)
|
85
|
-
parse_params(url_params)
|
86
|
-
filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call,
|
87
|
-
sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call,
|
88
|
-
paginated_query = PatternQueryHelper::Pagination.paginate_active_record_query(sorted_query,
|
89
|
-
with_associations = PatternQueryHelper::Associations.load_associations(paginated_query,
|
90
|
-
pagination = PatternQueryHelper::Pagination.create_pagination_payload(sorted_query.count,
|
85
|
+
query_helpers = parse_params(url_params)
|
86
|
+
filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call, query_helpers[:filters])
|
87
|
+
sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call, query_helpers[:sorting])
|
88
|
+
paginated_query = PatternQueryHelper::Pagination.paginate_active_record_query(sorted_query, query_helpers[:pagination])
|
89
|
+
with_associations = PatternQueryHelper::Associations.load_associations(paginated_query, query_helpers[:associations])
|
90
|
+
pagination = PatternQueryHelper::Pagination.create_pagination_payload(sorted_query.count, query_helpers[:pagination])
|
91
91
|
{
|
92
92
|
pagination: pagination,
|
93
93
|
data: with_associations
|
@@ -99,16 +99,16 @@ module PatternQueryHelper
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def self.parse_params(params)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
filtering = PatternQueryHelper::Filtering.create_filters(params)
|
103
|
+
sorting = PatternQueryHelper::Sorting.parse_sorting_params(params)
|
104
|
+
associations = PatternQueryHelper::Associations.process_association_params(params)
|
105
|
+
pagination = PatternQueryHelper::Pagination.parse_pagination_params(params)
|
106
106
|
|
107
107
|
{
|
108
|
-
filters:
|
109
|
-
sorting:
|
110
|
-
associations:
|
111
|
-
pagination:
|
108
|
+
filters: filtering,
|
109
|
+
sorting: sorting,
|
110
|
+
associations: associations,
|
111
|
+
pagination: pagination
|
112
112
|
}
|
113
113
|
end
|
114
114
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module PatternQueryHelper
|
2
2
|
class Filtering
|
3
|
-
def self.create_filters(
|
4
|
-
filters
|
3
|
+
def self.create_filters(params, column_map=nil, symbol_prefix="")
|
4
|
+
filters = params[:filter] || {}
|
5
5
|
filter_string = "true = true"
|
6
6
|
filter_params = {}
|
7
7
|
filter_array = []
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pattern_query_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan McDaniel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|