adapter-cassanity 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog.md +5 -0
- data/lib/adapter/cassanity.rb +3 -9
- data/lib/adapter/cassanity/version.rb +1 -1
- data/spec/cassanity_spec.rb +62 -54
- data/spec/helper.rb +0 -15
- metadata +4 -4
data/Changelog.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.5.0
|
4
|
+
|
5
|
+
* Drop support for composite primary keys.
|
6
|
+
* Force supplying primary_key for adapter rather than reflecting from schema. Since cassanity has migrations, it is no longer needed to always supply schema. Easier to pass primary key and more performant than reflecting from the database like AR does.
|
7
|
+
|
3
8
|
## 0.3.0
|
4
9
|
|
5
10
|
* Updates for adapter 0.7.0.
|
data/lib/adapter/cassanity.rb
CHANGED
@@ -6,8 +6,6 @@ module Adapter
|
|
6
6
|
module Cassanity
|
7
7
|
extend Forwardable
|
8
8
|
|
9
|
-
def_delegator :@client, :schema
|
10
|
-
|
11
9
|
# Public
|
12
10
|
def read(key, options = nil)
|
13
11
|
operation_options = {where: where(key)}
|
@@ -42,13 +40,9 @@ module Adapter
|
|
42
40
|
end
|
43
41
|
|
44
42
|
# Private
|
45
|
-
def where(
|
46
|
-
|
47
|
-
|
48
|
-
else
|
49
|
-
primary_key = schema.primary_keys.first
|
50
|
-
{primary_key => criteria}
|
51
|
-
end
|
43
|
+
def where(key)
|
44
|
+
primary_key = @options.fetch(:primary_key)
|
45
|
+
{primary_key => key}
|
52
46
|
end
|
53
47
|
|
54
48
|
# Private
|
data/spec/cassanity_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe "Cassanity adapter" do
|
|
6
6
|
context "single primary key" do
|
7
7
|
before do
|
8
8
|
@client = COLUMN_FAMILIES[:single]
|
9
|
-
@adapter = Adapter[adapter_name].new(@client)
|
9
|
+
@adapter = Adapter[adapter_name].new(@client, primary_key: :some_key)
|
10
10
|
@adapter.clear
|
11
11
|
end
|
12
12
|
|
@@ -19,7 +19,7 @@ describe "Cassanity adapter" do
|
|
19
19
|
context "default read consistency" do
|
20
20
|
it "is :quorum" do
|
21
21
|
client = COLUMN_FAMILIES[:single]
|
22
|
-
adapter = Adapter[adapter_name].new(client)
|
22
|
+
adapter = Adapter[adapter_name].new(client, primary_key: :some_key,)
|
23
23
|
|
24
24
|
client.should_receive(:select).with({
|
25
25
|
where: {:some_key => 'foo'},
|
@@ -33,7 +33,7 @@ describe "Cassanity adapter" do
|
|
33
33
|
context "default write consistency" do
|
34
34
|
it "is :quorum" do
|
35
35
|
client = COLUMN_FAMILIES[:single]
|
36
|
-
adapter = Adapter[adapter_name].new(client)
|
36
|
+
adapter = Adapter[adapter_name].new(client, primary_key: :some_key,)
|
37
37
|
|
38
38
|
client.should_receive(:update).with({
|
39
39
|
set: {'name' => 'New Name'},
|
@@ -48,7 +48,7 @@ describe "Cassanity adapter" do
|
|
48
48
|
context "default delete consistency" do
|
49
49
|
it "is :quorum" do
|
50
50
|
client = COLUMN_FAMILIES[:single]
|
51
|
-
adapter = Adapter[adapter_name].new(client)
|
51
|
+
adapter = Adapter[adapter_name].new(client, primary_key: :some_key)
|
52
52
|
|
53
53
|
client.should_receive(:delete).with({
|
54
54
|
where: {:some_key => 'foo'},
|
@@ -62,9 +62,12 @@ describe "Cassanity adapter" do
|
|
62
62
|
context "with adapter read options" do
|
63
63
|
it "uses read options for read method" do
|
64
64
|
client = COLUMN_FAMILIES[:single]
|
65
|
-
options = {
|
66
|
-
|
67
|
-
|
65
|
+
options = {
|
66
|
+
primary_key: :some_key,
|
67
|
+
read: {
|
68
|
+
using: {consistency: :one},
|
69
|
+
},
|
70
|
+
}
|
68
71
|
adapter = Adapter[adapter_name].new(client, options)
|
69
72
|
|
70
73
|
client.should_receive(:select).with({
|
@@ -77,10 +80,13 @@ describe "Cassanity adapter" do
|
|
77
80
|
|
78
81
|
it "does not override where" do
|
79
82
|
client = COLUMN_FAMILIES[:single]
|
80
|
-
options = {
|
81
|
-
|
82
|
-
|
83
|
-
|
83
|
+
options = {
|
84
|
+
primary_key: :some_key,
|
85
|
+
read: {
|
86
|
+
where: {:some_key => 'bar'},
|
87
|
+
using: {consistency: :one},
|
88
|
+
},
|
89
|
+
}
|
84
90
|
adapter = Adapter[adapter_name].new(client, options)
|
85
91
|
|
86
92
|
client.should_receive(:select).with({
|
@@ -93,9 +99,12 @@ describe "Cassanity adapter" do
|
|
93
99
|
|
94
100
|
it "can be overriden by read method options" do
|
95
101
|
client = COLUMN_FAMILIES[:single]
|
96
|
-
options = {
|
97
|
-
|
98
|
-
|
102
|
+
options = {
|
103
|
+
primary_key: :some_key,
|
104
|
+
read: {
|
105
|
+
using: {consistency: :one},
|
106
|
+
},
|
107
|
+
}
|
99
108
|
adapter = Adapter[adapter_name].new(client, options)
|
100
109
|
|
101
110
|
client.should_receive(:select).with({
|
@@ -110,9 +119,12 @@ describe "Cassanity adapter" do
|
|
110
119
|
context "with adapter write options" do
|
111
120
|
it "uses write options for write method" do
|
112
121
|
client = COLUMN_FAMILIES[:single]
|
113
|
-
options = {
|
114
|
-
|
115
|
-
|
122
|
+
options = {
|
123
|
+
primary_key: :some_key,
|
124
|
+
write: {
|
125
|
+
using: {consistency: :one},
|
126
|
+
},
|
127
|
+
}
|
116
128
|
adapter = Adapter[adapter_name].new(client, options)
|
117
129
|
|
118
130
|
client.should_receive(:update).with({
|
@@ -126,11 +138,14 @@ describe "Cassanity adapter" do
|
|
126
138
|
|
127
139
|
it "does not override where or set" do
|
128
140
|
client = COLUMN_FAMILIES[:single]
|
129
|
-
options = {
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
141
|
+
options = {
|
142
|
+
primary_key: :some_key,
|
143
|
+
write: {
|
144
|
+
where: {:some_key => 'should not use this'},
|
145
|
+
set: {'name' => 'should not use this'},
|
146
|
+
using: {consistency: :one}
|
147
|
+
},
|
148
|
+
}
|
134
149
|
adapter = Adapter[adapter_name].new(client, options)
|
135
150
|
|
136
151
|
client.should_receive(:update).with({
|
@@ -144,9 +159,12 @@ describe "Cassanity adapter" do
|
|
144
159
|
|
145
160
|
it "can be overriden by write method options" do
|
146
161
|
client = COLUMN_FAMILIES[:single]
|
147
|
-
options = {
|
148
|
-
|
149
|
-
|
162
|
+
options = {
|
163
|
+
primary_key: :some_key,
|
164
|
+
write: {
|
165
|
+
using: {consistency: :one},
|
166
|
+
},
|
167
|
+
}
|
150
168
|
adapter = Adapter[adapter_name].new(client, options)
|
151
169
|
|
152
170
|
client.should_receive(:update).with({
|
@@ -162,9 +180,12 @@ describe "Cassanity adapter" do
|
|
162
180
|
context "with adapter delete options" do
|
163
181
|
it "uses delete options for delete method" do
|
164
182
|
client = COLUMN_FAMILIES[:single]
|
165
|
-
options = {
|
166
|
-
|
167
|
-
|
183
|
+
options = {
|
184
|
+
primary_key: :some_key,
|
185
|
+
delete: {
|
186
|
+
using: {consistency: :one},
|
187
|
+
},
|
188
|
+
}
|
168
189
|
adapter = Adapter[adapter_name].new(client, options)
|
169
190
|
|
170
191
|
client.should_receive(:delete).with({
|
@@ -177,10 +198,13 @@ describe "Cassanity adapter" do
|
|
177
198
|
|
178
199
|
it "does not override where" do
|
179
200
|
client = COLUMN_FAMILIES[:single]
|
180
|
-
options = {
|
181
|
-
|
182
|
-
|
183
|
-
|
201
|
+
options = {
|
202
|
+
primary_key: :some_key,
|
203
|
+
delete: {
|
204
|
+
where: {:some_key => 'bar'},
|
205
|
+
using: {consistency: :one},
|
206
|
+
},
|
207
|
+
}
|
184
208
|
adapter = Adapter[adapter_name].new(client, options)
|
185
209
|
|
186
210
|
client.should_receive(:delete).with({
|
@@ -193,9 +217,12 @@ describe "Cassanity adapter" do
|
|
193
217
|
|
194
218
|
it "can be overriden by delete method options" do
|
195
219
|
client = COLUMN_FAMILIES[:single]
|
196
|
-
options = {
|
197
|
-
|
198
|
-
|
220
|
+
options = {
|
221
|
+
primary_key: :some_key,
|
222
|
+
delete: {
|
223
|
+
using: {consistency: :one},
|
224
|
+
},
|
225
|
+
}
|
199
226
|
adapter = Adapter[adapter_name].new(client, options)
|
200
227
|
|
201
228
|
client.should_receive(:delete).with({
|
@@ -206,23 +233,4 @@ describe "Cassanity adapter" do
|
|
206
233
|
adapter.delete('foo', using: {consistency: :one})
|
207
234
|
end
|
208
235
|
end
|
209
|
-
|
210
|
-
context "composite primary key" do
|
211
|
-
before do
|
212
|
-
@client = COLUMN_FAMILIES[:composite]
|
213
|
-
@adapter = Adapter[adapter_name].new(@client)
|
214
|
-
@adapter.clear
|
215
|
-
end
|
216
|
-
|
217
|
-
it_behaves_like 'an adapter' do
|
218
|
-
let(:adapter) { @adapter }
|
219
|
-
let(:client) { @client }
|
220
|
-
|
221
|
-
let(:key) { {:bucket => '1', :id => CassandraCQL::UUID.new} }
|
222
|
-
let(:key2) { {:bucket => '2', :id => CassandraCQL::UUID.new} }
|
223
|
-
|
224
|
-
let(:unavailable_key) { {:bucket => '3', :id => CassandraCQL::UUID.new} }
|
225
|
-
let(:unavailable_key2) { {:bucket => '4', :id => CassandraCQL::UUID.new} }
|
226
|
-
end
|
227
|
-
end
|
228
236
|
end
|
data/spec/helper.rb
CHANGED
@@ -43,22 +43,7 @@ cassandra_setup = lambda { |args|
|
|
43
43
|
}),
|
44
44
|
})
|
45
45
|
|
46
|
-
COLUMN_FAMILIES[:composite] = keyspace.column_family(:composite, {
|
47
|
-
schema: Cassanity::Schema.new({
|
48
|
-
primary_key: [:bucket, :id],
|
49
|
-
columns: {
|
50
|
-
bucket: :text,
|
51
|
-
id: :timeuuid,
|
52
|
-
one: :text,
|
53
|
-
two: :text,
|
54
|
-
three: :text,
|
55
|
-
four: :text,
|
56
|
-
}
|
57
|
-
}),
|
58
|
-
})
|
59
|
-
|
60
46
|
COLUMN_FAMILIES[:single].create
|
61
|
-
COLUMN_FAMILIES[:composite].create
|
62
47
|
}
|
63
48
|
|
64
49
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adapter-cassanity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-04-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: adapter
|
@@ -83,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
segments:
|
85
85
|
- 0
|
86
|
-
hash:
|
86
|
+
hash: 242222650800770136
|
87
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
88
|
none: false
|
89
89
|
requirements:
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
segments:
|
94
94
|
- 0
|
95
|
-
hash:
|
95
|
+
hash: 242222650800770136
|
96
96
|
requirements: []
|
97
97
|
rubyforge_project:
|
98
98
|
rubygems_version: 1.8.23
|