querier 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/querier.rb +11 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb7c5d8fc4b623ae3b146c0bce71b98aa7738d9f
|
4
|
+
data.tar.gz: 1b369a793dfb45726ad8807a4dee7adae275ee0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b3722f19bd382dcb49dd28a289f2e8e7d66ca1546ff7e48da04f3bee3700012575afcde3ccc74a7a9f995b908525d7a2584b34240cd57e5b90649f4919e253b
|
7
|
+
data.tar.gz: 87421d0e984be779a1afcd7ed78766ffcfcba35d8f67da43bddf972a03ff8c374ebfbb2a8f2edc841a6f08957ef1d37724d7282ad700eec0125ad889c7045d0e
|
data/README.md
CHANGED
data/lib/querier.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
class Querier
|
2
|
+
|
2
3
|
PARAM_NAME_INDEX = 0
|
3
4
|
PARAM_VALUE_INDEX = 1
|
5
|
+
|
4
6
|
attr_reader :query_template, :query_params
|
5
7
|
|
6
8
|
def initialize **template_query_params
|
@@ -8,7 +10,7 @@ class Querier
|
|
8
10
|
end
|
9
11
|
|
10
12
|
def execute
|
11
|
-
ActiveRecord::Base.connection.select_all
|
13
|
+
ActiveRecord::Base.connection.select_all fill_query_params(query_template: @query_template, query_params: @query_params)
|
12
14
|
end
|
13
15
|
|
14
16
|
def structured_results
|
@@ -18,22 +20,23 @@ class Querier
|
|
18
20
|
structured_results
|
19
21
|
end
|
20
22
|
|
21
|
-
def to_sanitized_sql
|
22
|
-
to_sql.gsub(/\n/, ' ').gsub(/\t/, ' ')
|
23
|
-
end
|
24
|
-
|
25
23
|
def to_sql
|
26
|
-
|
24
|
+
fill_query_params(query_template: @query_template, query_params: @query_params)
|
27
25
|
end
|
28
26
|
|
29
27
|
private
|
30
28
|
|
31
|
-
def
|
29
|
+
def get_param_value raw_query_param
|
30
|
+
# where's String#quote when we need it?
|
31
|
+
raw_query_param.class.eql?(String) ? "'#{raw_query_param.to_s}'" : raw_query_param.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def fill_query_params query_template:, query_params:
|
32
35
|
query = query_template.dup
|
33
36
|
|
34
37
|
query_params.each do |query_param|
|
35
38
|
query_param_name = query_param[PARAM_NAME_INDEX].to_s
|
36
|
-
query_param_value = query_param[PARAM_VALUE_INDEX]
|
39
|
+
query_param_value = get_param_value(query_param[PARAM_VALUE_INDEX])
|
37
40
|
|
38
41
|
query.gsub! /{\?#{query_param_name}}/, query_param_value
|
39
42
|
end
|