cassie 1.0.0.alpha.17 → 1.0.0.alpha.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cassie/connection_handler/cluster.rb +7 -1
- data/lib/cassie/connection_handler/sessions.rb +1 -1
- data/lib/cassie/queries/README.md +56 -0
- data/lib/cassie/queries/statement.rb +2 -20
- data/lib/cassie/queries/statement/consistency.rb +33 -0
- data/lib/cassie/queries/statement/execution.rb +41 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1574a96d31d99ad837fc8325c8cb705cdb86e28
|
4
|
+
data.tar.gz: 850b78f9859b02aa5b3593c0c550ac048fb6ce74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 107e8b6f43aac80be85470fcd210c900603e205fd013074742aba1b9b4bad979bc5da21ccbfa2da2a05228b1135e39428cc7b676a60eb9029c74414251bb324b
|
7
|
+
data.tar.gz: 0b4c6c105b51fe8515979c10543080cc9767aa4f382ddc36ff1c27bb914dc9403b4fc741d82ec7a2fd5eec04b9eefef499ab91e72bf34de4d72a53864740fea3
|
@@ -1,6 +1,12 @@
|
|
1
1
|
require 'benchmark'
|
2
2
|
|
3
3
|
module Cassie::ConnectionHandler
|
4
|
+
# ## Cassie::ConnectionHandler::Cluster
|
5
|
+
#
|
6
|
+
# Adds cluster instance configuration and memoization.
|
7
|
+
#
|
8
|
+
# Include in any class or module that responds to `configuration` with
|
9
|
+
# a cassandra cluster options hash.
|
4
10
|
module Cluster
|
5
11
|
|
6
12
|
def cluster
|
@@ -15,7 +21,7 @@ module Cassie::ConnectionHandler
|
|
15
21
|
_cluster = Cassandra.cluster(config)
|
16
22
|
end
|
17
23
|
|
18
|
-
logger.info "Connected to Cassandra cluster #{config[:hosts]}
|
24
|
+
logger.info "(#{(sec/1000.0).round(2)}ms) Connected to Cassandra cluster #{config[:hosts]}"
|
19
25
|
_cluster
|
20
26
|
end
|
21
27
|
end
|
@@ -20,7 +20,7 @@ module Cassie::ConnectionHandler
|
|
20
20
|
_session = cluster.connect(_keyspace)
|
21
21
|
end
|
22
22
|
|
23
|
-
logger.info "Session opened to Cassandra[#{_keyspace}]
|
23
|
+
logger.info "(#{(sec/1000.0).round(2)}ms) Session opened to Cassandra[#{_keyspace}]"
|
24
24
|
@sessions[_keyspace] = _session
|
25
25
|
end
|
26
26
|
end
|
@@ -148,6 +148,62 @@ or
|
|
148
148
|
end
|
149
149
|
```
|
150
150
|
|
151
|
+
#### Consistency configuration
|
152
|
+
|
153
|
+
The [consistency level](http://datastax.github.io/ruby-driver/v2.1.6/api/cassandra/#consistencies-constant) for a query is determined by your `Cassie::configuration` by default, falling to back to the `Cassandra` default if none is given.
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
Cassie.configuration[:consistency]
|
157
|
+
=> nil
|
158
|
+
|
159
|
+
Cassie.cluster.instance_variable_get(:@execution_options).consistency
|
160
|
+
=> :one
|
161
|
+
```
|
162
|
+
|
163
|
+
A Cassie::Query looks for a consistency level defined on the object, subclass, then base class levels. If one is found, it will override the `Cassandra` default when the query is executed.
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
select :posts_by_author_category
|
167
|
+
|
168
|
+
where :author_id, :eq
|
169
|
+
where :category, :eq, if: :filter_by_category?
|
170
|
+
|
171
|
+
def filter_by_category?
|
172
|
+
#true or false, as makes sense for your query
|
173
|
+
end
|
174
|
+
|
175
|
+
def consistency
|
176
|
+
#dynamically determine a query object's consistency level
|
177
|
+
if filter_by_category?
|
178
|
+
:quorum
|
179
|
+
else
|
180
|
+
super
|
181
|
+
end
|
182
|
+
end
|
183
|
+
```
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
select :posts_by_author_category
|
187
|
+
|
188
|
+
where :author_id, :eq
|
189
|
+
where :category, :eq
|
190
|
+
|
191
|
+
consistency :quorum
|
192
|
+
```
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
# lib/tasks/interesting_task.rake
|
196
|
+
require_relative "interesting_worker"
|
197
|
+
|
198
|
+
task :interesting_task do
|
199
|
+
Cassandra::Query.consistency = :all
|
200
|
+
|
201
|
+
InterestingWorker.new.perform
|
202
|
+
end
|
203
|
+
|
204
|
+
|
205
|
+
```
|
206
|
+
|
151
207
|
#### Object Mapping
|
152
208
|
For Selection Queries, resources are returned as structs by default for manipulation using accessor methods.
|
153
209
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/core_ext/string/filters'
|
2
2
|
require 'active_support/hash_with_indifferent_access'
|
3
|
+
require_relative 'statement/execution'
|
3
4
|
require_relative 'statement/preparation'
|
4
5
|
require_relative 'statement/callbacks'
|
5
6
|
require_relative 'statement/limiting'
|
@@ -16,6 +17,7 @@ module Cassie::Queries
|
|
16
17
|
extend ::ActiveSupport::Concern
|
17
18
|
|
18
19
|
included do
|
20
|
+
include Execution
|
19
21
|
include Preparation
|
20
22
|
include Callbacks
|
21
23
|
include Limiting
|
@@ -37,13 +39,6 @@ module Cassie::Queries
|
|
37
39
|
self.class.table
|
38
40
|
end
|
39
41
|
|
40
|
-
# Executes the statment, populates result
|
41
|
-
# returns true or false indicating a successful execution or not
|
42
|
-
def execute
|
43
|
-
@result = session.execute(statement)
|
44
|
-
execution_successful?
|
45
|
-
end
|
46
|
-
|
47
42
|
# returns a CQL string, or a Cassandra::Statement
|
48
43
|
# that is ready for execution
|
49
44
|
def statement
|
@@ -60,19 +55,6 @@ module Cassie::Queries
|
|
60
55
|
end
|
61
56
|
end
|
62
57
|
|
63
|
-
def execution_successful?
|
64
|
-
#TODO: rethink this, it knows too much
|
65
|
-
raise "execution not complete, no results to parse" unless result
|
66
|
-
|
67
|
-
# empty select
|
68
|
-
return true if result.empty?
|
69
|
-
|
70
|
-
# failed upsert
|
71
|
-
return false if (!result.rows.first["[applied]"].nil?) && (result.rows.first["[applied]"] == false)
|
72
|
-
|
73
|
-
true
|
74
|
-
end
|
75
|
-
|
76
58
|
private
|
77
59
|
|
78
60
|
def eval_if_opt?(value)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Cassie::Queries::Statement
|
2
|
+
module Consistency
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
attr_writer :consistency
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def inherited(subclass)
|
11
|
+
subclass.consistency = consistency
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
def consistency=(val)
|
16
|
+
@consistency = val
|
17
|
+
end
|
18
|
+
|
19
|
+
def consistency(val=:get)
|
20
|
+
if val == :get
|
21
|
+
@consistency if defined?(@consistency)
|
22
|
+
else
|
23
|
+
self.consistency = val
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def consistency
|
29
|
+
return @consistency if defined?(@consistency)
|
30
|
+
self.class.consistency
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'consistency'
|
2
|
+
|
3
|
+
module Cassie::Queries::Statement
|
4
|
+
module Execution
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include Consistency
|
9
|
+
end
|
10
|
+
|
11
|
+
# Executes the statment, populates result
|
12
|
+
# returns true or false indicating a successful execution or not
|
13
|
+
def execute
|
14
|
+
@result = session.execute(statement, execution_options)
|
15
|
+
execution_successful?
|
16
|
+
end
|
17
|
+
|
18
|
+
def execution_options
|
19
|
+
{}.tap do |opts|
|
20
|
+
#TODO: rework consistency module to be more
|
21
|
+
# abstract implementation for all execution options
|
22
|
+
opts[:consistency] = consistency if consistency
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def execution_successful?
|
29
|
+
#TODO: rethink this, it knows too much
|
30
|
+
raise "execution not complete, no results to parse" unless result
|
31
|
+
|
32
|
+
# empty select
|
33
|
+
return true if result.empty?
|
34
|
+
|
35
|
+
# failed upsert
|
36
|
+
return false if (!result.rows.first["[applied]"].nil?) && (result.rows.first["[applied]"] == false)
|
37
|
+
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.alpha.
|
4
|
+
version: 1.0.0.alpha.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Prothro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cassandra-driver
|
@@ -128,7 +128,9 @@ files:
|
|
128
128
|
- lib/cassie/queries/statement/assignments.rb
|
129
129
|
- lib/cassie/queries/statement/callbacks.rb
|
130
130
|
- lib/cassie/queries/statement/conditions.rb
|
131
|
+
- lib/cassie/queries/statement/consistency.rb
|
131
132
|
- lib/cassie/queries/statement/deleting.rb
|
133
|
+
- lib/cassie/queries/statement/execution.rb
|
132
134
|
- lib/cassie/queries/statement/fetching.rb
|
133
135
|
- lib/cassie/queries/statement/inserting.rb
|
134
136
|
- lib/cassie/queries/statement/limiting.rb
|