query_helper 0.1.8 → 0.2.0
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 +4 -10
- data/lib/query_helper.rb +3 -3
- data/lib/query_helper/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd74e8f24a4e6841f6bc0049c4cc729366114be762ccd79e065153dd356149ff
|
4
|
+
data.tar.gz: 7cd75d322863e367a0e623a1bc6f2fdc25ce397bd77352a32b4332e294f5711e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5ded16d1e131486949a1e5fb50622da80c1f0706fb4e1c466de98a0f631f2a7942baa90b44f6f666196c4aa711b317e86781edb79150c65a27c7fb6b83ac469
|
7
|
+
data.tar.gz: e481b684c397d872c9d0f1e383078f2f127f3eb0dc7a9c34f3eef3aac341849890322f5bff0a7f3d31a42dcec6d9c5cf2ba5988655e6a01de5da07712d10a0d3
|
data/README.md
CHANGED
@@ -35,7 +35,7 @@ Adding this code creates a `QueryHelper` object preloaded with pagination, filte
|
|
35
35
|
|
36
36
|
### Step 2: Use QueryHelper to run active record and sql queries within your controller
|
37
37
|
|
38
|
-
####
|
38
|
+
#### Raw SQL Example
|
39
39
|
|
40
40
|
```ruby
|
41
41
|
class ResourceController < ApplicationController
|
@@ -53,26 +53,20 @@ class ResourceController < ApplicationController
|
|
53
53
|
end
|
54
54
|
```
|
55
55
|
|
56
|
-
####
|
56
|
+
#### ActiveRecord Example
|
57
57
|
|
58
58
|
```ruby
|
59
59
|
class ResourceController < ApplicationController
|
60
60
|
|
61
61
|
def index
|
62
|
-
@query_helper.query
|
62
|
+
@query_helper.update(query: Resource.all)
|
63
63
|
render json: @query_helper.results()
|
64
64
|
end
|
65
65
|
|
66
66
|
end
|
67
67
|
```
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
```ruby
|
72
|
-
@query_helper.update(
|
73
|
-
query: Resource.all
|
74
|
-
)
|
75
|
-
```
|
69
|
+
*NOTE: Previous documentation stated you could simply run `@query_helper.query = Resource.all`. While this method still works, it will evaluate the ActiveRecord query causing it to hit the database twice. It is recommended that you always use the update method to avoid this inefficiency*
|
76
70
|
|
77
71
|
### Step 3: Paginate, Sort, Filter, and Include Associations using URL params
|
78
72
|
|
data/lib/query_helper.rb
CHANGED
@@ -32,7 +32,7 @@ class QueryHelper
|
|
32
32
|
preload: [] # preload activerecord associations - used instead of `associations` when you don't want them included in the payload
|
33
33
|
)
|
34
34
|
@query = query.class < ActiveRecord::Relation ? query.to_sql : query
|
35
|
-
@model = query.class < ActiveRecord::Relation ? query.
|
35
|
+
@model = query.class < ActiveRecord::Relation ? query.base_class : model
|
36
36
|
@bind_variables = bind_variables
|
37
37
|
@sql_filter = sql_filter
|
38
38
|
@sql_sort = sql_sort
|
@@ -67,7 +67,7 @@ class QueryHelper
|
|
67
67
|
preload: []
|
68
68
|
)
|
69
69
|
@query = query.class < ActiveRecord::Relation ? query.to_sql : query if query
|
70
|
-
@model = query.class < ActiveRecord::Relation ? query.
|
70
|
+
@model = query.class < ActiveRecord::Relation ? query.base_class : model if model || query
|
71
71
|
@bind_variables.merge!(bind_variables)
|
72
72
|
filters.each{ |f| add_filter(**f) }
|
73
73
|
@associations = @associations | associations
|
@@ -85,7 +85,7 @@ class QueryHelper
|
|
85
85
|
def query=(value)
|
86
86
|
if value.class < ActiveRecord::Relation
|
87
87
|
@query = value.to_sql
|
88
|
-
@model = value.
|
88
|
+
@model = value.base_class
|
89
89
|
else
|
90
90
|
@query = value
|
91
91
|
end
|
data/lib/query_helper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2019-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|