Class: Cassanity::Keyspace
- Inherits:
-
Object
- Object
- Cassanity::Keyspace
- Defined in:
- lib/cassanity/keyspace.rb
Instance Attribute Summary collapse
-
#executor ⇒ Object
readonly
Internal.
-
#name ⇒ Object
readonly
Public.
-
#strategy_class ⇒ Object
readonly
Internal.
-
#strategy_options ⇒ Object
readonly
Internal.
Instance Method Summary collapse
-
#column_families ⇒ Object
Public: Get all column families for keyspace.
-
#column_family(name_or_args, args = {}) ⇒ Object
(also: #table, #[])
Public: Get a column family instance.
-
#create(args = {}) ⇒ Object
Public: Creates the keyspace.
-
#drop(args = {}) ⇒ Object
Public: Drops a keyspace.
-
#exists? ⇒ Boolean
(also: #exist?)
Public: Returns true or false depending on if keyspace exists in the current cluster.
-
#initialize(args = {}) ⇒ Keyspace
constructor
Public: Initializes a Keyspace.
-
#recreate ⇒ Object
Public: Drops keyspace if it exists and then calls create.
-
#use(args = {}) ⇒ Object
Public: Uses a keyspace.
Constructor Details
#initialize(args = {}) ⇒ Keyspace
Public: Initializes a Keyspace.
args - The Hash of arguments (default: {}).
:name - The String name of the keyspace.
:executor - What will execute the queries. Must respond to `call`.
:strategy_class - The String strategy class name to use when
creating keyspace.
:strategy_options - The Hash of strategy options to use when
creating keyspace.
27 28 29 30 31 32 |
# File 'lib/cassanity/keyspace.rb', line 27 def initialize(args = {}) @name = args.fetch(:name) @executor = args.fetch(:executor) @strategy_class = args[:strategy_class] @strategy_options = args[:strategy_options] end |
Instance Attribute Details
#executor ⇒ Object (readonly)
Internal
9 10 11 |
# File 'lib/cassanity/keyspace.rb', line 9 def executor @executor end |
#name ⇒ Object (readonly)
Public
6 7 8 |
# File 'lib/cassanity/keyspace.rb', line 6 def name @name end |
#strategy_class ⇒ Object (readonly)
Internal
12 13 14 |
# File 'lib/cassanity/keyspace.rb', line 12 def strategy_class @strategy_class end |
#strategy_options ⇒ Object (readonly)
Internal
15 16 17 |
# File 'lib/cassanity/keyspace.rb', line 15 def @strategy_options end |
Instance Method Details
#column_families ⇒ Object
Public: Get all column families for keyspace.
Returns Array of Cassanity::ColumnFamily instances.
122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cassanity/keyspace.rb', line 122 def column_families @executor.call({ command: :column_families, arguments: { keyspace_name: @name, }, }).map { |row| ColumnFamily.new({ name: row['columnfamily'], keyspace: self, }) } end |
#column_family(name_or_args, args = {}) ⇒ Object Also known as: table, []
Public: Get a column family instance
name_or_args - The String name of the column family or a Hash which has
the name key and possibly other arguments.
args - The Hash of arguments to use for ColumnFamily initialization
(optional, default: {}). :keyspace is always included.
Returns a Cassanity::ColumnFamily instance.
144 145 146 147 148 149 150 151 152 |
# File 'lib/cassanity/keyspace.rb', line 144 def column_family(name_or_args, args = {}) column_family_args = if name_or_args.is_a?(Hash) name_or_args.merge(args) else args.merge(name: name_or_args) end ColumnFamily.new(column_family_args.merge(keyspace: self)) end |
#create(args = {}) ⇒ Object
Public: Creates the keyspace
args - The Hash of arguments to pass to the argument generator
(default: {}). :name is always included.
Examples
create # uses options from initialization
# override options from initialization
create({
strategy_class: 'NetworkTopologyStrategy',
strategy_options: {
dc1: 1,
dc2: 3,
}
})
Returns whatever is returned by executor.
64 65 66 67 68 69 70 71 |
# File 'lib/cassanity/keyspace.rb', line 64 def create(args = {}) @executor.call({ command: :keyspace_create, arguments: args.merge({ name: @name, }) }) end |
#drop(args = {}) ⇒ Object
Public: Drops a keyspace
args - The Hash of arguments to pass to the argument generator
(default: {}). :name is always included.
Examples
drop # you shouldn't really ever need more than this
Returns whatever is returned by executor.
110 111 112 113 114 115 116 117 |
# File 'lib/cassanity/keyspace.rb', line 110 def drop(args = {}) @executor.call({ command: :keyspace_drop, arguments: args.merge({ name: @name, }), }) end |
#exists? ⇒ Boolean Also known as: exist?
Public: Returns true or false depending on if keyspace exists in the current cluster.
Returns true if keyspace exists, false if it does not.
38 39 40 41 |
# File 'lib/cassanity/keyspace.rb', line 38 def exists? rows = @executor.call(command: :keyspaces) rows.any? { |row| row['name'].to_s == name.to_s } end |
#recreate ⇒ Object
Public: Drops keyspace if it exists and then calls create.
Returns nothing.
76 77 78 79 |
# File 'lib/cassanity/keyspace.rb', line 76 def recreate drop if exists? create end |
#use(args = {}) ⇒ Object
Public: Uses a keyspace
args - The Hash of arguments to pass to the argument generator
(default: {}). :name is always included.
Examples
use # you shouldn't really ever need more than this
Returns whatever is returned by executor.
91 92 93 94 95 96 97 98 |
# File 'lib/cassanity/keyspace.rb', line 91 def use(args = {}) @executor.call({ command: :keyspace_use, arguments: args.merge({ name: @name, }), }) end |