datastax_rails 2.0.7 → 2.0.9
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/config/schema.xml.erb +1 -1
- data/lib/datastax_rails/attribute_methods/primary_key.rb +5 -0
- data/lib/datastax_rails/cql/select.rb +3 -2
- data/lib/datastax_rails/cql/update.rb +6 -3
- data/lib/datastax_rails/dynamic_model.rb +30 -17
- data/lib/datastax_rails/persistence.rb +1 -1
- data/lib/datastax_rails/relation/finder_methods.rb +1 -1
- data/lib/datastax_rails/schema/solr.rb +3 -3
- data/lib/datastax_rails/version.rb +1 -1
- data/lib/datastax_rails/wide_storage_model.rb +5 -0
- data/spec/datastax_rails/base_spec.rb +9 -0
- data/spec/datastax_rails/cql/update_spec.rb +2 -2
- data/spec/datastax_rails/dynamic_model_spec.rb +6 -0
- data/spec/datastax_rails/relation/finder_methods_spec.rb +45 -0
- data/spec/dummy/log/test.log +6 -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: 9b54cd8a075c5502c6475725ddafe54fb42e434d
|
|
4
|
+
data.tar.gz: fa5474a8918b6d8fe28fc256039712a196fa4ae7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0236d32acbb3d99c2fa4363b7f6f0bdbbc36fe3ac76d264f086eef30348d91af0ae91f3417492c7c714a95e91f2588aa67173ec33c86b3a29380d3f432875022
|
|
7
|
+
data.tar.gz: 9540c51c831041f33e077adb933b0a0769cb49ef89f584f89191039df80050748eb5bf9a9272b7c41775879a1eb8b510b7b344e9e1f2177ac7436b14b7ddf59f
|
data/config/schema.xml.erb
CHANGED
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
<% else %>
|
|
53
53
|
<field name="<%= field.name %>" type="<%= field.solr_type %>" indexed="<%= field.options[:solr_index] %>" stored="<%= field.options[:solr_store] %>" multiValued="<%= field.options[:multi_valued] %>"/>
|
|
54
54
|
<% if field.solr_type == 'text' && field.options[:sortable] %>
|
|
55
|
-
<field name="sort_<%= field.name %>" type="string" indexed="true" stored="
|
|
55
|
+
<field name="sort_<%= field.name %>" type="string" indexed="true" stored="false" multiValued="false"/>
|
|
56
56
|
<% end %>
|
|
57
57
|
<% end %>
|
|
58
58
|
<% end %>
|
|
@@ -11,6 +11,11 @@ module DatastaxRails
|
|
|
11
11
|
key = self.id
|
|
12
12
|
[key] if key
|
|
13
13
|
end
|
|
14
|
+
|
|
15
|
+
# Returns a primary key hash for updates. Wide models override this.
|
|
16
|
+
def id_for_update
|
|
17
|
+
{self.class.primary_key.to_s => self.id}
|
|
18
|
+
end
|
|
14
19
|
|
|
15
20
|
# Returns the primary key value.
|
|
16
21
|
def id
|
|
@@ -52,11 +52,12 @@ module DatastaxRails#:nodoc:
|
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
@conditions.each do |k,v|
|
|
55
|
-
@values << v
|
|
56
55
|
if v.kind_of?(Array)
|
|
57
|
-
conditions << "\"#{k.to_s}\" IN (?)"
|
|
56
|
+
conditions << "\"#{k.to_s}\" IN (#{('?'*v.size).split(//).join(',')})"
|
|
57
|
+
@values += v
|
|
58
58
|
else
|
|
59
59
|
conditions << "\"#{k.to_s}\" = ?"
|
|
60
|
+
@values << v
|
|
60
61
|
end
|
|
61
62
|
end
|
|
62
63
|
|
|
@@ -51,9 +51,12 @@ module DatastaxRails
|
|
|
51
51
|
|
|
52
52
|
stmt << updates.join(", ")
|
|
53
53
|
end
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
conditions = []
|
|
55
|
+
@key.each do |k,v|
|
|
56
|
+
conditions << "\"#{k.to_s}\" = ?"
|
|
57
|
+
@values << v
|
|
58
|
+
end
|
|
59
|
+
stmt << " WHERE #{conditions.join(" AND ")}"
|
|
57
60
|
stmt.force_encoding('UTF-8')
|
|
58
61
|
end
|
|
59
62
|
end
|
|
@@ -82,7 +82,7 @@ module DatastaxRails
|
|
|
82
82
|
timestamp: :ts_, integer: :i_, float: :f_, uuid: :u_}.with_indifferent_access
|
|
83
83
|
|
|
84
84
|
class_attribute :group_by_attribute
|
|
85
|
-
class_attribute :
|
|
85
|
+
class_attribute :virtual_attributes
|
|
86
86
|
|
|
87
87
|
class << self
|
|
88
88
|
def grouping=(group)
|
|
@@ -95,22 +95,18 @@ module DatastaxRails
|
|
|
95
95
|
|
|
96
96
|
def attribute(name, options)
|
|
97
97
|
options.symbolize_keys!
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
define_method(name) do
|
|
104
|
-
self.send(PREFIXES[options[:type]])[name]
|
|
105
|
-
end
|
|
106
|
-
define_method("#{name.to_s}=") do |val|
|
|
107
|
-
self.send(PREFIXES[options[:type]])[name] = val
|
|
98
|
+
unless [:map,:list,:set].include?(options[:type].to_sym)
|
|
99
|
+
# Only type supported for now
|
|
100
|
+
options.assert_valid_keys(:type)
|
|
101
|
+
raise ArgumentError, "Invalid type specified for dynamic attribute: '#{name}: #{options[:type]}'" unless PREFIXES.has_key?(options[:type])
|
|
102
|
+
self.virtual_attributes[name.to_s] = PREFIXES[options[:type]].to_s + name.to_s
|
|
108
103
|
end
|
|
104
|
+
super
|
|
109
105
|
end
|
|
110
106
|
|
|
111
107
|
def inherited(child)
|
|
112
108
|
super
|
|
113
|
-
child.
|
|
109
|
+
child.virtual_attributes = child.virtual_attributes.nil? ? {}.with_indifferent_access : child.virtual_attributes.dup
|
|
114
110
|
child.column_family = 'dynamic_model'
|
|
115
111
|
child.primary_key = 'id'
|
|
116
112
|
child.cluster_by = 'group'
|
|
@@ -123,11 +119,28 @@ module DatastaxRails
|
|
|
123
119
|
end
|
|
124
120
|
|
|
125
121
|
def solr_field_name(attr, type = nil)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
type ||= self.attribute_definitions[attr].try(:type)
|
|
123
|
+
raise(UnknownAttributeError, "Collections cannot be mapped") if [:map,:list,:set].include?(type)
|
|
124
|
+
raise(UnknownAttributeError, "Unknown attribute: #{attr}. You must specify a type.") unless type
|
|
125
|
+
PREFIXES[type].to_s + attr.to_s
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def write_attribute(attr_name, val)
|
|
130
|
+
if virtual_attributes.include?(attr_name.to_s)
|
|
131
|
+
type = self.class.attribute_definitions[attr_name].type
|
|
132
|
+
self.send(PREFIXES[type])[attr_name] = val
|
|
133
|
+
else
|
|
134
|
+
super
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def read_attribute(attr_name)
|
|
139
|
+
if virtual_attributes.include?(attr_name.to_s)
|
|
140
|
+
type = self.class.attribute_definitions[attr_name].type
|
|
141
|
+
self.send(PREFIXES[type])[attr_name]
|
|
142
|
+
else
|
|
143
|
+
super
|
|
131
144
|
end
|
|
132
145
|
end
|
|
133
146
|
|
|
@@ -107,7 +107,7 @@ module DatastaxRails
|
|
|
107
107
|
if options[:new_record]
|
|
108
108
|
cql.insert.columns(encoded).using(options[:consistency]).execute
|
|
109
109
|
else
|
|
110
|
-
cql.update(record.
|
|
110
|
+
cql.update(record.id_for_update).columns(encoded).using(options[:consistency]).execute
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
113
|
|
|
@@ -190,7 +190,7 @@ module DatastaxRails
|
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
def find_some(ids)
|
|
193
|
-
keys = ids.collect {|id| @klass.attribute_definitions[@klass.primary_key].type_cast(id) || "Couldn't find #{@klass.name} with an invalid ID=#{id}"}
|
|
193
|
+
keys = ids.collect {|id| @klass.attribute_definitions[@klass.primary_key].type_cast(id) || raise(RecordNotFound,"Couldn't find #{@klass.name} with an invalid ID=#{id}")}
|
|
194
194
|
result = with_cassandra.where(@klass.primary_key => keys).all
|
|
195
195
|
|
|
196
196
|
expected_size =
|
|
@@ -106,7 +106,7 @@ module DatastaxRails
|
|
|
106
106
|
end
|
|
107
107
|
break
|
|
108
108
|
end
|
|
109
|
-
DatastaxRails::Cql::Update.new(SchemaMigration, model.column_family).columns(:solrconfig => solrconfig_digest).execute
|
|
109
|
+
DatastaxRails::Cql::Update.new(SchemaMigration, :cf => model.column_family).columns(:solrconfig => solrconfig_digest).execute
|
|
110
110
|
end
|
|
111
111
|
if force || stopwords_digest != sm_digests['stopwords']
|
|
112
112
|
count += 1
|
|
@@ -120,7 +120,7 @@ module DatastaxRails
|
|
|
120
120
|
end
|
|
121
121
|
break
|
|
122
122
|
end
|
|
123
|
-
DatastaxRails::Cql::Update.new(SchemaMigration, model.column_family).columns(:stopwords => stopwords_digest).execute
|
|
123
|
+
DatastaxRails::Cql::Update.new(SchemaMigration, :cf => model.column_family).columns(:stopwords => stopwords_digest).execute
|
|
124
124
|
end
|
|
125
125
|
if force || schema_digest != sm_digests['digest']
|
|
126
126
|
count += 1
|
|
@@ -134,7 +134,7 @@ module DatastaxRails
|
|
|
134
134
|
end
|
|
135
135
|
break
|
|
136
136
|
end
|
|
137
|
-
DatastaxRails::Cql::Update.new(SchemaMigration, model.column_family).columns(:digest => schema_digest).execute
|
|
137
|
+
DatastaxRails::Cql::Update.new(SchemaMigration, :cf => model.column_family).columns(:digest => schema_digest).execute
|
|
138
138
|
newcf ? create_solr_core(model) : reindex_solr(model)
|
|
139
139
|
end
|
|
140
140
|
count
|
|
@@ -24,5 +24,10 @@ module DatastaxRails
|
|
|
24
24
|
# end
|
|
25
25
|
class WideStorageModel < DatastaxRails::Base
|
|
26
26
|
self.abstract_class = true
|
|
27
|
+
|
|
28
|
+
# Returns a primary key hash for updates that includes the cluster key
|
|
29
|
+
def id_for_update
|
|
30
|
+
{self.class.primary_key.to_s => self.id, self.class.cluster_by.to_s => self.read_attribute(self.class.cluster_by.to_s)}
|
|
31
|
+
end
|
|
27
32
|
end
|
|
28
33
|
end
|
|
@@ -18,6 +18,15 @@ describe DatastaxRails::Base do
|
|
|
18
18
|
expect(p1).not_to eq(p2)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
+
it "considers two new objects to be unequal" do
|
|
22
|
+
expect(Person.new).not_to eq(Person.new)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "considers the same object equal to itself" do
|
|
26
|
+
p=Person.new
|
|
27
|
+
expect(p).to eq(p)
|
|
28
|
+
end
|
|
29
|
+
|
|
21
30
|
it "considers two persisted objects to be equal if their primary keys are equal" do
|
|
22
31
|
Person.commit_solr
|
|
23
32
|
p1=Person.create!(:name => 'Jim')
|
|
@@ -6,9 +6,9 @@ describe DatastaxRails::Cql::Update do
|
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
it "should generate valid CQL" do
|
|
9
|
-
cql = DatastaxRails::Cql::Update.new(@model_class, "12345")
|
|
9
|
+
cql = DatastaxRails::Cql::Update.new(@model_class, 'id' => "12345")
|
|
10
10
|
cql.using(DatastaxRails::Cql::Consistency::QUORUM).columns(:name => 'John', :age => '23')
|
|
11
|
-
cql.to_cql.should match(/update users SET ("name" = \?, "age" = \?|"age" = \?, "name" = \?) WHERE id
|
|
11
|
+
cql.to_cql.should match(/update users SET ("name" = \?, "age" = \?|"age" = \?, "name" = \?) WHERE "id" = \?/)
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
it_has_behavior "default_consistency"
|
|
@@ -29,6 +29,12 @@ describe DatastaxRails::DynamicModel do
|
|
|
29
29
|
expect(one.name).to eq('John')
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
+
it "updates an existing attribute" do
|
|
33
|
+
one.save
|
|
34
|
+
one.name = 'Jim'
|
|
35
|
+
expect(one.save).to be_true
|
|
36
|
+
end
|
|
37
|
+
|
|
32
38
|
describe "#solr_field_name" do
|
|
33
39
|
it "maps a attribute name to the underlying storage key" do
|
|
34
40
|
expect(one.solr_field_name(:name)).to eq('s_name')
|
|
@@ -6,6 +6,51 @@ describe DatastaxRails::Relation do
|
|
|
6
6
|
Hobby.commit_solr
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
+
describe "#find" do
|
|
10
|
+
let(:h) {Hobby.create}
|
|
11
|
+
let(:i) {Hobby.create}
|
|
12
|
+
|
|
13
|
+
context "with a single id" do
|
|
14
|
+
context "as a scalar" do
|
|
15
|
+
it "finds the object and returns it as an object" do
|
|
16
|
+
expect(Hobby.find(h.id)).to eq(h)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "raises RecordNotFound for an invalid ID" do
|
|
20
|
+
expect{Hobby.find("asdf")}.to raise_exception(DatastaxRails::RecordNotFound)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "raises RecordNotFound for a nil ID" do
|
|
24
|
+
expect{Hobby.find(nil)}.to raise_exception(DatastaxRails::RecordNotFound)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
context "as an array" do
|
|
29
|
+
it "finds the object and returns it as a single-element array" do
|
|
30
|
+
expect(Hobby.find([h.id])).to eq([h])
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "with multiple ids" do
|
|
36
|
+
it "raises RecordNotFound if any portion of the records could not be found" do
|
|
37
|
+
expect{Hobby.find(h.id, ::Cql::TimeUuid::Generator.new.next)}.to raise_exception(DatastaxRails::RecordNotFound)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "as an array" do
|
|
41
|
+
it "finds the objects and returns them as an array" do
|
|
42
|
+
expect(Hobby.find([h.id, i.id])).to eq([h,i])
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "as discrete parameters" do
|
|
47
|
+
it "finds the objects and returns them as an array" do
|
|
48
|
+
expect(Hobby.find(h.id, i.id)).to eq([h,i])
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
9
54
|
describe "#first" do
|
|
10
55
|
it "should return the first result if records are already loaded" do
|
|
11
56
|
a_record = mock_model(Hobby)
|
data/spec/dummy/log/test.log
CHANGED
|
@@ -15601,3 +15601,9 @@ Connecting to database specified by database.yml
|
|
|
15601
15601
|
Connecting to database specified by database.yml
|
|
15602
15602
|
Connecting to database specified by database.yml
|
|
15603
15603
|
Connecting to database specified by database.yml
|
|
15604
|
+
Error connecting to database
|
|
15605
|
+
the scheme http does not accept registry part: :8983 (or bad hostname?)
|
|
15606
|
+
Reconnecting and retrying
|
|
15607
|
+
Error connecting to database
|
|
15608
|
+
the scheme http does not accept registry part: :8983 (or bad hostname?)
|
|
15609
|
+
Reconnecting and retrying
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: datastax_rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason M. Kusar
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-06-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|