Class: DatastaxRails::Cql::CreateColumnFamily

Inherits:
Base
  • Object
show all
Defined in:
lib/datastax_rails/cql/create_column_family.rb

Overview

CQL generation for CREATE COLUMNFAMILY

Instance Method Summary collapse

Methods inherited from Base

#execute, #using

Constructor Details

#initialize(cf_name) ⇒ CreateColumnFamily


5
6
7
8
9
10
# File 'lib/datastax_rails/cql/create_column_family.rb', line 5

def initialize(cf_name)
  @cf_name = cf_name
  @columns = {}
  @storage_parameters = []
  @primary_key = 'id'
end

Instance Method Details

#columns(columns) ⇒ Object


22
23
24
25
# File 'lib/datastax_rails/cql/create_column_family.rb', line 22

def columns(columns)
  @columns.merge! columns
  self
end

#comment=(comment) ⇒ Object

Migration helpers


28
29
30
# File 'lib/datastax_rails/cql/create_column_family.rb', line 28

def comment=(comment)
  with('comment' => comment)
end

#comparator=(comp) ⇒ Object


32
33
34
# File 'lib/datastax_rails/cql/create_column_family.rb', line 32

def comparator=(comp)
  with('comparator' => comp)
end

#default_validation=(val) ⇒ Object


36
37
38
# File 'lib/datastax_rails/cql/create_column_family.rb', line 36

def default_validation=(val)
  with('default_validation' => val)
end

#primary_key(pk) ⇒ Object


12
13
14
15
# File 'lib/datastax_rails/cql/create_column_family.rb', line 12

def primary_key(pk)
  @primary_key = pk
  self
end

#to_cqlObject


40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/datastax_rails/cql/create_column_family.rb', line 40

def to_cql
  stmt = "CREATE COLUMNFAMILY #{@cf_name} ("
  @columns.each do |name, type|
    stmt << "#{name} #{type}, "
  end
  stmt << "PRIMARY KEY (#{@primary_key}))"
  unless @storage_parameters.empty?
    stmt << ' WITH '
    stmt << @storage_parameters.flatten.join(' AND ')
  end

  stmt
end

#with(with) ⇒ Object


17
18
19
20
# File 'lib/datastax_rails/cql/create_column_family.rb', line 17

def with(with)
  @storage_parameters << with
  self
end