activerecord-postgres-hstore 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5c1fd061cb95d1132d2674b9e5a3cb7fb5f52787
4
+ data.tar.gz: 23162c6b3a46e204db025686510fd155fc36fc8c
5
+ SHA512:
6
+ metadata.gz: e1ac2b3843f7e9e89bc1f211b8ebb12b66ab6d2d54ee2afe192e8e4d8376597843fded72e9cc2a912cf90933e164384cbd7b57e718fbbc4fd51c9a6a36d7affd
7
+ data.tar.gz: 30dea4ce9d3238e1f488828628f36d12dbdf0dc6124c333af75f5f7ffaca922694dda3c83d93850c1dab9d27e28b79bf65b0a477a22d77e54dbceeab6d398009
@@ -1,6 +1,15 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
6
+ - ruby-head
7
+ - jruby-head
8
+
9
+ # jruby-head sometimes breaks stuff, but it's passing at the moment
10
+ #matrix:
11
+ # allow_failures:
12
+ # - rvm: jruby-head
4
13
 
5
14
  branches:
6
15
  only:
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
- #Goodbye serialize, hello hstore. [![Build Status](https://secure.travis-ci.org/engageis/activerecord-postgres-hstore.png?branch=master)](http://travis-ci.org/engageis/activerecord-postgres-hstore)
1
+ #Goodbye serialize, hello hstore.
2
+
3
+ [![Build Status](https://secure.travis-ci.org/diogob/activerecord-postgres-hstore.png?branch=master)](http://travis-ci.org/diogob/activerecord-postgres-hstore)
4
+ [![Code Climate](https://codeclimate.com/github/diogob/activerecord-postgres-hstore.png)](https://codeclimate.com/github/diogob/activerecord-postgres-hstore)
2
5
 
3
6
  You need dynamic columns in your tables. What do you do?
4
7
 
@@ -6,6 +9,18 @@ You need dynamic columns in your tables. What do you do?
6
9
  * Use a noSQL database just for this issue. Good luck.
7
10
  * Create a serialized column. Nice, insertion will be fine, and reading data from a record too. But, what if you have a condition in your select that includes serialized data? Yeah, regular expressions.
8
11
 
12
+ ##Common use cases
13
+
14
+ Add settings to users, like in rails-settings or HasEasy.
15
+
16
+ ```ruby
17
+ class User < ActiveRecord::Base
18
+ serialize :settings, ActiveRecord::Coders::Hstore
19
+ end
20
+ user = User.create settings: {theme: 'navy'}
21
+ user.settings['theme']
22
+ ```
23
+
9
24
  ##Note about 0.7
10
25
 
11
26
  I have decided to clean up the old code and provide only a custom serializer in this new version.
@@ -62,7 +77,7 @@ Well, not yet. Don’t forget to add indexes. Like this:
62
77
  CREATE INDEX people_gist_data ON people USING GIST(data);
63
78
  ```
64
79
  or
65
- ```sql
80
+ ```sql
66
81
  CREATE INDEX people_gin_data ON people USING GIN(data);
67
82
  ```
68
83
 
@@ -73,7 +88,7 @@ For the model Person we could create an index (defaults to type GIST) over the d
73
88
  class AddIndexToPeople < ActiveRecord::Migration
74
89
  def change
75
90
  add_hstore_index :people, :data
76
- end
91
+ end
77
92
  end
78
93
  ```
79
94
 
@@ -85,7 +100,9 @@ look at [PostgreSQL docs](http://www.postgresql.org/docs/9.2/static/textsearch-i
85
100
  This gem only provides a custom serialization coder.
86
101
  If you want to use it just put in your Gemfile:
87
102
 
88
- gem 'activerecord-postgres-hstore'
103
+ ```ruby
104
+ gem 'activerecord-postgres-hstore'
105
+ ```
89
106
 
90
107
  Now add a line (for each hstore column) on the model you have your hstore columns.
91
108
  Assuming a model called **Person**, with a **data** field on it, the
@@ -99,10 +116,12 @@ end
99
116
 
100
117
  This way, you will automatically start with an empty hash that you can write attributes to.
101
118
 
102
- irb(main):001:0> person = Person.new
103
- => #<Person id: nil, name: nil, data: {}, created_at: nil, updated_at: nil>
104
- irb(main):002:0> person.data['favorite_color'] = 'blue'
105
- => "blue"
119
+ ```ruby
120
+ irb(main):001:0> person = Person.new
121
+ => #<Person id: nil, name: nil, data: {}, created_at: nil, updated_at: nil>
122
+ irb(main):002:0> person.data['favorite_color'] = 'blue'
123
+ => "blue"
124
+ ```
106
125
 
107
126
  ###Querying the database
108
127
 
@@ -110,48 +129,70 @@ Now you just need to learn a little bit of new
110
129
  sqls for selecting stuff (creating and updating is transparent).
111
130
  Find records that contains a key named 'foo’:
112
131
 
113
- Person.where("data ? 'foo'")
132
+ ```ruby
133
+ Person.where("data ? 'foo'")
134
+ ```
114
135
 
115
136
  Find records where 'foo’ is equal to 'bar’:
116
137
 
117
- Person.where("data -> 'foo' = 'bar'")
138
+ ```ruby
139
+ Person.where("data -> 'foo' = 'bar'")
140
+ ```
118
141
 
119
142
  This same sql is at least twice as fast (using indexes) if you do it
120
143
  that way:
121
144
 
122
- Person.where("data @> 'foo=>bar'")
145
+ ```ruby
146
+ Person.where("data @> 'foo=>bar'")
147
+ ```
123
148
 
124
149
  Find records where 'foo’ is not equal to 'bar’:
125
150
 
126
- Person.where("data -> 'foo' <> 'bar'")
151
+ ```ruby
152
+ Person.where("data -> 'foo' <> 'bar'")
153
+ ```
127
154
 
128
155
  Find records where 'foo’ is like 'bar’:
129
156
 
130
- Person.where("data -> 'foo' LIKE '%bar%'")
157
+ ```ruby
158
+ Person.where("data -> 'foo' LIKE '%bar%'")
159
+ ```
131
160
 
132
161
  If you need to delete a key in a record, you can do it that way:
133
162
 
134
- person.destroy_key(:data, :foo)
163
+ ```ruby
164
+ person.destroy_key(:data, :foo)
165
+ ```
135
166
 
136
167
  This way you’ll also save the record:
137
168
 
138
- person.destroy_key!(:data, :foo)
169
+ ```ruby
170
+ person.destroy_key!(:data, :foo)
171
+ ```
139
172
 
140
173
  The destroy\_key method returns 'self’, so you can chain it:
141
174
 
142
- person.destroy_key(:data, :foo).destroy_key(:data, :bar).save
175
+ ```ruby
176
+ person.destroy_key(:data, :foo).destroy_key(:data, :bar).save
177
+ ```
143
178
 
144
179
  But there is a shortcuts for that:
145
180
 
146
- person.destroy_keys(:data, :foo, :bar)
181
+ ```ruby
182
+ person.destroy_keys(:data, :foo, :bar)
183
+ ```
147
184
 
148
185
  And finally, if you need to delete keys in many rows, you can:
149
186
 
150
- Person.delete_key(:data, :foo)
187
+ ```ruby
188
+ Person.delete_key(:data, :foo)
189
+ ```
151
190
 
152
191
  and with many keys:
153
192
 
154
- Person.delete_keys(:data, :foo, :bar)
193
+ ```ruby
194
+ Person.delete_keys(:data, :foo, :bar)
195
+ ```
155
196
 
156
197
  ##Caveats
157
198
 
@@ -159,12 +200,16 @@ hstore keys and values have to be strings. This means `true` will become `"true"
159
200
 
160
201
  It is also confusing when querying:
161
202
 
162
- Person.where("data -> 'foo' = :value", value: true).to_sql
163
- #=> SELECT "people".* FROM "people" WHERE ("data -> 'foo' = 't'") # notice 't'
203
+ ```ruby
204
+ Person.where("data -> 'foo' = :value", value: true).to_sql
205
+ #=> SELECT "people".* FROM "people" WHERE ("data -> 'foo' = 't'") # notice 't'
206
+ ```
164
207
 
165
208
  To avoid the above, make sure all named parameters are strings:
166
209
 
167
- Person.where("data -> 'foo' = :value", value: some_var.to_s)
210
+ ```ruby
211
+ Person.where("data -> 'foo' = :value", value: some_var.to_s)
212
+ ```
168
213
 
169
214
  Have fun.
170
215
 
@@ -174,11 +219,19 @@ To have hstore enabled when you load your database schema (as happens in rake db
174
219
  have two options.
175
220
 
176
221
  The first option is creating a template database with hstore installed and set the template option
177
- in database.yml to that database.
222
+ in database.yml to that database. If you use the template1 database for this you don't even need to
223
+ set the template option, but the extension will be installed in all your databases from now on
224
+ by default. To install the extension in your template1 database you could simply run:
225
+
226
+ ```ruby
227
+ psql -d template1 -c 'create extension hstore;'
228
+ ```
178
229
 
179
230
  The second option is to uncomment or add the following line in config/application.rb
180
231
 
181
- config.active_record.schema_format = :sql
232
+ ```ruby
233
+ config.active_record.schema_format = :sql
234
+ ```
182
235
 
183
236
  This will change your schema dumps from Ruby to SQL. If you're
184
237
  unsure about the implications of this change, we suggest reading this
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.7.6
@@ -4,7 +4,7 @@ $:.unshift lib unless $:.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "activerecord-postgres-hstore"
7
- s.version = "0.7.6"
7
+ s.version = "0.7.7"
8
8
 
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.license = "MIT"
@@ -9,6 +9,9 @@ require 'rails/generators/migration'
9
9
  # * Initialize ActiveRecord properly
10
10
  # * Add hstore:setup generator
11
11
  class Hstore < Rails::Railtie
12
+ rake_tasks do
13
+ load "tasks/hstore.rake"
14
+ end
12
15
 
13
16
  initializer 'activerecord-postgres-hstore' do
14
17
  ActiveSupport.on_load :active_record do
@@ -0,0 +1,7 @@
1
+ namespace :hstore do
2
+ desc "Setup hstore extension into the database"
3
+ task 'setup' do
4
+ ActiveRecord::Base.connection.execute "CREATE EXTENSION IF NOT EXISTS hstore"
5
+ end
6
+ end
7
+ Rake::Task["db:schema:load"].enhance(["hstore:setup"])
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-postgres-hstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
5
- prerelease:
4
+ version: 0.7.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Juan Maiz
@@ -10,92 +9,81 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2013-03-26 00:00:00.000000000 Z
12
+ date: 2013-11-19 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: activerecord
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '3.1'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '3.1'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rake
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '0'
39
35
  type: :runtime
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '0'
47
42
  - !ruby/object:Gem::Dependency
48
43
  name: pg-hstore
49
44
  requirement: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: 1.1.5
55
49
  type: :runtime
56
50
  prerelease: false
57
51
  version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
52
  requirements:
60
- - - ! '>='
53
+ - - '>='
61
54
  - !ruby/object:Gem::Version
62
55
  version: 1.1.5
63
56
  - !ruby/object:Gem::Dependency
64
57
  name: bundler
65
58
  requirement: !ruby/object:Gem::Requirement
66
- none: false
67
59
  requirements:
68
- - - ! '>='
60
+ - - '>='
69
61
  - !ruby/object:Gem::Version
70
62
  version: '0'
71
63
  type: :development
72
64
  prerelease: false
73
65
  version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
66
  requirements:
76
- - - ! '>='
67
+ - - '>='
77
68
  - !ruby/object:Gem::Version
78
69
  version: '0'
79
70
  - !ruby/object:Gem::Dependency
80
71
  name: rdoc
81
72
  requirement: !ruby/object:Gem::Requirement
82
- none: false
83
73
  requirements:
84
- - - ! '>='
74
+ - - '>='
85
75
  - !ruby/object:Gem::Version
86
76
  version: '0'
87
77
  type: :development
88
78
  prerelease: false
89
79
  version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
80
  requirements:
92
- - - ! '>='
81
+ - - '>='
93
82
  - !ruby/object:Gem::Version
94
83
  version: '0'
95
84
  - !ruby/object:Gem::Dependency
96
85
  name: rspec
97
86
  requirement: !ruby/object:Gem::Requirement
98
- none: false
99
87
  requirements:
100
88
  - - ~>
101
89
  - !ruby/object:Gem::Version
@@ -103,7 +91,6 @@ dependencies:
103
91
  type: :development
104
92
  prerelease: false
105
93
  version_requirements: !ruby/object:Gem::Requirement
106
- none: false
107
94
  requirements:
108
95
  - - ~>
109
96
  - !ruby/object:Gem::Version
@@ -130,6 +117,7 @@ files:
130
117
  - lib/activerecord-postgres-hstore/activerecord.rb
131
118
  - lib/activerecord-postgres-hstore/coder.rb
132
119
  - lib/activerecord-postgres-hstore/railties.rb
120
+ - lib/tasks/hstore.rake
133
121
  - lib/templates/setup_hstore.rb
134
122
  - lib/templates/setup_hstore91.rb
135
123
  - spec/activerecord-coders-hstore_spec.rb
@@ -137,26 +125,27 @@ files:
137
125
  homepage: http://github.com/engageis/activerecord-postgres-hstore
138
126
  licenses:
139
127
  - MIT
128
+ metadata: {}
140
129
  post_install_message:
141
130
  rdoc_options: []
142
131
  require_paths:
143
132
  - lib
144
133
  required_ruby_version: !ruby/object:Gem::Requirement
145
- none: false
146
134
  requirements:
147
- - - ! '>='
135
+ - - '>='
148
136
  - !ruby/object:Gem::Version
149
137
  version: 1.8.7
150
138
  required_rubygems_version: !ruby/object:Gem::Requirement
151
- none: false
152
139
  requirements:
153
- - - ! '>='
140
+ - - '>='
154
141
  - !ruby/object:Gem::Version
155
142
  version: 1.3.6
156
143
  requirements: []
157
144
  rubyforge_project:
158
- rubygems_version: 1.8.25
145
+ rubygems_version: 2.0.7
159
146
  signing_key:
160
- specification_version: 3
147
+ specification_version: 4
161
148
  summary: Goodbye serialize, hello hstore
162
- test_files: []
149
+ test_files:
150
+ - spec/activerecord-coders-hstore_spec.rb
151
+ - spec/spec_helper.rb