cassie-queries 0.0.1.a1 → 0.0.1.a2
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/lib/cassie/queries/instrumentation.rb +23 -0
- data/lib/cassie/queries/log_subscription/cql_execution_event.rb +40 -0
- data/lib/cassie/queries/log_subscription.rb +31 -0
- data/lib/cassie/queries/prepared_statement.rb +42 -0
- data/lib/cassie/queries/session.rb +22 -0
- data/lib/cassie/queries/statement.rb +4 -20
- data/lib/cassie/query.rb +9 -1
- data/lib/cassie-queries.rb +1 -1
- metadata +20 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 292e17b52cc92a211e404495ca0835bd2a3bb368
|
4
|
+
data.tar.gz: edede8b8ef33b3625cba57ce64699ee11556ad86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 813f15ce1672f5f0a7cfb3adced562b0ee94a2f3a4e523a048e5b6973d22d38562068059a1cbc53fc0353c24fd20a1685b9246b19a9e9c03a24cd01327e98f28
|
7
|
+
data.tar.gz: b063aba0e91ef6bdb58bf68f732ec1bb5a490ffe37c63ac5b4c22f60e664c11fdf2a85ea787bc451fb3cf30d2d347e33a35f65929fa4b486932cf09821b8b3d7
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Cassie::Queries
|
2
|
+
module Instrumentation
|
3
|
+
extend ::ActiveSupport::Concern
|
4
|
+
|
5
|
+
def execute
|
6
|
+
instrument { super }
|
7
|
+
end
|
8
|
+
|
9
|
+
def instrument #:nodoc:
|
10
|
+
instrumenter.instrument("cql.execute") do |payload|
|
11
|
+
execution_val = yield # execution populates #result
|
12
|
+
payload[:execution_info] = result.try(:execution_info)
|
13
|
+
execution_val
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def instrumenter
|
20
|
+
ActiveSupport::Notifications
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Cassie::Queries::LogSubscription
|
2
|
+
class CqlExecutionEvent < ActiveSupport::Notifications::Event
|
3
|
+
|
4
|
+
def duration # in milliseconds
|
5
|
+
return super unless traced?
|
6
|
+
|
7
|
+
# trace duration is in microseconds
|
8
|
+
trace.duration / 1000.0
|
9
|
+
end
|
10
|
+
|
11
|
+
def message
|
12
|
+
color "(#{duration.round(1)}ms) #{statement}"
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def execution_info
|
18
|
+
payload[:execution_info]
|
19
|
+
end
|
20
|
+
|
21
|
+
def statement
|
22
|
+
statement = execution_info.statement
|
23
|
+
str = statement.cql
|
24
|
+
str += " [#{statement.params}]" if statement.respond_to? :params
|
25
|
+
str
|
26
|
+
end
|
27
|
+
|
28
|
+
def traced?
|
29
|
+
execution_info && !!trace
|
30
|
+
end
|
31
|
+
|
32
|
+
def trace
|
33
|
+
execution_info.trace
|
34
|
+
end
|
35
|
+
|
36
|
+
def color(message)
|
37
|
+
"\e[1m\e[37m#{message}\e[0m\e[22m"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'log_subscription/cql_execution_event'
|
2
|
+
|
3
|
+
module Cassie::Queries
|
4
|
+
module LogSubscription
|
5
|
+
extend ::ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
ActiveSupport::Notifications.subscribe('cql.execute') do |*args|
|
9
|
+
# args:
|
10
|
+
# name # => String, name of the event (such as 'render' from above)
|
11
|
+
# start # => Time, when the instrumented block started execution
|
12
|
+
# finish # => Time, when the instrumented block ended execution
|
13
|
+
# id # => String, unique ID for this notification
|
14
|
+
# payload # => Hash, the payload
|
15
|
+
unless args.last[:exception]
|
16
|
+
logger.debug(CqlExecutionEvent.new(*args).message)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
module ClassMethods
|
22
|
+
def logger
|
23
|
+
@logger ||= begin
|
24
|
+
l = Logger.new(STDOUT)
|
25
|
+
l.formatter = ActiveSupport::Logger::SimpleFormatter.new
|
26
|
+
l
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'active_support/core_ext/string/filters'
|
2
|
+
|
3
|
+
module Cassie::Queries
|
4
|
+
module PreparedStatement
|
5
|
+
extend ::ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
class << self
|
9
|
+
attr_accessor :prepare
|
10
|
+
end
|
11
|
+
self.prepare = true
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def inherited(subclass)
|
16
|
+
subclass.prepare = prepare
|
17
|
+
end
|
18
|
+
|
19
|
+
def prepare?
|
20
|
+
!!prepare
|
21
|
+
end
|
22
|
+
|
23
|
+
def prepared_statement
|
24
|
+
# use class instance variable to esnure only 1
|
25
|
+
# statement is prepared per process
|
26
|
+
# no mutex required in MRI because of GIL
|
27
|
+
#
|
28
|
+
# note: cassandra-driver handles the case
|
29
|
+
# of executing a prepared statement
|
30
|
+
# on a host where it has not been prepared
|
31
|
+
# yet, by re-preparing.
|
32
|
+
@prepared_statement ||= begin
|
33
|
+
session.prepare(statement)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def statement
|
39
|
+
self.class.prepare? ? self.class.prepared_statement : super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Cassie::Queries
|
2
|
+
module Session
|
3
|
+
extend ::ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def session
|
7
|
+
# until cassie-configuration exists,
|
8
|
+
# we're relying on the client to
|
9
|
+
# supply the session
|
10
|
+
if defined?(super)
|
11
|
+
super
|
12
|
+
else
|
13
|
+
raise "Oops! Cassie::Queries doesn't manage a Cassandra session for you, yet. You must provide a .session class method that returns a valid session."
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def session
|
19
|
+
self.class.session
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -19,26 +19,14 @@ module Cassie::Queries
|
|
19
19
|
|
20
20
|
def statement
|
21
21
|
self.const_get(:STATEMENT)
|
22
|
-
|
23
|
-
|
24
|
-
def prepared_statement
|
25
|
-
# use class instance variable to esnure only 1
|
26
|
-
# statement is prepared per process
|
27
|
-
# no mutex required in MRI because of GIL
|
28
|
-
#
|
29
|
-
# note: cassandra-driver handles the case
|
30
|
-
# of executing a prepared statement
|
31
|
-
# on a host where it has not been prepared
|
32
|
-
# yet, by re-preparing.
|
33
|
-
@prepared_statement ||= begin
|
34
|
-
session.prepare(statement)
|
35
|
-
end
|
22
|
+
rescue NameError
|
36
23
|
end
|
37
24
|
end
|
38
25
|
|
26
|
+
# Executes the statment, populates result
|
27
|
+
# returns true or false indicating a successful execution or not
|
39
28
|
def execute
|
40
|
-
@result = session.execute(
|
41
|
-
|
29
|
+
@result = session.execute(statement, arguments: bindings)
|
42
30
|
execution_successful?
|
43
31
|
end
|
44
32
|
|
@@ -46,10 +34,6 @@ module Cassie::Queries
|
|
46
34
|
self.class.statement
|
47
35
|
end
|
48
36
|
|
49
|
-
def prepared_statement
|
50
|
-
self.class.prepared_statement
|
51
|
-
end
|
52
|
-
|
53
37
|
protected
|
54
38
|
|
55
39
|
def bindings
|
data/lib/cassie/query.rb
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
module Cassie
|
2
2
|
# think about ActiveSupport autoloading
|
3
|
+
require_relative 'queries/session'
|
3
4
|
require_relative 'queries/statement'
|
5
|
+
require_relative 'queries/prepared_statement'
|
6
|
+
require_relative 'queries/instrumentation'
|
7
|
+
require_relative 'queries/log_subscription'
|
4
8
|
|
5
9
|
class Query
|
6
|
-
include
|
10
|
+
include Queries::Session
|
11
|
+
include Queries::Statement
|
12
|
+
include Queries::PreparedStatement
|
13
|
+
include Queries::Instrumentation
|
14
|
+
include Queries::LogSubscription
|
7
15
|
end
|
8
16
|
end
|
data/lib/cassie-queries.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassie-queries
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.a2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evan Prothro
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: '`cassie-queries` is a lightweight interface adapter allowing easy use
|
56
70
|
of the functionality provided by the `cassandra-driver`.'
|
57
71
|
email: evan.prothro@gmail.com
|
@@ -59,6 +73,11 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- lib/cassie/queries/instrumentation.rb
|
77
|
+
- lib/cassie/queries/log_subscription/cql_execution_event.rb
|
78
|
+
- lib/cassie/queries/log_subscription.rb
|
79
|
+
- lib/cassie/queries/prepared_statement.rb
|
80
|
+
- lib/cassie/queries/session.rb
|
62
81
|
- lib/cassie/queries/statement.rb
|
63
82
|
- lib/cassie/query.rb
|
64
83
|
- lib/cassie-queries.rb
|