inquery 0.1.0 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +26 -0
  3. data/LICENSE +2 -2
  4. data/README.md +41 -13
  5. data/RUBY_VERSION +1 -1
  6. data/Rakefile +2 -2
  7. data/VERSION +1 -1
  8. data/doc/Inquery.html +7 -7
  9. data/doc/Inquery/Exceptions.html +6 -6
  10. data/doc/Inquery/Exceptions/Base.html +6 -6
  11. data/doc/Inquery/Exceptions/InvalidRelation.html +6 -6
  12. data/doc/Inquery/Exceptions/UnknownCallSignature.html +6 -6
  13. data/doc/Inquery/Mixins.html +9 -9
  14. data/doc/Inquery/Mixins/RawSqlUtils.html +116 -0
  15. data/doc/Inquery/Mixins/RelationValidation.html +40 -36
  16. data/doc/Inquery/Mixins/RelationValidation/ClassMethods.html +12 -12
  17. data/doc/Inquery/Mixins/SchemaValidation.html +6 -6
  18. data/doc/Inquery/Mixins/SchemaValidation/ClassMethods.html +14 -20
  19. data/doc/Inquery/Query.html +105 -34
  20. data/doc/Inquery/Query/Chainable.html +78 -8
  21. data/doc/_index.html +18 -11
  22. data/doc/class_list.html +3 -3
  23. data/doc/css/style.css +12 -8
  24. data/doc/file.README.html +60 -33
  25. data/doc/file_list.html +2 -2
  26. data/doc/frames.html +2 -2
  27. data/doc/index.html +60 -33
  28. data/doc/js/app.js +69 -3
  29. data/doc/method_list.html +26 -10
  30. data/doc/top-level-namespace.html +6 -6
  31. data/inquery.gemspec +11 -11
  32. data/lib/inquery.rb +1 -0
  33. data/lib/inquery/mixins/raw_sql_utils.rb +23 -0
  34. data/lib/inquery/mixins/relation_validation.rb +16 -9
  35. data/lib/inquery/mixins/schema_validation.rb +5 -8
  36. data/lib/inquery/query.rb +9 -2
  37. data/lib/inquery/query/chainable.rb +5 -0
  38. data/test/inquery/query/chainable_test.rb +1 -1
  39. data/test/inquery/query_test.rb +2 -2
  40. data/test/queries/group/filter_with_color.rb +3 -1
  41. data/test/queries/user/fetch_in_group.rb +3 -3
  42. metadata +20 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: aec4e3689d2f6830ee142beb89ef38d8c7e03d65
4
- data.tar.gz: 491f28cd6d7b8335362d77699f0f0c214824b893
2
+ SHA256:
3
+ metadata.gz: 705cf4cd798bece378f6bb8f58f6fe8c4cc8e5175519bff8d292bcb1c718ffa9
4
+ data.tar.gz: 4aad1d32fc5725ad02d1361d351f225304115006fd974f98ea587f2e7e0dcfa7
5
5
  SHA512:
6
- metadata.gz: 9d009ad21e0578929aa49c050210096c6f3d747c9b6aed1ede3ab26d4e4255d7695a0d22ec896b657167cca300642158ecf040cac48f0d3a2c7e8d374aec603f
7
- data.tar.gz: '08ad570e01461f620e959923cc8cbc8083efe08296982f5517ab1e99df22dad1d3b6bb73fe9eba1c68205bacdffb782ab8b4df92538eb568d015d70c3c412ae5'
6
+ metadata.gz: 54ca20f922c48be73d09f88519323a9133837fb621721b3fc7ad4ba68e612df6f1aabcd2343322440d0a6102691bdd29de704b440007168ff068547f20021c5f
7
+ data.tar.gz: 46ddba74947a1c088216e3467a20c0ddf4716e471f4b6f3fab1a96e8b0d5e624bc935bfd4cfbbfc44ac6515dac0380aebfcfae80fff77ae2b7ec70fd83599611
@@ -0,0 +1,26 @@
1
+ # Change log
2
+
3
+ ## 1.0.4 (2020-11-24)
4
+
5
+ - Add support for schemacop 3.x (but still using 2.x schema version)
6
+
7
+ ## 1.0.3 (2020-05-12)
8
+
9
+ - Overwrite parameter hash with the casted version if using
10
+ casting inside the schemacop `schema` block
11
+
12
+ ## 1.0.2 (2019-10-09)
13
+
14
+ - Add new mixin `RawSqlUtils`, which provides two methods for
15
+ `Inquery::Query`:
16
+
17
+ - `san`: Sanitizes SQL and performs parameter substitution
18
+ - `exec_query`: For directly executing SQL queries
19
+
20
+ ## 1.0.1 (2017-05-17)
21
+
22
+ - Pin `schemacop` version properly
23
+
24
+ ## 1.0.0 (2017-05-16)
25
+
26
+ - Initial release
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2016 Sitrox
3
+ Copyright (c) 2020 Sitrox
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -24,9 +24,9 @@ gem 'inquery'
24
24
 
25
25
  ```ruby
26
26
  class FetchUsersWithACar < Inquery::Query
27
- schema(
28
- color: :symbol
29
- )
27
+ schema do
28
+ req :color, :symbol
29
+ end
30
30
 
31
31
  def call
32
32
  User.joins(:cars).where(cars: { color: osparams.color })
@@ -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.
@@ -223,14 +254,12 @@ purpose, Inquery provides the `schema` method witch integrates the
223
254
 
224
255
  ```ruby
225
256
  class SomeQueryClass < Inquery::Query
226
- schema(
227
- some_param: :integer,
228
- some_other_param: {
229
- hash: {
230
- some_field: :string
231
- }
232
- }
233
- )
257
+ schema do
258
+ req :some_param, :integer
259
+ opt :some_other_param, :hash do
260
+ req :some_field, :string
261
+ end
262
+ end
234
263
 
235
264
  # ...
236
265
  end
@@ -290,8 +319,7 @@ There are some key benefits to this approach:
290
319
 
291
320
  Thanks to Jeroen Weeink for his insights regarding using query classes as scopes
292
321
  in his [blog post](http://craftingruby.com/posts/2015/06/29/query-objects-through-scopes.html).
293
- And special thanks to [SubGit](http://www.subgit.com/) for their great open source licensing.
294
322
 
295
323
  ## Copyright
296
324
 
297
- Copyright (c) 2017 Sitrox. See `LICENSE` for further details.
325
+ Copyright (c) 2020 Sitrox. See `LICENSE` for further details.
@@ -1 +1 @@
1
- ruby-2.3.1-p112
1
+ ruby-2.6.2-p47
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', '~> 1.3'
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'
@@ -21,7 +21,7 @@ task :gemspec do
21
21
  spec.add_dependency 'minitest'
22
22
  spec.add_dependency 'activesupport'
23
23
  spec.add_dependency 'activerecord'
24
- spec.add_dependency 'schemacop', '~> 1'
24
+ spec.add_dependency 'schemacop', '>= 2.0'
25
25
  end
26
26
 
27
27
  File.open('inquery.gemspec', 'w') { |f| f.write(gemspec.to_ruby.strip) }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 1.0.4
@@ -6,15 +6,15 @@
6
6
  <title>
7
7
  Module: Inquery
8
8
 
9
- &mdash; Documentation by YARD 0.9.9
9
+ &mdash; Documentation by YARD 0.9.25
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
14
 
15
- <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
16
 
17
- <script type="text/javascript" charset="utf-8">
17
+ <script type="text/javascript">
18
18
  pathId = "Inquery";
19
19
  relpath = '';
20
20
  </script>
@@ -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 Tue May 16 10:49:05 2017 by
112
+ Generated on Tue Nov 24 16:32:43 2020 by
113
113
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
114
- 0.9.9 (ruby-2.3.1).
114
+ 0.9.25 (ruby-2.6.2).
115
115
  </div>
116
116
 
117
117
  </div>
@@ -6,15 +6,15 @@
6
6
  <title>
7
7
  Module: Inquery::Exceptions
8
8
 
9
- &mdash; Documentation by YARD 0.9.9
9
+ &mdash; Documentation by YARD 0.9.25
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" />
14
14
 
15
- <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" />
16
16
 
17
- <script type="text/javascript" charset="utf-8">
17
+ <script type="text/javascript">
18
18
  pathId = "Inquery::Exceptions";
19
19
  relpath = '../';
20
20
  </script>
@@ -105,9 +105,9 @@
105
105
  </div>
106
106
 
107
107
  <div id="footer">
108
- Generated on Tue May 16 10:49:05 2017 by
108
+ Generated on Tue Nov 24 16:32:43 2020 by
109
109
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
110
- 0.9.9 (ruby-2.3.1).
110
+ 0.9.25 (ruby-2.6.2).
111
111
  </div>
112
112
 
113
113
  </div>
@@ -6,15 +6,15 @@
6
6
  <title>
7
7
  Exception: Inquery::Exceptions::Base
8
8
 
9
- &mdash; Documentation by YARD 0.9.9
9
+ &mdash; Documentation by YARD 0.9.25
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
13
+ <link rel="stylesheet" href="../../css/style.css" type="text/css" />
14
14
 
15
- <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
15
+ <link rel="stylesheet" href="../../css/common.css" type="text/css" />
16
16
 
17
- <script type="text/javascript" charset="utf-8">
17
+ <script type="text/javascript">
18
18
  pathId = "Inquery::Exceptions::Base";
19
19
  relpath = '../../';
20
20
  </script>
@@ -118,9 +118,9 @@
118
118
  </div>
119
119
 
120
120
  <div id="footer">
121
- Generated on Tue May 16 10:49:05 2017 by
121
+ Generated on Tue Nov 24 16:32:43 2020 by
122
122
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
123
- 0.9.9 (ruby-2.3.1).
123
+ 0.9.25 (ruby-2.6.2).
124
124
  </div>
125
125
 
126
126
  </div>
@@ -6,15 +6,15 @@
6
6
  <title>
7
7
  Exception: Inquery::Exceptions::InvalidRelation
8
8
 
9
- &mdash; Documentation by YARD 0.9.9
9
+ &mdash; Documentation by YARD 0.9.25
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
13
+ <link rel="stylesheet" href="../../css/style.css" type="text/css" />
14
14
 
15
- <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
15
+ <link rel="stylesheet" href="../../css/common.css" type="text/css" />
16
16
 
17
- <script type="text/javascript" charset="utf-8">
17
+ <script type="text/javascript">
18
18
  pathId = "Inquery::Exceptions::InvalidRelation";
19
19
  relpath = '../../';
20
20
  </script>
@@ -122,9 +122,9 @@
122
122
  </div>
123
123
 
124
124
  <div id="footer">
125
- Generated on Tue May 16 10:49:05 2017 by
125
+ Generated on Tue Nov 24 16:32:43 2020 by
126
126
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
127
- 0.9.9 (ruby-2.3.1).
127
+ 0.9.25 (ruby-2.6.2).
128
128
  </div>
129
129
 
130
130
  </div>
@@ -6,15 +6,15 @@
6
6
  <title>
7
7
  Exception: Inquery::Exceptions::UnknownCallSignature
8
8
 
9
- &mdash; Documentation by YARD 0.9.9
9
+ &mdash; Documentation by YARD 0.9.25
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
13
+ <link rel="stylesheet" href="../../css/style.css" type="text/css" />
14
14
 
15
- <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
15
+ <link rel="stylesheet" href="../../css/common.css" type="text/css" />
16
16
 
17
- <script type="text/javascript" charset="utf-8">
17
+ <script type="text/javascript">
18
18
  pathId = "Inquery::Exceptions::UnknownCallSignature";
19
19
  relpath = '../../';
20
20
  </script>
@@ -122,9 +122,9 @@
122
122
  </div>
123
123
 
124
124
  <div id="footer">
125
- Generated on Tue May 16 10:49:05 2017 by
125
+ Generated on Tue Nov 24 16:32:43 2020 by
126
126
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
127
- 0.9.9 (ruby-2.3.1).
127
+ 0.9.25 (ruby-2.6.2).
128
128
  </div>
129
129
 
130
130
  </div>
@@ -6,15 +6,15 @@
6
6
  <title>
7
7
  Module: Inquery::Mixins
8
8
 
9
- &mdash; Documentation by YARD 0.9.9
9
+ &mdash; Documentation by YARD 0.9.25
10
10
 
11
11
  </title>
12
12
 
13
- <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />
13
+ <link rel="stylesheet" href="../css/style.css" type="text/css" />
14
14
 
15
- <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />
15
+ <link rel="stylesheet" href="../css/common.css" type="text/css" />
16
16
 
17
- <script type="text/javascript" charset="utf-8">
17
+ <script type="text/javascript">
18
18
  pathId = "Inquery::Mixins";
19
19
  relpath = '../';
20
20
  </script>
@@ -78,8 +78,8 @@
78
78
 
79
79
  <dl>
80
80
  <dt>Defined in:</dt>
81
- <dd>lib/inquery/mixins/schema_validation.rb<span class="defines">,<br />
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 Tue May 16 10:49:05 2017 by
110
+ Generated on Tue Nov 24 16:32:43 2020 by
111
111
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
112
- 0.9.9 (ruby-2.3.1).
112
+ 0.9.25 (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
+ &mdash; Documentation by YARD 0.9.25
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="../../css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="../../css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
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> &raquo;
40
+ <span class='title'><span class='object_link'><a href="../../Inquery.html" title="Inquery (module)">Inquery</a></span></span> &raquo; <span class='title'><span class='object_link'><a href="../Mixins.html" title="Inquery::Mixins (module)">Mixins</a></span></span>
41
+ &raquo;
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 Tue Nov 24 16:32:43 2020 by
110
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
111
+ 0.9.25 (ruby-2.6.2).
112
+ </div>
113
+
114
+ </div>
115
+ </body>
116
+ </html>