cequel 1.9.1 → 1.10.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/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +17 -0
- data/lib/cequel/metal/keyspace.rb +4 -0
- data/lib/cequel/record/associations.rb +5 -3
- data/lib/cequel/record/belongs_to_association.rb +4 -1
- data/lib/cequel/version.rb +1 -1
- data/spec/examples/metal/keyspace_spec.rb +12 -0
- data/spec/examples/record/associations_spec.rb +45 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7ff155091be0d5464305a705c0ec81c48f43b63
|
4
|
+
data.tar.gz: 6ddea2f0ae77a64b050cb77d44ead1970b3b1fec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc693f1b953c426aaac6b65d51f5ae7038933d8040efe7272733f809784522a60b5575ff3fb9744f2f69c1a51f9c5348eb7195e9a4149faa1ad6f0a8c827e4ce
|
7
|
+
data.tar.gz: b91aee5ec4d83c483a733cac281d1b1c91ac326f63f3b44a95458707edade557420ffcdcd1cd7018421d02504ea8861e585c0e516ad589c426469014664f1912
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 1.10.0
|
2
|
+
|
3
|
+
* `:foreign_key` option for belongs_to associations
|
4
|
+
([PR 287](https://github.com/cequel/cequel/pull/287))
|
5
|
+
* `:client_compression` option in cequel.yaml
|
6
|
+
([PR 304](https://github.com/cequel/cequel/pull/304))
|
7
|
+
|
1
8
|
## 1.9.1
|
2
9
|
|
3
10
|
* fix dirty checking for timestamps more precise than Cassandra can store
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -83,6 +83,9 @@ The `auto` option for the `key` declaration means Cequel will initialize new
|
|
83
83
|
records with a UUID already generated. This option is only valid for `:uuid` and
|
84
84
|
`:timeuuid` key columns.
|
85
85
|
|
86
|
+
The `belongs_to` association accepts a `:foreign_key` option which allows you to
|
87
|
+
specify the attribute used as the partition key.
|
88
|
+
|
86
89
|
Note that the `belongs_to` declaration must come *before* the `key` declaration.
|
87
90
|
This is because `belongs_to` defines the
|
88
91
|
[partition key](http://www.datastax.com/documentation/cql/3.0/webhelp/index.html#cql/ddl/../../cassandra/glossary/gloss_glossary.html#glossentry_dhv_s24_bk); the `id` column is
|
@@ -382,6 +385,20 @@ Post.consistency(:one).find_each { |post| puts post.title }
|
|
382
385
|
|
383
386
|
Both read and write consistency default to `QUORUM`.
|
384
387
|
|
388
|
+
### Compression ###
|
389
|
+
|
390
|
+
Cassandra supports [frame compression](http://datastax.github.io/ruby-driver/features/#compression),
|
391
|
+
which can give you a performance boost if your requests or responses are big. To enable it you can
|
392
|
+
specify `client_compression` to use in cequel.yaml.
|
393
|
+
|
394
|
+
```yaml
|
395
|
+
development:
|
396
|
+
host: '127.0.0.1'
|
397
|
+
port: 9042
|
398
|
+
keyspace: Blog
|
399
|
+
client_compression: :lz4
|
400
|
+
```
|
401
|
+
|
385
402
|
### ActiveModel Support ###
|
386
403
|
|
387
404
|
Cequel supports ActiveModel functionality, such as callbacks, validations,
|
@@ -32,6 +32,8 @@ module Cequel
|
|
32
32
|
attr_reader :credentials
|
33
33
|
# @return [Hash] SSL Configuration options
|
34
34
|
attr_reader :ssl_config
|
35
|
+
# @return [Symbol] The client compression option
|
36
|
+
attr_reader :client_compression
|
35
37
|
|
36
38
|
#
|
37
39
|
# @!method write(statement, *bind_vars)
|
@@ -139,6 +141,7 @@ module Cequel
|
|
139
141
|
|
140
142
|
@name = configuration[:keyspace]
|
141
143
|
@default_consistency = configuration[:default_consistency].try(:to_sym)
|
144
|
+
@client_compression = configuration[:client_compression].try(:to_sym)
|
142
145
|
|
143
146
|
# reset the connections
|
144
147
|
clear_active_connections!
|
@@ -284,6 +287,7 @@ module Cequel
|
|
284
287
|
{hosts: hosts, port: port}.tap do |options|
|
285
288
|
options.merge!(credentials) if credentials
|
286
289
|
options.merge!(ssl_config) if ssl_config
|
290
|
+
options.merge!(compression: client_compression) if client_compression
|
287
291
|
end
|
288
292
|
end
|
289
293
|
|
@@ -108,14 +108,16 @@ module Cequel
|
|
108
108
|
"belongs_to association must be declared before declaring " \
|
109
109
|
"key(s)"
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
key_options = options.extract!(:partition)
|
113
113
|
|
114
114
|
self.parent_association =
|
115
115
|
BelongsToAssociation.new(self, name.to_sym, options)
|
116
116
|
|
117
|
-
parent_association.association_key_columns.
|
118
|
-
|
117
|
+
parent_association.association_key_columns.each_with_index do |column, i|
|
118
|
+
foreign_key_parts = self.parent_association.foreign_keys
|
119
|
+
foreign_key = foreign_key_parts.any? ? foreign_key_parts[i] : "#{name}_#{column.name}"
|
120
|
+
key foreign_key.to_sym, column.type, key_options
|
119
121
|
end
|
120
122
|
def_parent_association_accessors
|
121
123
|
end
|
@@ -17,6 +17,8 @@ module Cequel
|
|
17
17
|
attr_reader :name
|
18
18
|
# @return [String] name of parent class
|
19
19
|
attr_reader :association_class_name
|
20
|
+
# @return [Array] array of foreign key symbols
|
21
|
+
attr_reader :foreign_keys
|
20
22
|
|
21
23
|
# @!attribute [r] association_key_columns
|
22
24
|
# @return [Array<Schema::Column>] key columns on the parent class
|
@@ -31,8 +33,9 @@ module Cequel
|
|
31
33
|
# @api private
|
32
34
|
#
|
33
35
|
def initialize(owner_class, name, options = {})
|
34
|
-
options.assert_valid_keys(:class_name)
|
36
|
+
options.assert_valid_keys(:class_name, :foreign_key)
|
35
37
|
|
38
|
+
@foreign_keys = Array(options.fetch(:foreign_key, [])).map { |x| x.to_sym }
|
36
39
|
@owner_class, @name = owner_class, name.to_sym
|
37
40
|
@association_class_name =
|
38
41
|
options.fetch(:class_name, @name.to_s.classify)
|
data/lib/cequel/version.rb
CHANGED
@@ -104,6 +104,18 @@ describe Cequel::Metal::Keyspace do
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
+
describe "#client_compression" do
|
108
|
+
let(:client_compression) { :lz4 }
|
109
|
+
let(:connect) do
|
110
|
+
Cequel.connect host: Cequel::SpecSupport::Helpers.host,
|
111
|
+
port: Cequel::SpecSupport::Helpers.port,
|
112
|
+
client_compression: client_compression
|
113
|
+
end
|
114
|
+
it "client compression settings get extracted correctly for sending to cluster" do
|
115
|
+
expect(connect.client_compression).to eq client_compression
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
107
119
|
describe "#execute" do
|
108
120
|
let(:statement) { "SELECT id FROM posts" }
|
109
121
|
|
@@ -186,6 +186,51 @@ describe Cequel::Record::Associations do
|
|
186
186
|
end
|
187
187
|
end
|
188
188
|
|
189
|
+
context 'with foreign_key option' do
|
190
|
+
model :Parent do
|
191
|
+
key :parent_id, :uuid, auto: true
|
192
|
+
column :name, :text
|
193
|
+
has_many :children, class_name: 'Child'
|
194
|
+
end
|
195
|
+
|
196
|
+
model :Child do
|
197
|
+
belongs_to :parent, partition: true, foreign_key: [:parent_id]
|
198
|
+
key :child_id, :uuid, auto: true
|
199
|
+
column :name, :text
|
200
|
+
end
|
201
|
+
|
202
|
+
it "should add parent's keys as first keys" do
|
203
|
+
expect(Child.key_column_names.first(2)).to eq([:parent_id, :child_id])
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should add parent's keys as partition keys" do
|
207
|
+
expect(Child.partition_key_column_names).to eq([:parent_id])
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'with multiple foreign_keys' do
|
211
|
+
model :Foo do
|
212
|
+
key :account_id, :uuid, auto: true
|
213
|
+
key :parent_id, :uuid, auto: true
|
214
|
+
column :name, :text
|
215
|
+
has_many :children, class_name: 'Child'
|
216
|
+
end
|
217
|
+
|
218
|
+
model :Bar do
|
219
|
+
belongs_to :foo, partition: true, foreign_key: [:account_id, :parent_id]
|
220
|
+
key :child_id, :uuid, auto: true
|
221
|
+
column :name, :text
|
222
|
+
end
|
223
|
+
|
224
|
+
it "should add parent's keys as first keys" do
|
225
|
+
expect(Bar.key_column_names).to eq([:account_id, :parent_id, :child_id])
|
226
|
+
end
|
227
|
+
|
228
|
+
it "should add parent's keys as partition keys" do
|
229
|
+
expect(Bar.partition_key_column_names).to eq([:account_id, :parent_id])
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
189
234
|
end
|
190
235
|
|
191
236
|
describe '::has_many' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cequel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mat Brown
|
@@ -29,7 +29,7 @@ authors:
|
|
29
29
|
autorequire:
|
30
30
|
bindir: bin
|
31
31
|
cert_chain: []
|
32
|
-
date: 2016-
|
32
|
+
date: 2016-06-28 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: activemodel
|