Class: Cassanity::Connection
- Inherits:
-
Object
- Object
- Cassanity::Connection
- Defined in:
- lib/cassanity/connection.rb
Instance Attribute Summary collapse
-
#executor ⇒ Object
readonly
Internal.
Instance Method Summary collapse
-
#batch(args = {}) ⇒ Object
Public: Group multiple statements into a batch.
-
#initialize(args = {}) ⇒ Connection
constructor
Public: Initializes a connection.
-
#inspect ⇒ Object
Public.
-
#keyspace(name_or_args, args = {}) ⇒ Object
(also: #[])
Public: Get a keyspace instance.
-
#keyspaces ⇒ Object
Public: Get all keyspaces.
Constructor Details
#initialize(args = {}) ⇒ Connection
Public: Initializes a connection
args - The Hash of arguments (default: {}).
:executor - What will execute the CQL statements.
Must respond to `call`.
13 14 15 |
# File 'lib/cassanity/connection.rb', line 13 def initialize(args = {}) @executor = args.fetch(:executor) end |
Instance Attribute Details
#executor ⇒ Object (readonly)
Internal
6 7 8 |
# File 'lib/cassanity/connection.rb', line 6 def executor @executor end |
Instance Method Details
#batch(args = {}) ⇒ Object
Public: Group multiple statements into a batch.
args - The Hash of arguments to pass to the argument generator
(default: {}).
Examples
batch({
modifications: [
[:insert, name: 'apps', data: {id: '1', name: 'github'}],
[:insert, name: 'apps', data: {id: '2', name: 'gist'}],
[:update, name: 'apps', set: {name: 'github.com'}, where: {id: '1'}],
[:delete, name: 'apps', where: {id: '2'}],
]
})
Returns whatever is returned by executor.
34 35 36 37 38 39 |
# File 'lib/cassanity/connection.rb', line 34 def batch(args = {}) @executor.call({ command: :batch, arguments: args, }) end |
#inspect ⇒ Object
Public
74 75 76 77 78 79 |
# File 'lib/cassanity/connection.rb', line 74 def inspect attributes = [ "executor=#{@executor.inspect}", ] "#<#{self.class.name}:#{object_id} #{attributes.join(', ')}>" end |
#keyspace(name_or_args, args = {}) ⇒ Object Also known as: []
Public: Get a keyspace instance
name_or_args - The String name of the keyspace or a Hash which has a name
key and possibly other arguments.
args - The Hash of arguments to use for Keyspace initialization.
(optional, default: {}). :executor is always included.
Returns a Cassanity::Keyspace instance.
61 62 63 64 65 66 67 68 69 |
# File 'lib/cassanity/connection.rb', line 61 def keyspace(name_or_args, args = {}) keyspace_args = if name_or_args.is_a?(Hash) name_or_args.merge(args) else args.merge(name: name_or_args) end Keyspace.new(keyspace_args.merge(executor: executor)) end |
#keyspaces ⇒ Object
Public: Get all keyspaces.
Returns Array of Cassanity::Keyspace instances.
44 45 46 47 48 49 50 51 |
# File 'lib/cassanity/connection.rb', line 44 def keyspaces @executor.call({ command: :keyspaces, transformer_arguments: { executor: @executor, }, }) end |