rao-query 0.0.48.pre → 0.0.50.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -3
- data/app/concerns/rao/query/controller/query_concern.rb +3 -3
- data/app/parsers/rao/query/condition_parser.rb +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ce1a4cf9d5cba42dc47127d986e8f07f51b0418c6b946f03cd994295ea3b337
|
4
|
+
data.tar.gz: eccea738821842049daed7f8337f2c6f67bc7500b7cfb067861299211181d8e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e70ba89cf5b845b38ad6742ab7ea1a5e12ef7663229c6127439f3eb67b4c6135d0b7d7e1e658721b7ba870010669f9c2ca659671c21186f16b8fdebfd53c4a00
|
7
|
+
data.tar.gz: d4f5990dc6005abf6a12a77f167095bdc26a2114fd0338e5c314dd064002b3fa5761864d4e2ba9dcf43e6af5105a14d899a6597a54d7af36cc3ef26d3047f9e7
|
data/README.md
CHANGED
@@ -1,10 +1,54 @@
|
|
1
1
|
# Rails Add-Ons Query
|
2
|
-
Short description and motivation.
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
Provides filtering and sorting of collections at controller level. Useful for
|
4
|
+
UIs or APIs that display any collection of records.
|
5
|
+
|
6
|
+
## Basic Usage
|
7
|
+
|
8
|
+
Include the concern in your controller and change you index action to use
|
9
|
+
conditions coming from the query string:
|
10
|
+
|
11
|
+
# app/controllers/posts_controller.rb
|
12
|
+
class PostsController < ApplicationController
|
13
|
+
include Rao::Query::Controller::QueryConcern
|
14
|
+
|
15
|
+
def index
|
16
|
+
@posts = with_conditions_from_query(Post).all
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
### Using limit
|
21
|
+
|
22
|
+
### Using offset
|
23
|
+
|
24
|
+
### Using order
|
25
|
+
|
26
|
+
### Using includes
|
27
|
+
|
28
|
+
The includes parameter is used to eager load associations.
|
29
|
+
|
30
|
+
#### has many
|
31
|
+
|
32
|
+
Assume you have posts that have many comments. You can have the comments
|
33
|
+
included in your query like this:
|
34
|
+
|
35
|
+
http://localhost:3000/posts?includes[]=comments
|
36
|
+
|
37
|
+
## Usage with rao-api-resources_controller
|
38
|
+
|
39
|
+
rao-api_resources_controller comes with support for rao-query. You just have
|
40
|
+
to include the QueryConcern to enable it. There is no need to overwrite the
|
41
|
+
index action:
|
42
|
+
|
43
|
+
# app/controllers/posts_controller.rb
|
44
|
+
class PostsController < Rao::Api::ResourcesController::Base
|
45
|
+
include Rao::Query::Controller::QueryConcern
|
46
|
+
|
47
|
+
#...
|
48
|
+
end
|
6
49
|
|
7
50
|
## Installation
|
51
|
+
|
8
52
|
Add this line to your application's Gemfile:
|
9
53
|
|
10
54
|
```ruby
|
@@ -12,17 +56,21 @@ gem 'rao-query'
|
|
12
56
|
```
|
13
57
|
|
14
58
|
And then execute:
|
59
|
+
|
15
60
|
```bash
|
16
61
|
$ bundle
|
17
62
|
```
|
18
63
|
|
19
64
|
Or install it yourself as:
|
65
|
+
|
20
66
|
```bash
|
21
67
|
$ gem install rao-query
|
22
68
|
```
|
23
69
|
|
24
70
|
## Contributing
|
71
|
+
|
25
72
|
Contribution directions go here.
|
26
73
|
|
27
74
|
## License
|
75
|
+
|
28
76
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -47,11 +47,11 @@ module Rao
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def default_query_params
|
50
|
-
request.query_parameters.except(*
|
50
|
+
request.query_parameters.except(*query_params_exceptions)
|
51
51
|
end
|
52
52
|
|
53
|
-
def
|
54
|
-
Rao::Query::Configuration.default_query_params_exceptions
|
53
|
+
def query_params_exceptions
|
54
|
+
@query_params_exceptions ||= Rao::Query::Configuration.default_query_params_exceptions
|
55
55
|
end
|
56
56
|
|
57
57
|
def normalize_query_params(params)
|
@@ -18,7 +18,7 @@ module Rao
|
|
18
18
|
if operator == 'cont'
|
19
19
|
return ["#{table}.#{column} LIKE ?", "%#{normalized_condition(table, column, condition)}%"]
|
20
20
|
else
|
21
|
-
return ["#{table}.#{column}
|
21
|
+
return ["#{table}.#{column} #{extract_operator(parent_key)} ?", normalized_condition(table, column, condition)]
|
22
22
|
end
|
23
23
|
else
|
24
24
|
if nested
|
@@ -73,7 +73,7 @@ module Rao
|
|
73
73
|
# end
|
74
74
|
|
75
75
|
def extract_table_column_and_operator(string)
|
76
|
-
if string =~ /([\.a-
|
76
|
+
if string =~ /([\.a-z0-9_]{1,})\(([a-z0-9_]{2,})\)/
|
77
77
|
table_and_column = $~[1]
|
78
78
|
operator = $~[2]
|
79
79
|
column, table_or_association = table_and_column.split('.').reverse
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rao-query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.50.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Vasquez Angel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -221,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
221
|
- !ruby/object:Gem::Version
|
222
222
|
version: 1.3.1
|
223
223
|
requirements: []
|
224
|
-
rubygems_version: 3.
|
224
|
+
rubygems_version: 3.4.20
|
225
225
|
signing_key:
|
226
226
|
specification_version: 4
|
227
227
|
summary: Simple Filter Queries for Ruby on Rails.
|