sessionm-cassandra_object 4.0.3 → 4.0.4
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/Gemfile +1 -1
- data/Gemfile.lock +21 -25
- data/lib/cassandra_object/adapters/cassandra_driver.rb +11 -1
- data/lib/cassandra_object/base.rb +10 -0
- data/lib/cassandra_object/finder_methods.rb +35 -10
- data/lib/cassandra_object/relation.rb +4 -0
- data/lib/cassandra_object.rb +1 -0
- data/sessionm-cassandra_object.gemspec +1 -1
- data/spec/cassandra_object/associations_spec.rb +3 -0
- data/spec/support/db/migrate/001_create_test_tables.rb +6 -0
- data/spec/support/models/role.rb +3 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8c817cbeb631838baf909acfbf6b5bebdc5d5d9
|
4
|
+
data.tar.gz: e6e953e9e94ef1b572ab08ce513d15e2fea99db8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 743af911cfb055f00414fa4cd156fdfec15bd43318cf9e8d2495474b5e13a3b7e05f07836822b1b7ef07441bae395f1b18dc70f98bc3fdc1daba22d88928f128
|
7
|
+
data.tar.gz: cc93690d7f0d979642c7adc867eeb1254dadc8633979957f86dfb5cb2e701d2ce86a923422e297c7639d0a3f5637469b2988f1b6c7cfbdcdba437af374318889
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (4.2.
|
5
|
-
activesupport (= 4.2.
|
4
|
+
activemodel (4.2.2)
|
5
|
+
activesupport (= 4.2.2)
|
6
6
|
builder (~> 3.1)
|
7
|
-
activerecord (4.2.
|
8
|
-
activemodel (= 4.2.
|
9
|
-
activesupport (= 4.2.
|
7
|
+
activerecord (4.2.2)
|
8
|
+
activemodel (= 4.2.2)
|
9
|
+
activesupport (= 4.2.2)
|
10
10
|
arel (~> 6.0)
|
11
|
-
activesupport (4.2.
|
11
|
+
activesupport (4.2.2)
|
12
12
|
i18n (~> 0.7)
|
13
13
|
json (~> 1.7, >= 1.7.7)
|
14
14
|
minitest (~> 5.1)
|
@@ -22,30 +22,26 @@ GEM
|
|
22
22
|
diff-lcs (1.2.5)
|
23
23
|
i18n (0.7.0)
|
24
24
|
ione (1.2.0)
|
25
|
-
json (1.8.
|
26
|
-
macaddr (1.6.1)
|
27
|
-
systemu (~> 2.5.0)
|
25
|
+
json (1.8.3)
|
28
26
|
metaclass (0.0.4)
|
29
|
-
minitest (5.
|
27
|
+
minitest (5.7.0)
|
30
28
|
mocha (1.1.0)
|
31
29
|
metaclass (~> 0.0.1)
|
32
30
|
mysql2 (0.3.18)
|
33
|
-
rspec (3.
|
34
|
-
rspec-core (~> 3.
|
35
|
-
rspec-expectations (~> 3.
|
36
|
-
rspec-mocks (~> 3.
|
37
|
-
rspec-core (3.
|
38
|
-
rspec-support (~> 3.
|
39
|
-
rspec-expectations (3.
|
31
|
+
rspec (3.3.0)
|
32
|
+
rspec-core (~> 3.3.0)
|
33
|
+
rspec-expectations (~> 3.3.0)
|
34
|
+
rspec-mocks (~> 3.3.0)
|
35
|
+
rspec-core (3.3.1)
|
36
|
+
rspec-support (~> 3.3.0)
|
37
|
+
rspec-expectations (3.3.0)
|
40
38
|
diff-lcs (>= 1.2.0, < 2.0)
|
41
|
-
rspec-support (~> 3.
|
42
|
-
rspec-mocks (3.
|
39
|
+
rspec-support (~> 3.3.0)
|
40
|
+
rspec-mocks (3.3.1)
|
43
41
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
-
rspec-support (~> 3.
|
45
|
-
rspec-support (3.
|
46
|
-
simple_uuid (0.
|
47
|
-
macaddr (= 1.6.1)
|
48
|
-
systemu (2.5.2)
|
42
|
+
rspec-support (~> 3.3.0)
|
43
|
+
rspec-support (3.3.0)
|
44
|
+
simple_uuid (0.4.0)
|
49
45
|
thread_safe (0.3.5)
|
50
46
|
tzinfo (1.2.2)
|
51
47
|
thread_safe (~> 0.1)
|
@@ -61,4 +57,4 @@ DEPENDENCIES
|
|
61
57
|
mocha
|
62
58
|
mysql2
|
63
59
|
rspec
|
64
|
-
simple_uuid
|
60
|
+
simple_uuid
|
@@ -35,8 +35,14 @@ module CassandraObject
|
|
35
35
|
}
|
36
36
|
end
|
37
37
|
|
38
|
+
class SchemaCache < ActiveRecord::ConnectionAdapters::SchemaCache
|
39
|
+
def columns_hash(table_name)
|
40
|
+
@columns_hash[table_name] ||= {'id' => 'id'}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
38
44
|
# The client class acts like the old cassandra gem
|
39
|
-
class Client
|
45
|
+
class Client < ActiveRecord::ConnectionAdapters::AbstractAdapter
|
40
46
|
attr_reader :session, :cluster
|
41
47
|
|
42
48
|
KEY_FIELD = 'key'
|
@@ -158,6 +164,10 @@ module CassandraObject
|
|
158
164
|
def has_table?(name)
|
159
165
|
self.cluster.keyspace(session.keyspace).has_table? name
|
160
166
|
end
|
167
|
+
|
168
|
+
def schema_cache
|
169
|
+
@schema_cache ||= SchemaCache.new(self)
|
170
|
+
end
|
161
171
|
end
|
162
172
|
end
|
163
173
|
end
|
@@ -10,10 +10,12 @@ module CassandraObject
|
|
10
10
|
def column_family=(column_family)
|
11
11
|
@column_family = column_family
|
12
12
|
end
|
13
|
+
alias table_name= column_family=
|
13
14
|
|
14
15
|
def column_family
|
15
16
|
@column_family || name.pluralize
|
16
17
|
end
|
18
|
+
alias table_name column_family
|
17
19
|
|
18
20
|
def base_class
|
19
21
|
klass = self
|
@@ -26,6 +28,14 @@ module CassandraObject
|
|
26
28
|
def compute_type(*args)
|
27
29
|
ActiveRecord::Base.send :compute_type, *args
|
28
30
|
end
|
31
|
+
|
32
|
+
def primary_key
|
33
|
+
'id'
|
34
|
+
end
|
35
|
+
|
36
|
+
def columns_hash
|
37
|
+
connection.schema_cache.columns_hash table_name
|
38
|
+
end
|
29
39
|
end
|
30
40
|
|
31
41
|
extend ActiveModel::Naming
|
@@ -48,22 +48,47 @@ module CassandraObject
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
def all(options
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
51
|
+
def all(options={})
|
52
|
+
CassandraObject::Relation.new(self, self.arel_table, options)
|
53
|
+
end
|
54
|
+
|
55
|
+
def first(options=nil)
|
56
|
+
result = CassandraObject::Base.with_connection(nil, :read) do
|
57
|
+
ActiveSupport::Notifications.instrument("get_range.cassandra_object", column_family: column_family, key_count: 1) do
|
58
|
+
connection.get_range(column_family, key_count: 1, consistency: thrift_read_consistency)
|
59
|
+
end
|
60
|
+
end.first
|
61
|
+
|
62
|
+
result ? instantiate(result[0], result[1]) : nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def find_by_sql(arel, bind_values)
|
66
|
+
if bind_values.size == 0
|
67
|
+
limit = 100
|
68
|
+
results = CassandraObject::Base.with_connection(nil, :read) do
|
69
|
+
ActiveSupport::Notifications.instrument("get_range.cassandra_object", column_family: column_family, key_count: limit) do
|
70
|
+
connection.get_range(column_family, key_count: limit, consistency: thrift_read_consistency)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
return results.map do |k, v|
|
75
|
+
v.empty? ? nil : instantiate(k, v)
|
76
|
+
end.compact
|
77
|
+
elsif bind_values.size == 1
|
78
|
+
if bind_values[0][0] == 'id' && bind_values[0][1].is_a?(String)
|
79
|
+
return [find_by_id(bind_values[0][1])]
|
80
|
+
elsif bind_values[0][:id]
|
81
|
+
return [find_by_id(bind_values[0][:id])]
|
56
82
|
end
|
57
83
|
end
|
58
84
|
|
59
|
-
|
60
|
-
v.empty? ? nil : instantiate(k, v)
|
61
|
-
end.compact
|
85
|
+
raise "only supports lookups by id currently bind_values #{bind_values}"
|
62
86
|
end
|
63
87
|
|
64
|
-
def
|
65
|
-
|
88
|
+
def unscoped
|
89
|
+
CassandraObject::Relation.new(self, self.arel_table, {})
|
66
90
|
end
|
91
|
+
alias current_scope unscoped
|
67
92
|
|
68
93
|
def find_with_ids(*ids)
|
69
94
|
expects_array = ids.first.kind_of?(Array)
|
data/lib/cassandra_object.rb
CHANGED
@@ -11,6 +11,9 @@ describe CassandraObject::Associations do
|
|
11
11
|
it "should fetch the cassandra object from the belongs_to relationship from an active record object" do
|
12
12
|
issue = Issue.create! :description => 'web site not working', :worth => 1.5
|
13
13
|
user = User.create! :position => 1, :issue_id => issue.id
|
14
|
+
role = Role.create! :name => 'admin', :user_id => user.id
|
15
|
+
|
16
|
+
expect(role.user.id).to eq user.id
|
14
17
|
expect(user.issue.id).to eq issue.id
|
15
18
|
end
|
16
19
|
end
|
@@ -4,9 +4,15 @@ class CreateTestTables < ActiveRecord::Migration
|
|
4
4
|
t.string :issue_id
|
5
5
|
t.integer :position
|
6
6
|
end
|
7
|
+
|
8
|
+
create_table :roles do |t|
|
9
|
+
t.string :name
|
10
|
+
t.integer :user_id
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
14
|
def self.down
|
10
15
|
drop_table :users
|
16
|
+
drop_table :roles
|
11
17
|
end
|
12
18
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sessionm-cassandra_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Koziarski
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-06-25 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Cassandra ActiveModel
|
16
16
|
email: doug@sessionm.com
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/cassandra_object/nested_attributes.rb
|
69
69
|
- lib/cassandra_object/persistence.rb
|
70
70
|
- lib/cassandra_object/railtie.rb
|
71
|
+
- lib/cassandra_object/relation.rb
|
71
72
|
- lib/cassandra_object/row_ttl.rb
|
72
73
|
- lib/cassandra_object/schema.rb
|
73
74
|
- lib/cassandra_object/schema/migration.rb
|
@@ -102,6 +103,7 @@ files:
|
|
102
103
|
- spec/support/db/migrate/001_create_test_tables.rb
|
103
104
|
- spec/support/models/counter.rb
|
104
105
|
- spec/support/models/issue.rb
|
106
|
+
- spec/support/models/role.rb
|
105
107
|
- spec/support/models/user.rb
|
106
108
|
- test/README
|
107
109
|
- test/active_model_test.rb
|
@@ -159,6 +161,7 @@ test_files:
|
|
159
161
|
- spec/support/db/migrate/001_create_test_tables.rb
|
160
162
|
- spec/support/models/counter.rb
|
161
163
|
- spec/support/models/issue.rb
|
164
|
+
- spec/support/models/role.rb
|
162
165
|
- spec/support/models/user.rb
|
163
166
|
- test/README
|
164
167
|
- test/active_model_test.rb
|