post_json 1.0.5 → 1.0.6

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: d5fb855c51537275da0a59cfda2e1b80bc13a257
4
- data.tar.gz: 4088ddc01020461837ff1b1bfd044c5c1426ed33
3
+ metadata.gz: 96d7ef19a5b074957629924c45a9a71894cc5f97
4
+ data.tar.gz: ca189492fea7bf032db65d2762c852b66c39532b
5
5
  SHA512:
6
- metadata.gz: e5ce9111121f57bd4cbe74ec3bf9ba43704469bbc585abcc004894d47b243749a39cab7744de50d5b389e79c1013116258f418cc53efe5db1054aeb13ca0cad9
7
- data.tar.gz: 6f27d38837491b0cbb3c5e4acf410c52066bdc6f4dbbed8893aae6886b5c22a401497ed8a7cb2cefb79da705fda3244446e84fc65c7fd2635bbca4d69c902793
6
+ metadata.gz: 263da488e04ee6c7dc08aaaed72d21c0802bc3d6ec96aa5575e0519c8945c72c31f20c346e432eaa182cfe8b1b964f5bcd0eeacdca7f02b3d693606ae73cc8d1
7
+ data.tar.gz: b3a221adbf2b1b67c810a0c0b7c76c942ff4f68dc3a3234e75557a7006c07ce49be538560218884085f94ff08e8108a8050464cee7e6b1b35cee78c7edf6d389
data/MIT-LICENSE CHANGED
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -7,7 +7,7 @@ PostJson take full advantage of PostgreSQL 9.2+ support for JavaScript (Google's
7
7
  PostJson, because we love document databases and PostgreSQL. PostJson combine features of Ruby, ActiveRecord and
8
8
  PostgreSQL to provide a great document database.
9
9
 
10
- See example of how we use PostJson as part of Jump...
10
+ See example of how we use PostJson as part of <a href="https://github.com/webnuts/jumpstarter">Jumpstarter</a>.
11
11
 
12
12
 
13
13
  ## Getting started
@@ -105,61 +105,43 @@ Also, __notice you don't have to define model attributes anywhere!__
105
105
 
106
106
  Like you would expect with ActiveRecord.
107
107
 
108
- #### All of the following methods are supported
108
+ 5. Introduction to select and selectors.
109
109
 
110
- except
111
- limit
112
- offset
113
- page(page, per_page) # translate to `offset((page-1)*per_page).limit(per_page)`
114
- only
115
- order
116
- reorder
117
- reverse_order
118
- where
119
-
120
- And ...
121
-
122
- all
123
- any?
124
- blank?
125
- count
126
- delete
127
- delete_all
128
- destroy
129
- destroy_all
130
- empty?
131
- exists?
132
- find
133
- find_by
134
- find_by!
135
- find_each
136
- find_in_batches
137
- first
138
- first!
139
- first_or_create
140
- first_or_initialize
141
- ids
142
- last
143
- load
144
- many?
145
- pluck
146
- select
147
- size
148
- take
149
- take!
150
- to_a
151
- to_sql
152
-
153
-
154
-
155
-
110
+ Sometimes we need a transformed version of documents. This is very easy with `select`
156
111
 
112
+ me = Person.create(name: "Jacob", details: {age: 33})
113
+
114
+ other_me = Person.limit(1).select({name: "name", age: "details.age"}).first
115
+ puts other_me # {name: "Jacob", age: 33}
116
+
117
+ `select` takes a hash as argument and return an array of hashes. The value of each key/value pair in the hash argument is a selector. Selectors can point at attributes at root level, but also nested attributes. Each level of attributes is seperated with a dot (.).
118
+
119
+ 6. Check out the initializer at `config/initializers/post_json.rb`
120
+
121
+ PostJson.setup "people" do |collection|
122
+ collection.record_timestamps = true # default is 'true'
123
+ collection.created_at_attribute_name = "created_at" # default is 'created_at'
124
+ collection.updated_at_attribute_name = "updated_at" # default is 'updated_at'
125
+ collection.include_version_number = true # default is 'true'
126
+ collection.version_attribute_name = "version" # default is 'version'
127
+ collection.use_dynamic_index = true # default is 'true'
128
+ collection.create_dynamic_index_milliseconds_threshold = 50 # default is '50'
129
+ end
130
+
131
+ #### All of the following methods are supported
157
132
 
133
+ all, any?, blank?, count, delete, delete_all, destroy, destroy_all, each, empty?, except, exists?, find, find_by,
134
+ find_by!, find_each, find_in_batches, first, first!, first_or_create, first_or_initialize, ids, last, limit, load,
135
+ many?, offset, only, order, pluck, reorder, reverse_order, select, size, take, take!, to_a, to_sql, and where.
136
+
137
+ We also added `page(page, per_page)`, which translate into `offset((page-1)*per_page).limit(per_page)`.
158
138
 
159
139
  ## Dynamic Indexes
160
140
 
161
- We have created a feature we call `Dynamic Index`. It will automatically create indexes on slow queries, so queries
162
- speed up considerably.
141
+ Most applications do the same queries over and over again. This is why we think it is useful, if PostJson create indexes on slow queries.
142
+
143
+ So we have created a feature we call `Dynamic Index`. It will automatically create indexes on slow queries,
144
+ so queries speed up considerably.
163
145
 
164
146
  PostJson will measure the duration of each `SELECT` query and instruct PostgreSQL to create an Index,
165
147
  if the query duration is above a specified threshold.
@@ -174,6 +156,38 @@ Lets say that you execute the following query and the duration is above the thre
174
156
  PostJson will create (unless it already exists) an Index on `name` behind the scenes. The next time
175
157
  you execute a query with `name` the performance will be much improved.
176
158
 
159
+ You can adjust the settings:
160
+
161
+ class Person < PostJson::Collection["people"]
162
+ self.create_dynamic_index_milliseconds_threshold = 75
163
+ end
164
+
165
+ # Or you can do:
166
+
167
+ PostJson::Collection["people"].create_dynamic_index_milliseconds_threshold = 75
168
+
169
+ # Now indexes are only created if queries are slower than 75 milliseconds.
170
+
171
+
172
+ You might already know this about User Interfaces, but it is usual considered good practice if auto-complete responses are served to the user within 100 milliseconds. Other results are usual okay within 500 milliseconds. So leave room for application processing and network delay.
173
+
174
+ Do not set create_dynamic_index_milliseconds_threshold too low as PostJson will try to create an index for every query performance. Like a threshold of 1 millisecond will be less than almost all query durations.
175
+
176
+ ## The future
177
+
178
+ A few things we will be working on:
179
+ - Versioning of documents with support for history, restore and rollback.
180
+ - Restore a copy of entire collection at a specific date.
181
+ - Copy a collection.
182
+ - Automatic deletion of dynamic indexes when unused for a period of time.
183
+ - Full text search. PostgreSQL has many great features.
184
+ - Bulk import.
185
+ - Support for files. Maybe as attachments to documents.
186
+ - Keep the similarities with ActiveRecord API, but it shouldn't depend on Rails or ActiveRecord.
187
+ - Better performance and less complex code.
188
+
189
+ And please let us know what you think and what you need.
190
+
177
191
  ## Requirements
178
192
 
179
193
  - PostgreSQL 9.2 or 9.3
@@ -187,7 +201,7 @@ PostJson is released under the MIT License. See the MIT-LICENSE file.
187
201
 
188
202
  That's awesome, thank you!
189
203
 
190
- Do you have an idea or suggestion? Please create an issue or send us an e-mail (hello@webnuts.com). We would be happy to implement (if we like the idea) right away.
204
+ Do you have an idea or suggestion? Please create an issue or send us an e-mail (hello@webnuts.com). We would be happy to implement right away.
191
205
 
192
206
  You can also send us a pull request with your contribution.
193
207
 
data/Rakefile CHANGED
@@ -18,4 +18,3 @@ end
18
18
 
19
19
 
20
20
  Bundler::GemHelper.install_tasks
21
-
@@ -1,3 +1,5 @@
1
+ require 'post_json'
2
+
1
3
  # PostJson.setup "people" do |collection|
2
4
  # collection.record_timestamps = true # default is 'true'
3
5
  # collection.created_at_attribute_name = "created_at" # default is 'created_at'
data/lib/post_json.rb CHANGED
@@ -53,4 +53,4 @@ module PostJson
53
53
  end
54
54
  end
55
55
  end
56
- end
56
+ end
@@ -1,3 +1,6 @@
1
+ # Why all the ugly naming you might ask? Well, it will be fixed,
2
+ # but for now it is preventing a conflict with the naming of JSON attributes
3
+
1
4
  module PostJson
2
5
  class Base < ActiveRecord::Base
3
6
  self.abstract_class = true
@@ -1,3 +1,3 @@
1
1
  module PostJson
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: post_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jacob Madsen and Martin Thoegersen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-18 00:00:00.000000000 Z
11
+ date: 2013-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails