sessionm-cassandra_object 4.0.6 → 4.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 539bceeb4486ffdd621cb72f76d716f870f4e18a
4
- data.tar.gz: 45e22b538f31d1c1657be029fac182f8e16b618f
3
+ metadata.gz: a5c25269842c2a62630aa2accf056e3d15464f12
4
+ data.tar.gz: e74ccbb479ce36b61c48700e9ff79b971f196f25
5
5
  SHA512:
6
- metadata.gz: 85e074b00d7e502eb1b7e20d42dd2b6b47a4cd2de6e5dc324612636f3db5c9f130d17ca4d9f3d7aa3ff667efc16fe817ef819158a449e7c1b923a71e43674bff
7
- data.tar.gz: e2d391a541f081c3e262ecd61eeeeff0144c7cdce355873795800578818559eee845170baf132d54549252358c1ac6114a656413d495d8d68ef5b3fa28b325c9
6
+ metadata.gz: c0c095994244bf02b66e8f1197b756f0fc523d3f1bfc6935a48ad33d5abe3fdd72ea1e816ebe0ba93511ee9e832e2986ecc23d7062ede08c942aba509c07cd6e
7
+ data.tar.gz: 682992879ccf1e9fdc81436511fb90358dbe05eadf10952064f18a4a7dcc119b73c816768f474eac921af91c8743228d1c0927886ddb35a7e6a7fd328ff81723
@@ -163,6 +163,10 @@ module CassandraObject
163
163
  ) || {}
164
164
  end
165
165
 
166
+ def keyspace
167
+ session.keyspace
168
+ end
169
+
166
170
  def has_table?(name)
167
171
  self.cluster.keyspace(session.keyspace).has_table? name
168
172
  end
@@ -174,6 +178,30 @@ module CassandraObject
174
178
  def column_families
175
179
  @column_families ||= self.cluster.keyspace(session.keyspace).tables.inject({}) { |hsh, table| hsh[table.name] = table; hsh }
176
180
  end
181
+
182
+ def schema(reload=false)
183
+ if reload
184
+ remove_instance_variable(:@schema_cache) if instance_variable_defined?(:@schema_cache)
185
+ remove_instance_variable(:@column_families) if instance_variable_defined?(:@column_families)
186
+ end
187
+ end
188
+
189
+ def add_column_family(column_family)
190
+ value_type = column_family.column_type == 'Standard' ? 'text' : 'counter'
191
+
192
+ query = <<-CQL
193
+ CREATE TABLE "#{column_family.name}" (
194
+ key blob,
195
+ column1 text,
196
+ value #{value_type},
197
+ PRIMARY KEY (key, column1)
198
+ )
199
+ CQL
200
+
201
+ self.execute(query)
202
+
203
+ self.column_families[column_family.name.to_s] = column_family
204
+ end
177
205
  end
178
206
  end
179
207
  end
@@ -42,17 +42,18 @@ module CassandraObject
42
42
  self.connection_spec = spec
43
43
  end
44
44
 
45
+ @@connection = nil
45
46
  def connection
46
- @connection ||= CassandraObject::Adapters::CassandraDriver.new(self.connection_spec).client
47
+ @@connection ||= CassandraObject::Adapters::CassandraDriver.new(self.connection_spec).client
47
48
  end
48
49
 
49
50
  def connection?
50
- !! @connection
51
+ !! @@connection
51
52
  end
52
53
 
53
54
  def disconnect!
54
- @connection.try(:close)
55
- @connection = nil
55
+ @@connection.try(:close)
56
+ @@connection = nil
56
57
  end
57
58
 
58
59
  def with_connection(*args)
@@ -102,5 +102,16 @@ module CassandraObject
102
102
  end
103
103
 
104
104
  end
105
+
106
+ class ColumnFamily < Struct.new(:name,
107
+ :keyspace,
108
+ :comparator_type,
109
+ :column_type,
110
+ :compaction_strategy,
111
+ :row_cache_provider,
112
+ :default_validation_class,
113
+ :subcomparator_type
114
+ )
115
+ end
105
116
  end
106
117
  end
@@ -28,7 +28,7 @@ module CassandraObject
28
28
  }.merge(options)
29
29
 
30
30
  # this won't work with cassandra-driver
31
- cf = Cassandra::ColumnFamily.new
31
+ cf = CassandraObject::Schema::ColumnFamily.new
32
32
  cf.name = name.to_s
33
33
  cf.keyspace = @keyspace.to_s
34
34
  options.each do |option, value|
@@ -83,15 +83,3 @@ module CassandraObject
83
83
  end
84
84
 
85
85
  end
86
-
87
- class Cassandra
88
- class ColumnFamily
89
- def with_fields(options)
90
- struct_fields.collect { |f| f[1][:name] }.each do |f|
91
- send("#{f}=", options[f.to_sym] || options[f.to_s])
92
- end
93
- self
94
- end
95
- end
96
- end
97
-
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '4.0.6'
5
+ s.version = '4.0.7'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe CassandraObject::Schema::Migration do
4
+ context "create_column_family" do
5
+ it "should create a new standard column family" do
6
+ expect(Issue.connection.column_families['Foobars'].present?).to be false
7
+ CassandraObject::Schema::Migration.create_column_family("Foobars") do |cf|
8
+ cf.column_type = 'Standard'
9
+ cf.comparator_type = 'UTF8Type'
10
+ cf.default_validation_class = 'UTF8Type'
11
+ end
12
+ expect(Issue.connection.column_families['Foobars'].present?).to be true
13
+ end
14
+
15
+ it "should create a new counter column family" do
16
+ expect(Issue.connection.column_families['FooCounters'].present?).to be false
17
+ CassandraObject::Schema::Migration.create_column_family("FooCounters") do |cf|
18
+ cf.column_type = 'Counter'
19
+ cf.comparator_type = 'UTF8Type'
20
+ cf.default_validation_class = 'UTF8Type'
21
+ end
22
+ expect(Issue.connection.column_families['FooCounters'].present?).to be true
23
+ end
24
+ end
25
+ 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.6
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Koziarski
@@ -100,6 +100,7 @@ files:
100
100
  - spec/cassandra_object/associations_spec.rb
101
101
  - spec/cassandra_object/base_spec.rb
102
102
  - spec/cassandra_object/persistence_spec.rb
103
+ - spec/cassandra_object/schema/migration_spec.rb
103
104
  - spec/spec_helper.rb
104
105
  - spec/support/cassandra.rb
105
106
  - spec/support/db/migrate/001_create_test_tables.rb
@@ -160,6 +161,7 @@ test_files:
160
161
  - spec/cassandra_object/associations_spec.rb
161
162
  - spec/cassandra_object/base_spec.rb
162
163
  - spec/cassandra_object/persistence_spec.rb
164
+ - spec/cassandra_object/schema/migration_spec.rb
163
165
  - spec/spec_helper.rb
164
166
  - spec/support/cassandra.rb
165
167
  - spec/support/db/migrate/001_create_test_tables.rb