extendi-cassandra_object 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/extendi-cassandra_object.gemspec +1 -1
- data/lib/cassandra_object/adapters/cassandra_schemaless_adapter.rb +5 -1
- data/lib/cassandra_object/base_schema.rb +1 -1
- data/lib/cassandra_object/base_schemaless.rb +1 -1
- data/lib/cassandra_object/base_schemaless_dynamic.rb +1 -1
- data/lib/cassandra_object/model.rb +1 -0
- data/test/support/cassandra.rb +1 -0
- data/test/support/issue_custom_config.rb +33 -0
- data/test/test_helper.rb +1 -0
- data/test/unit/base_test.rb +6 -0
- data/test/unit/scope/query_methods_test.rb +9 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d93715ace91da1509d264e53261d2a4b7b987cda
|
4
|
+
data.tar.gz: a479704c0f24f7285e1ef46df855d8fb8410d404
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 578aa46f8dd1702f6f7224c427c058804300c01da45a529ab8401ca79bd837117a8001d8f1f7d97dc11c1139ccd58fe8f1a7dd12c59e2f2f49d02644b2209ebb
|
7
|
+
data.tar.gz: 89ff7cc0bd118cd69d8be51015ab25ba5070ef4f32ccb4798583a1bc646c37756e142e72849140c966794fc32a3e4cda80556d792afa29cad66534484751de4d
|
data/README.md
CHANGED
@@ -113,6 +113,21 @@ class Widget < CassandraObject::BaseSchema
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
```
|
116
|
+
### Custom config
|
117
|
+
|
118
|
+
You can define a custom configuration for the cassandra connection, allowing you to have multiple cassandra endpoints fromt he same application
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
class Widget < CassandraObject::BaseSchema
|
122
|
+
string :name
|
123
|
+
|
124
|
+
def self.custom_config
|
125
|
+
#return custom cassandra configuration
|
126
|
+
{ }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
116
131
|
## Using with Cassandra
|
117
132
|
|
118
133
|
Add a config/cassandra.yml:
|
@@ -46,7 +46,11 @@ module CassandraObject
|
|
46
46
|
def where_string_async(id)
|
47
47
|
conditions = []
|
48
48
|
conditions << "#{@adapter.primary_key_column} = '#{id}'" if !id.nil?
|
49
|
-
|
49
|
+
select_values = @scope.select_values.select { |sv| sv != :column1 }
|
50
|
+
if select_values.size > 0
|
51
|
+
select_str = select_values.size > 1 ? "column1 IN (#{select_values.map { |sv| '?' }.join(',')})" : 'column1 = ?'
|
52
|
+
conditions << select_str
|
53
|
+
end
|
50
54
|
conditions += @scope.where_values.select.each_with_index { |_, i| i.even? }
|
51
55
|
return conditions.any? ? "WHERE #{conditions.join(' AND ')}" : nil
|
52
56
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module CassandraObject
|
2
2
|
class BaseSchemaless < Base
|
3
3
|
def self.adapter
|
4
|
-
@adapter ||= CassandraObject::Adapters::CassandraSchemalessAdapter.new(
|
4
|
+
@adapter ||= CassandraObject::Adapters::CassandraSchemalessAdapter.new(self.config)
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.schema_type
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module CassandraObject
|
2
2
|
class BaseSchemalessDynamic < Base
|
3
3
|
def self.adapter
|
4
|
-
@adapter ||= CassandraObject::Adapters::CassandraSchemalessAdapter.new(
|
4
|
+
@adapter ||= CassandraObject::Adapters::CassandraSchemalessAdapter.new(self.config)
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.schema_type
|
data/test/support/cassandra.rb
CHANGED
@@ -29,6 +29,7 @@ CassandraObject::Schema.create_keyspace 'cassandra_object_test'
|
|
29
29
|
CassandraObject::Schemaless.create_column_family 'Issues'
|
30
30
|
CassandraObject::Schema.create_column_family 'IssueSchemas', {attributes: 'id text, title text, description text, field float, intero int, created_at timestamp, updated_at timestamp, PRIMARY KEY (id)', options: {}}
|
31
31
|
CassandraObject::Schemaless.create_column_family 'IssueDynamics'
|
32
|
+
CassandraObject::Schemaless.create_column_family 'IssuesCustomConfig'
|
32
33
|
CassandraObject::Schema.create_column_family 'IssueSchemaFathers', {attributes: 'id text, title text, field float, created_at timestamp, updated_at timestamp, PRIMARY KEY (id)', options: {}}
|
33
34
|
CassandraObject::Schema.create_column_family 'IssueSchemaChildren', {attributes: 'id text, title text, description text, field float, created_at timestamp, updated_at timestamp, issue_schema_father_id text, PRIMARY KEY (id)', options: {}}
|
34
35
|
CassandraObject::BaseSchemaless.adapter.consistency = :quorum
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class IssueCustomConfig < CassandraObject::BaseSchemalessDynamic
|
2
|
+
string :description
|
3
|
+
string :title
|
4
|
+
|
5
|
+
before_create { self.description ||= 'funny' }
|
6
|
+
|
7
|
+
self.allow_filtering = true
|
8
|
+
|
9
|
+
def self.for_key key
|
10
|
+
where_ids(key)
|
11
|
+
end
|
12
|
+
|
13
|
+
# must be different to general config to test funcionality!
|
14
|
+
def self.custom_config
|
15
|
+
{
|
16
|
+
keyspace: 'cassandra_object_test',
|
17
|
+
hosts: ['127.0.0.1'],
|
18
|
+
compression: :lz4,
|
19
|
+
connect_timeout: 2,
|
20
|
+
timeout: 30,
|
21
|
+
consistency: :quorum,
|
22
|
+
protocol_version: 3,
|
23
|
+
page_size: 12345,
|
24
|
+
trace: true,
|
25
|
+
connections_per_local_node: 4,
|
26
|
+
schema_refresh_delay: 0.1,
|
27
|
+
schema_refresh_timeout: 0.1,
|
28
|
+
# connections_per_remote_node: nil,
|
29
|
+
# logger: Logger.new($stderr)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -8,6 +8,7 @@ require 'cassandra_object'
|
|
8
8
|
require 'support/cassandra'
|
9
9
|
require 'support/issue'
|
10
10
|
require 'support/issue_dynamic'
|
11
|
+
require 'support/issue_custom_config'
|
11
12
|
require 'support/issue_schema'
|
12
13
|
require 'support/issue_schema_child'
|
13
14
|
require 'support/issue_schema_father'
|
data/test/unit/base_test.rb
CHANGED
@@ -17,4 +17,10 @@ class CassandraObject::BaseTest < CassandraObject::TestCase
|
|
17
17
|
assert_equal 'CassandraObject::BaseTest::Sons', Son.column_family
|
18
18
|
assert_equal 'CassandraObject::BaseTest::Sons', Grandson.column_family
|
19
19
|
end
|
20
|
+
|
21
|
+
test 'custom cassandra configuration' do
|
22
|
+
assert_equal IssueCustomConfig.config, IssueCustomConfig.custom_config
|
23
|
+
assert_not_equal CassandraObject::Base.config, IssueCustomConfig.config
|
24
|
+
end
|
25
|
+
|
20
26
|
end
|
@@ -10,6 +10,15 @@ class CassandraObject::Scope::QueryMethodsTest < CassandraObject::TestCase
|
|
10
10
|
assert_nil found_issue.description
|
11
11
|
end
|
12
12
|
|
13
|
+
test 'multi select' do
|
14
|
+
original_issue = Issue.create title: 'foo', description: 'bar'
|
15
|
+
found_issue = Issue.select(:title, :description).find(original_issue.id)
|
16
|
+
|
17
|
+
assert_equal 'foo', found_issue.title
|
18
|
+
assert_equal 'bar', found_issue.description
|
19
|
+
assert_equal original_issue.id, found_issue.id
|
20
|
+
end
|
21
|
+
|
13
22
|
test 'select with block' do
|
14
23
|
foo_issue = Issue.create title: 'foo'
|
15
24
|
Issue.create title: 'bar'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: extendi-cassandra_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Duccio Giovannelli
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-09-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activemodel
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/cassandra_object/validations.rb
|
135
135
|
- test/support/cassandra.rb
|
136
136
|
- test/support/issue.rb
|
137
|
+
- test/support/issue_custom_config.rb
|
137
138
|
- test/support/issue_dynamic.rb
|
138
139
|
- test/support/issue_schema.rb
|
139
140
|
- test/support/issue_schema_child.rb
|