querier 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +1 -0
- data/lib/querier.rb +41 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7a7b74a9aa118493034f4b2827e147680a0fbe6a
|
4
|
+
data.tar.gz: d041de66c3934471ad8a5cf0a5af60d49e3c1330
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e2a1928fe86c5b0ec1b3b1b3593154f4b8f0e8f37914f2d26a1a99886a9e6b04c5efeaef43728388f26b8197cffe1a6c5dd4c348b1b7623bab3a764d5e598bc
|
7
|
+
data.tar.gz: 14b81752ca651fed3364d9a4ed9d3cbbd87173552d30e8e4b2ff1d70e1999d5b5977c67ce53aa1ddf89b7173798110eabc1d8c3de84af7ad20d82d98bda6aada
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# querier
|
data/lib/querier.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
class Querier
|
2
|
+
attr_reader :query_template, :query_params
|
3
|
+
|
4
|
+
def initialize **template_query_params
|
5
|
+
@query_params = template_query_params.dup
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
ActiveRecord::Base.connection.select_all build_query(query_template: @query_template, query_params: @query_params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def structured_results
|
13
|
+
query_results = self.execute
|
14
|
+
structured_results = []
|
15
|
+
query_results.each {|query_result| structured_results << OpenStruct.new(query_result.symbolize_keys!)}
|
16
|
+
structured_results
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_sanitized_sql
|
20
|
+
to_sql.gsub(/\n/, ' ').gsub(/\t/, ' ')
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_sql
|
24
|
+
build_query(query_template: @query_template, query_params: @query_params)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_query query_template:, query_params:
|
30
|
+
query = query_template.dup
|
31
|
+
|
32
|
+
query_params.each do |query_param|
|
33
|
+
query_param_name = query_param[0].to_s
|
34
|
+
query_param_value = query_param[1].to_s
|
35
|
+
|
36
|
+
query.gsub! /{\?#{query_param_name}}/, query_param_value
|
37
|
+
end
|
38
|
+
|
39
|
+
query
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: querier
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gedean Dias
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Active Record queries with variable number of params
|
14
|
+
email: gedean.dias@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- lib/querier.rb
|
21
|
+
homepage: https://github.com/gedean/querier
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.6.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Active Record Querier
|
45
|
+
test_files: []
|