parse-stack 1.0.10 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6f0c40c8f93d0487d4f85c4de8c71ac067a5f9f
4
- data.tar.gz: d36ba2fd71de6fc4e15af83d32c8ed7eda024a9f
3
+ metadata.gz: a1138b12b68494580dd0ca427544dc4780a52ddd
4
+ data.tar.gz: f077b1ab3767c747c2257ab5f35539fbab5aa7a7
5
5
  SHA512:
6
- metadata.gz: 99b5d7fe4fa3a9adad714477dd9e857de7fd761e750081acdfd83cee41862d40629640bd8c95e3dec26e654e5e86195f20a4f338df26a997ab2ee9ecd773278d
7
- data.tar.gz: 0c9a75165cc1d90ce634eee97335c55241a7d97fbe156a75416be8483f084f33eb71f0ce945648e73bd1f3de3a1f571fbda51dc787b874ea1ca29de86aea66b2
6
+ metadata.gz: 0c21522c5712cc64b2d7ec0c7842fb42e5514ef86460a8aee92e61238a926bad5f2cc0e9b27545de98fda0f5dfb700a596fad6847fa6b981cdd0e7b49a55c5f0
7
+ data.tar.gz: ab980694c184fb24ed72ad8a9440703d189e98f9cef6c8d6c0ca7dba6760fbc8fcddf5846ebe4aeac0915aa0743d0a95e6a527c5519d503236713db8c1a8b22f
data/Changes.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Parse-Stack Changes
2
2
 
3
+ 1.1
4
+ -----------
5
+ - In Query `join` has been renamed to `matches`.
6
+ - Not In Query `exclude` has been renamed to `excludes` for consistency.
7
+ - Parse::Query now has a `:key` operation to be usd when passing sub-queries to `select` and `matches`
8
+ - Improves query supporting `select`, `matches`, `matches` and `excludes`.
9
+ - Regular expression queries for `like` now send regex options
10
+
3
11
  1.0.10
4
12
  -----------
5
13
  - Fixes issues with setting default values as dirty when using the builder or before_save hook.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parse-stack (1.0.10)
4
+ parse-stack (1.1.0)
5
5
  active_model_serializers (>= 0.9, < 1)
6
6
  activemodel (>= 4, < 5)
7
7
  activesupport (>= 4, < 5)
@@ -14,7 +14,7 @@ PATH
14
14
  GEM
15
15
  remote: https://rubygems.org/
16
16
  specs:
17
- active_model_serializers (0.9.4)
17
+ active_model_serializers (0.9.5)
18
18
  activemodel (>= 3.2)
19
19
  activemodel (4.2.6)
20
20
  activesupport (= 4.2.6)
@@ -30,7 +30,7 @@ GEM
30
30
  builder (3.2.2)
31
31
  coderay (1.1.1)
32
32
  debug_inspector (0.0.2)
33
- dotenv (2.1.0)
33
+ dotenv (2.1.1)
34
34
  faraday (0.9.2)
35
35
  multipart-post (>= 1.2, < 3)
36
36
  faraday_middleware (0.10.0)
@@ -41,7 +41,7 @@ GEM
41
41
  minitest (5.8.4)
42
42
  moneta (0.8.0)
43
43
  multipart-post (2.0.0)
44
- parallel (1.7.0)
44
+ parallel (1.8.0)
45
45
  pry (0.10.3)
46
46
  coderay (~> 1.1.0)
47
47
  method_source (~> 0.8.1)
data/README.md CHANGED
@@ -302,7 +302,11 @@ class Post < Parse::Object
302
302
  property :comment_count, :integer, default: 0
303
303
 
304
304
  # the published date. Maps to "publishDate"
305
- property :publish_date, :date, ->{ DateTime.now }
305
+ property :publish_date, :date, default: ->{ DateTime.now }
306
+
307
+ # use lambda to access the instance object.
308
+ # Set draft_date to the created_at date if empty.
309
+ property :draft_date, :date, default: lambda { |x| x.created_at }
306
310
 
307
311
  # maybe whether it is currently visible
308
312
  property :visible, :boolean
@@ -823,11 +827,11 @@ If you only need to know the result count for a query, provide count a non-zero
823
827
 
824
828
  ```ruby
825
829
  # get number of songs with a play_count > 10
826
- Song.count(:play_count.gt => 10)
830
+ Song.count :play_count.gt => 10
827
831
 
828
832
  # same
829
833
  query = Parse::Query.new("Song")
830
- query.where play_count.gt => 10
834
+ query.where :play_count.gt => 10
831
835
  query.count
832
836
 
833
837
  ```
@@ -862,7 +866,6 @@ When a query API is made, the results are cached in the query object in case you
862
866
 
863
867
  ```
864
868
 
865
-
866
869
  ### Expressions
867
870
  The set of supported expressions based on what is available through the Parse REST API. _For those who don't prefer the DataMapper style syntax, we have provided method accessors for each of the expressions._
868
871
 
@@ -871,11 +874,11 @@ Specify a field to sort by.
871
874
 
872
875
  ```ruby
873
876
  # order updated_at ascending order
874
- Song.all( :order => :updated_at )
877
+ Song.all :order => :updated_at
875
878
 
876
879
  # first order by highest like_count, then by ascending name.
877
880
  # Note that ascending is the default if not specified (ex. `:name.asc`)
878
- Song.all( :order => [:like_count.desc, :name])
881
+ Song.all :order => [:like_count.desc, :name]
879
882
  ```
880
883
 
881
884
  ##### :keys
@@ -883,10 +886,10 @@ Restrict the fields returned by the query. This is useful for larger query resul
883
886
 
884
887
  ```ruby
885
888
  # results only contain :name field
886
- Song.all(:keys => :name)
889
+ Song.all :keys => :name
887
890
 
888
891
  # multiple keys
889
- Song.all(:keys => [:name,:artist])
892
+ Song.all :keys => [:name,:artist]
890
893
  ```
891
894
 
892
895
  ##### :includes
@@ -900,7 +903,7 @@ Use on Pointer columns to return the full object. You may chain multiple columns
900
903
  Song.all(:includes => :artist)
901
904
 
902
905
  # Chaining
903
- Song.all(:includes => [:artist, 'artist.manager'])
906
+ Song.all :includes => [:artist, 'artist.manager']
904
907
 
905
908
  ```
906
909
 
@@ -908,9 +911,9 @@ Use on Pointer columns to return the full object. You may chain multiple columns
908
911
  Limit the number of objects returned by the query. The default is 100, with Parse allowing a maximum of 1000. The framework also allows a value of `:max`. Utilizing this will have the framework continually intelligently utilize `:skip` to continue to paginate through results until an empty result set is received or the `:skip` limit is reached (10,000). When utilizing `all()`, `:max` is the default option for `:limit`.
909
912
 
910
913
  ```ruby
911
- Song.all(:limit => 1) # same as Song.first
912
- Song.all(:limit => 1000) # maximum allowed by Parse
913
- Song.all(:limit => :max) # up to 11,000 records (theoretical).
914
+ Song.all :limit => 1 # same as Song.first
915
+ Song.all :limit => 1000 # maximum allowed by Parse
916
+ Song.all :limit => :max # up to 11,000 records (theoretical).
914
917
  ```
915
918
 
916
919
  ##### :skip
@@ -918,7 +921,7 @@ Use with limit to paginate through results. Default is 0 with maximum value bein
918
921
 
919
922
  ```ruby
920
923
  # get the next 3 songs after the first 10
921
- Song.all(:limit => 3, :skip => 10)
924
+ Song.all :limit => 3, :skip => 10
922
925
  ```
923
926
 
924
927
  ##### :where
@@ -975,18 +978,20 @@ Most of the constraints supported by Parse are available to `Parse::Query`. Assu
975
978
  q.where :field.like => /ruby_regex/
976
979
  q.where :field.regex => /abc/ # alias
977
980
 
978
- # select (TODO: improve API)
979
- q.where :field.select => query
981
+ # select
982
+ q.where :field.select => query #with key
983
+ # ex. q.where :city.select => Artist.where(:total_plays.gt => 50, :key => "city")
980
984
 
981
- # don't select (TODO: improve API)
985
+ # don't select
982
986
  q.where :field.reject => query
983
987
 
984
- # matches inQuery (TODO: improve API)
985
- q.where :field.join => query
988
+ # matches inQuery
989
+ q.where :field.matches => query
986
990
  q.where :field.in_query => query # alias
987
991
 
988
992
  # notInQuery (inverse of `join`)
989
993
  q.where :field.excludes => query
994
+ q.where :field.not_in_query => query # alias
990
995
 
991
996
  # near GeoPoint
992
997
  q.where :field.near => geopoint
@@ -1004,6 +1009,23 @@ Most of the constraints supported by Parse are available to `Parse::Query`. Assu
1004
1009
  or_query = query1 | query2 | query3 ...
1005
1010
  ```
1006
1011
 
1012
+ ## Select and Matching Queries
1013
+ Parse-Stack supports sub-select queries. These are referred to in Parse as `$select` and `$dontSelect` for columns that contain values. These are mapped to `select` and `reject` respectively in Parse-Stack. For creating sub-queries where the column field is an object or a pointer, Parse provides `$inQuery` and `$notInQuery`. These are mapped to `matches` and `excludes` respectively in Parse-Stack. To perform these types of sub-query constraints, you pass a different `Parse::Query` instance to the value of the query constraint. Using the example for `$select` from the Parse documentation where you have a class containing sports teams and you store a user's hometown in the user class, you can issue one query to find the list of users whose hometown teams have winning records as follows:
1014
+
1015
+ ```ruby
1016
+ # assume Team class with column of `city`
1017
+ users = Parse::User.all :hometown.select => Team.where(:win_pct.gt => 0.5, :key => :city )
1018
+ # where={"hometown":{"$select":{"query":{"className":"Team", "limit":100, "where":{"winPct":{"$gt":0.5}}},"key":"city"}}}
1019
+ # for https://api.parse.com/1/classes/_User
1020
+ ```
1021
+
1022
+ Using the `matches` and `excludes`, is similar, but are used when the field is a pointer or object. If you wanted to find all `Song` objects where the song's artist has a `city` of `San Diego` and is `approved`, you could use a `matches` query as follows:
1023
+
1024
+ ```ruby
1025
+ songs = Song.all :artist.matches => Artist.where(approved: true, city: "San Diego", limit: 1000)
1026
+ # where={"artist": {"$inQuery": {"className":"Team", "limit":1000, "where": {"winPct": {"$gt" :0.5 }}}}}
1027
+ ```
1028
+
1007
1029
  ## Hooks and Callbacks
1008
1030
  All `Parse::Object` subclasses extend [`ActiveModel::Callbacks`](http://api.rubyonrails.org/classes/ActiveModel/Callbacks.html) for `#save` and `#destroy` operations. You can setup internal hooks for `before`, `during` and `after`. See
1009
1031
 
data/lib/parse/query.rb CHANGED
@@ -23,7 +23,7 @@ module Parse
23
23
  # You can modify the default client being used by all Parse::Query objects by setting
24
24
  # Parse::Query.client. You can override individual Parse::Query object clients
25
25
  # by changing their client variable to a different Parse::Client object.
26
- attr_accessor :table, :client
26
+ attr_accessor :table, :client, :key
27
27
 
28
28
  # We have a special class method to handle field formatting. This turns
29
29
  # the symbol keys in an operand from one key to another. For example, we can
@@ -109,6 +109,8 @@ module Parse
109
109
  order value
110
110
  elsif expression == :keys
111
111
  keys value
112
+ elsif expression == :key
113
+ @key = value
112
114
  elsif expression == :skip
113
115
  skip value
114
116
  elsif expression == :limit
@@ -197,6 +199,13 @@ module Parse
197
199
  @where ||= []
198
200
  constraint = Parse::Constraint.create operator, value
199
201
  return unless constraint.is_a?(Parse::Constraint)
202
+ # to support select queries where you have to pass a `key` parameter for matching
203
+ # different tables.
204
+ if constraint.operand == :key || constraint.operand == "key"
205
+ @key = constraint.value
206
+ return
207
+ end
208
+
200
209
  unless opts[:filter] == false
201
210
  constraint.operand = Query.format_field(constraint.operand)
202
211
  end
@@ -118,8 +118,14 @@ module Parse
118
118
  d = @value
119
119
  d = { __type: "Date", iso: d.iso8601(3) } if d.respond_to?(:iso8601)
120
120
  d = d.pointer if d.respond_to?(:pointer) #simplified query object
121
+ d = d.to_s if d.is_a?(Regexp)
121
122
  #d = d.pointer if d.is_a?(Parse::Object) #simplified query object
122
- d = d.source if d.is_a?(Regexp)
123
+ # d = d.compile
124
+ if d.is_a?(Parse::Query)
125
+ compiled = d.compile(false)
126
+ compiled["className"] = d.table
127
+ d = compiled
128
+ end
123
129
  d
124
130
  end
125
131
 
@@ -109,13 +109,23 @@ module Parse
109
109
  #This matches a value for a key in the result of a different query
110
110
  contraint_keyword :$select
111
111
  register :select
112
+
113
+ def build
114
+ select_key = @value.key.present? ? @value.key : @operation.operand
115
+ select_query = formatted_value
116
+ { @operation.operand => { key => { query: select_query, key: select_key } } }
117
+ end
112
118
  end
113
119
 
114
120
  class RejectionConstraint < Constraint
115
121
  #requires that a key's value not match a value for a key in the result of a different query
116
122
  contraint_keyword :$dontSelect
117
123
  register :reject
118
-
124
+ def build
125
+ reject_key = @value.key.present? ? @value.key : @operation.operand
126
+ reject_query = formatted_value
127
+ { @operation.operand => { key => { query: reject_query, key: reject_key } } }
128
+ end
119
129
  end
120
130
 
121
131
  class RegularExpressionConstraint < Constraint
@@ -140,16 +150,15 @@ module Parse
140
150
  end
141
151
  end
142
152
 
143
- class JoinQueryConstraint < Constraint
153
+ class InQueryConstraint < Constraint
144
154
  contraint_keyword :$inQuery
145
- register :join
155
+ register :matches
146
156
  register :in_query
147
-
148
157
  end
149
158
 
150
- class DisjointQueryConstraint < Constraint
159
+ class NotInQueryConstraint < Constraint
151
160
  contraint_keyword :$notInQuery
152
- register :exclude
161
+ register :excludes
153
162
  register :not_in_query
154
163
 
155
164
  end
@@ -1,5 +1,5 @@
1
1
  module Parse
2
2
  module Stack
3
- VERSION = "1.0.10"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parse-stack
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Persaud
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-03-25 00:00:00.000000000 Z
12
+ date: 2016-04-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel