inquery 1.0.1 → 1.0.2
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 +5 -5
- data/CHANGELOG.md +17 -0
- data/LICENSE +2 -2
- data/README.md +32 -2
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/doc/Inquery.html +4 -4
- data/doc/Inquery/Exceptions.html +3 -3
- data/doc/Inquery/Exceptions/Base.html +3 -3
- data/doc/Inquery/Exceptions/InvalidRelation.html +3 -3
- data/doc/Inquery/Exceptions/UnknownCallSignature.html +3 -3
- data/doc/Inquery/Mixins.html +6 -6
- data/doc/Inquery/Mixins/RawSqlUtils.html +116 -0
- data/doc/Inquery/Mixins/RelationValidation.html +23 -17
- data/doc/Inquery/Mixins/RelationValidation/ClassMethods.html +3 -3
- data/doc/Inquery/Mixins/SchemaValidation.html +3 -3
- data/doc/Inquery/Mixins/SchemaValidation/ClassMethods.html +3 -3
- data/doc/Inquery/Query.html +99 -28
- data/doc/Inquery/Query/Chainable.html +73 -3
- data/doc/_index.html +15 -8
- data/doc/class_list.html +1 -1
- data/doc/css/style.css +10 -6
- data/doc/file.README.html +35 -6
- data/doc/frames.html +1 -1
- data/doc/index.html +35 -6
- data/doc/js/app.js +55 -0
- data/doc/method_list.html +24 -8
- data/doc/top-level-namespace.html +3 -3
- data/inquery.gemspec +8 -8
- data/lib/inquery.rb +1 -0
- data/lib/inquery/mixins/raw_sql_utils.rb +23 -0
- data/lib/inquery/query.rb +7 -0
- data/lib/inquery/query/chainable.rb +5 -0
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fadeb3eebd8e58e36b96cddf25d32dc634de642a68cb967dd1cbaf010b889665
|
4
|
+
data.tar.gz: b468fd644261a3dd7d78f630833677539ab157d96483cfbacc7d16de5d734df0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c19663ecce2ce5f0818ea606b9d07bc6512aff13eb26cb7a979b25dd7ef5db6f077c6f1e6c246b7c85597eab6385beb2d633cecc4bea8381d0145098b992c27
|
7
|
+
data.tar.gz: 28d534d48d02eb0f78e170fecd02b446244ea80ea1f1906001cc21a90681258a319cb85715099c94d402463aa17338ada5d835cb341e20200480f5f97368b44d
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
## 1.0.2 (2019-10-09)
|
4
|
+
|
5
|
+
- Add new mixin `RawSqlUtils`, which provides two methods for
|
6
|
+
`Inquery::Query`:
|
7
|
+
|
8
|
+
- `san`: Sanitizes SQL and performs parameter substitution
|
9
|
+
- `exec_query`: For directly executing SQL queries
|
10
|
+
|
11
|
+
## 1.0.1 (2017-05-17)
|
12
|
+
|
13
|
+
- Pin `schemacop` version properly
|
14
|
+
|
15
|
+
## 1.0.0 (2017-05-16)
|
16
|
+
|
17
|
+
- Initial release
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -87,6 +87,37 @@ FetchRedCarsAsJson.new(params = {}).call
|
|
87
87
|
Note that it's perfectly fine for some queries to return `nil`, i.e. if they're
|
88
88
|
writing queries that don't fetch any results.
|
89
89
|
|
90
|
+
### Using raw SQL
|
91
|
+
|
92
|
+
In some cases it may make sense to push down all computation to the database and
|
93
|
+
only construct an SQL query for this purpose. To facilitate this,
|
94
|
+
{Inquery::Query} provides sanitization and query execution methods:
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
# Note: There are better ways of achieving the same result, this is an example
|
98
|
+
# to demonstrate the methods.
|
99
|
+
class CheckIfSold < Inquery::Query
|
100
|
+
def call
|
101
|
+
parts = [
|
102
|
+
'SELECT car_id FROM dealership_sales',
|
103
|
+
'SELECT car_id FROM dealership_leasings'
|
104
|
+
]
|
105
|
+
|
106
|
+
sql = 'SELECT ? IN (' + parts.join(' UNION ') + ')'
|
107
|
+
|
108
|
+
# The 'san' method takes n+1 arguments: The SQL string and n parameters
|
109
|
+
sanitized_sql = san(sql, osparams.car_id)
|
110
|
+
|
111
|
+
# Returns instance of ActiveRecord::Result
|
112
|
+
return exec_query(sanitized_sql)
|
113
|
+
end
|
114
|
+
|
115
|
+
def process(results)
|
116
|
+
results.rows.first.first
|
117
|
+
end
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
90
121
|
## Chainable queries
|
91
122
|
|
92
123
|
Chainable queries are queries that input and output an Active Record relation.
|
@@ -288,8 +319,7 @@ There are some key benefits to this approach:
|
|
288
319
|
|
289
320
|
Thanks to Jeroen Weeink for his insights regarding using query classes as scopes
|
290
321
|
in his [blog post](http://craftingruby.com/posts/2015/06/29/query-objects-through-scopes.html).
|
291
|
-
And special thanks to [SubGit](http://www.subgit.com/) for their great open source licensing.
|
292
322
|
|
293
323
|
## Copyright
|
294
324
|
|
295
|
-
Copyright (c)
|
325
|
+
Copyright (c) 2019 Sitrox. See `LICENSE` for further details.
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ task :gemspec do
|
|
11
11
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
12
12
|
spec.require_paths = ['lib']
|
13
13
|
|
14
|
-
spec.add_development_dependency 'bundler'
|
14
|
+
spec.add_development_dependency 'bundler'
|
15
15
|
spec.add_development_dependency 'rake'
|
16
16
|
spec.add_development_dependency 'sqlite3'
|
17
17
|
spec.add_development_dependency 'haml'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
data/doc/Inquery.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Inquery
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.20
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -79,7 +79,7 @@
|
|
79
79
|
<dl>
|
80
80
|
<dt>Defined in:</dt>
|
81
81
|
<dd>lib/inquery.rb<span class="defines">,<br />
|
82
|
-
lib/inquery/query.rb,<br /> lib/inquery/exceptions.rb,<br /> lib/inquery/query/chainable.rb,<br /> lib/inquery/mixins/schema_validation.rb,<br /> lib/inquery/mixins/relation_validation.rb</span>
|
82
|
+
lib/inquery/query.rb,<br /> lib/inquery/exceptions.rb,<br /> lib/inquery/query/chainable.rb,<br /> lib/inquery/mixins/raw_sql_utils.rb,<br /> lib/inquery/mixins/schema_validation.rb,<br /> lib/inquery/mixins/relation_validation.rb</span>
|
83
83
|
</dd>
|
84
84
|
</dl>
|
85
85
|
|
@@ -109,9 +109,9 @@
|
|
109
109
|
</div>
|
110
110
|
|
111
111
|
<div id="footer">
|
112
|
-
Generated on Wed
|
112
|
+
Generated on Wed Oct 9 16:20:53 2019 by
|
113
113
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
114
|
-
0.9.
|
114
|
+
0.9.20 (ruby-2.6.2).
|
115
115
|
</div>
|
116
116
|
|
117
117
|
</div>
|
data/doc/Inquery/Exceptions.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Inquery::Exceptions
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.20
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -105,9 +105,9 @@
|
|
105
105
|
</div>
|
106
106
|
|
107
107
|
<div id="footer">
|
108
|
-
Generated on Wed
|
108
|
+
Generated on Wed Oct 9 16:20:53 2019 by
|
109
109
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
110
|
-
0.9.
|
110
|
+
0.9.20 (ruby-2.6.2).
|
111
111
|
</div>
|
112
112
|
|
113
113
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Exception: Inquery::Exceptions::Base
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.20
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -118,9 +118,9 @@
|
|
118
118
|
</div>
|
119
119
|
|
120
120
|
<div id="footer">
|
121
|
-
Generated on Wed
|
121
|
+
Generated on Wed Oct 9 16:20:53 2019 by
|
122
122
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
123
|
-
0.9.
|
123
|
+
0.9.20 (ruby-2.6.2).
|
124
124
|
</div>
|
125
125
|
|
126
126
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Exception: Inquery::Exceptions::InvalidRelation
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.20
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -122,9 +122,9 @@
|
|
122
122
|
</div>
|
123
123
|
|
124
124
|
<div id="footer">
|
125
|
-
Generated on Wed
|
125
|
+
Generated on Wed Oct 9 16:20:53 2019 by
|
126
126
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
127
|
-
0.9.
|
127
|
+
0.9.20 (ruby-2.6.2).
|
128
128
|
</div>
|
129
129
|
|
130
130
|
</div>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Exception: Inquery::Exceptions::UnknownCallSignature
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.20
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -122,9 +122,9 @@
|
|
122
122
|
</div>
|
123
123
|
|
124
124
|
<div id="footer">
|
125
|
-
Generated on Wed
|
125
|
+
Generated on Wed Oct 9 16:20:53 2019 by
|
126
126
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
127
|
-
0.9.
|
127
|
+
0.9.20 (ruby-2.6.2).
|
128
128
|
</div>
|
129
129
|
|
130
130
|
</div>
|
data/doc/Inquery/Mixins.html
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Inquery::Mixins
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.20
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -78,8 +78,8 @@
|
|
78
78
|
|
79
79
|
<dl>
|
80
80
|
<dt>Defined in:</dt>
|
81
|
-
<dd>lib/inquery/mixins/
|
82
|
-
lib/inquery/mixins/relation_validation.rb</span>
|
81
|
+
<dd>lib/inquery/mixins/raw_sql_utils.rb<span class="defines">,<br />
|
82
|
+
lib/inquery/mixins/schema_validation.rb,<br /> lib/inquery/mixins/relation_validation.rb</span>
|
83
83
|
</dd>
|
84
84
|
</dl>
|
85
85
|
|
@@ -89,7 +89,7 @@
|
|
89
89
|
<p class="children">
|
90
90
|
|
91
91
|
|
92
|
-
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Mixins/RelationValidation.html" title="Inquery::Mixins::RelationValidation (module)">RelationValidation</a></span>, <span class='object_link'><a href="Mixins/SchemaValidation.html" title="Inquery::Mixins::SchemaValidation (module)">SchemaValidation</a></span>
|
92
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Mixins/RawSqlUtils.html" title="Inquery::Mixins::RawSqlUtils (module)">RawSqlUtils</a></span>, <span class='object_link'><a href="Mixins/RelationValidation.html" title="Inquery::Mixins::RelationValidation (module)">RelationValidation</a></span>, <span class='object_link'><a href="Mixins/SchemaValidation.html" title="Inquery::Mixins::SchemaValidation (module)">SchemaValidation</a></span>
|
93
93
|
|
94
94
|
|
95
95
|
|
@@ -107,9 +107,9 @@
|
|
107
107
|
</div>
|
108
108
|
|
109
109
|
<div id="footer">
|
110
|
-
Generated on Wed
|
110
|
+
Generated on Wed Oct 9 16:20:53 2019 by
|
111
111
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
112
|
-
0.9.
|
112
|
+
0.9.20 (ruby-2.6.2).
|
113
113
|
</div>
|
114
114
|
|
115
115
|
</div>
|
@@ -0,0 +1,116 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6
|
+
<title>
|
7
|
+
Module: Inquery::Mixins::RawSqlUtils
|
8
|
+
|
9
|
+
— Documentation by YARD 0.9.20
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
pathId = "Inquery::Mixins::RawSqlUtils";
|
19
|
+
relpath = '../../';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
|
23
|
+
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script>
|
24
|
+
|
25
|
+
<script type="text/javascript" charset="utf-8" src="../../js/app.js"></script>
|
26
|
+
|
27
|
+
|
28
|
+
</head>
|
29
|
+
<body>
|
30
|
+
<div class="nav_wrap">
|
31
|
+
<iframe id="nav" src="../../class_list.html?1"></iframe>
|
32
|
+
<div id="resizer"></div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="main" tabindex="-1">
|
36
|
+
<div id="header">
|
37
|
+
<div id="menu">
|
38
|
+
|
39
|
+
<a href="../../_index.html">Index (R)</a> »
|
40
|
+
<span class='title'><span class='object_link'><a href="../../Inquery.html" title="Inquery (module)">Inquery</a></span></span> » <span class='title'><span class='object_link'><a href="../Mixins.html" title="Inquery::Mixins (module)">Mixins</a></span></span>
|
41
|
+
»
|
42
|
+
<span class="title">RawSqlUtils</span>
|
43
|
+
|
44
|
+
</div>
|
45
|
+
|
46
|
+
<div id="search">
|
47
|
+
|
48
|
+
<a class="full_list_link" id="class_list_link"
|
49
|
+
href="../../class_list.html">
|
50
|
+
|
51
|
+
<svg width="24" height="24">
|
52
|
+
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
53
|
+
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
54
|
+
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
55
|
+
</svg>
|
56
|
+
</a>
|
57
|
+
|
58
|
+
</div>
|
59
|
+
<div class="clear"></div>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div id="content"><h1>Module: Inquery::Mixins::RawSqlUtils
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
</h1>
|
67
|
+
<div class="box_info">
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
<dl>
|
73
|
+
<dt>Extended by:</dt>
|
74
|
+
<dd>ActiveSupport::Concern</dd>
|
75
|
+
</dl>
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
<dl>
|
83
|
+
<dt>Included in:</dt>
|
84
|
+
<dd><span class='object_link'><a href="../Query.html" title="Inquery::Query (class)">Query</a></span></dd>
|
85
|
+
</dl>
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
<dl>
|
90
|
+
<dt>Defined in:</dt>
|
91
|
+
<dd>lib/inquery/mixins/raw_sql_utils.rb</dd>
|
92
|
+
</dl>
|
93
|
+
|
94
|
+
</div>
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
</div>
|
107
|
+
|
108
|
+
<div id="footer">
|
109
|
+
Generated on Wed Oct 9 16:20:53 2019 by
|
110
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
111
|
+
0.9.20 (ruby-2.6.2).
|
112
|
+
</div>
|
113
|
+
|
114
|
+
</div>
|
115
|
+
</body>
|
116
|
+
</html>
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<title>
|
7
7
|
Module: Inquery::Mixins::RelationValidation
|
8
8
|
|
9
|
-
— Documentation by YARD 0.9.
|
9
|
+
— Documentation by YARD 0.9.20
|
10
10
|
|
11
11
|
</title>
|
12
12
|
|
@@ -104,23 +104,28 @@
|
|
104
104
|
|
105
105
|
</p>
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
<
|
111
|
-
|
112
|
-
|
113
|
-
|
107
|
+
|
108
|
+
<h2>
|
109
|
+
Constant Summary
|
110
|
+
<small><a href="#" class="constants_summary_toggle">collapse</a></small>
|
111
|
+
</h2>
|
112
|
+
|
113
|
+
<dl class="constants">
|
114
|
+
|
115
|
+
<dt id="OPTIONS_SCHEMA-constant" class="">OPTIONS_SCHEMA =
|
116
|
+
|
117
|
+
</dt>
|
118
|
+
<dd><pre class="code"><span class='const'>Schemacop</span><span class='op'>::</span><span class='const'>Schema</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='kw'>do</span>
|
114
119
|
<span class='id identifier rubyid_opt'>opt</span> <span class='symbol'>:class</span><span class='comma'>,</span> <span class='symbol'>:string</span>
|
115
120
|
<span class='id identifier rubyid_opt'>opt</span> <span class='symbol'>:fields</span><span class='comma'>,</span> <span class='symbol'>:integer</span>
|
116
121
|
<span class='id identifier rubyid_opt'>opt</span> <span class='symbol'>:default_select</span><span class='comma'>,</span> <span class='symbol'>:symbol</span>
|
117
122
|
<span class='id identifier rubyid_opt'>opt</span> <span class='symbol'>:default</span><span class='comma'>,</span> <span class='symbol'>:object</span><span class='comma'>,</span> <span class='label'>classes:</span> <span class='lbracket'>[</span><span class='const'>Proc</span><span class='comma'>,</span> <span class='const'>FalseClass</span><span class='rbracket'>]</span>
|
118
123
|
<span class='kw'>end</span></pre></dd>
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
+
|
125
|
+
<dt id="DEFAULT_OPTIONS-constant" class="">DEFAULT_OPTIONS =
|
126
|
+
|
127
|
+
</dt>
|
128
|
+
<dd><pre class="code"><span class='lbrace'>{</span>
|
124
129
|
<span class='comment'># Allows to restrict the class (attribute `klass`) of the relation. Use
|
125
130
|
</span> <span class='comment'># `nil` to not perform any checks. The `class` attribute will also be
|
126
131
|
</span> <span class='comment'># taken to infer a default if no relation is given and you didn't
|
@@ -145,8 +150,9 @@
|
|
145
150
|
</span> <span class='comment'># behavior.
|
146
151
|
</span> <span class='label'>default_select:</span> <span class='symbol'>:id</span>
|
147
152
|
<span class='rbrace'>}</span></pre></dd>
|
148
|
-
|
149
|
-
|
153
|
+
|
154
|
+
</dl>
|
155
|
+
|
150
156
|
|
151
157
|
|
152
158
|
|
@@ -319,9 +325,9 @@ options specified at class level using the <code>relation</code> method.</p>
|
|
319
325
|
</div>
|
320
326
|
|
321
327
|
<div id="footer">
|
322
|
-
Generated on Wed
|
328
|
+
Generated on Wed Oct 9 16:20:53 2019 by
|
323
329
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
324
|
-
0.9.
|
330
|
+
0.9.20 (ruby-2.6.2).
|
325
331
|
</div>
|
326
332
|
|
327
333
|
</div>
|