Class: Believer::CreateTable
- Defined in:
- lib/believer/create_table.rb
Instance Attribute Summary
Attributes inherited from Command
#consistency_level, #execution_options, #record_class
Instance Method Summary collapse
Methods inherited from Command
#can_execute?, #clone, #command_name, #consistency, #execute, #initialize, #query_attributes
Constructor Details
This class inherits a constructor from Believer::Command
Instance Method Details
#to_cql ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/believer/create_table.rb', line 4 def to_cql keys = [] record_class.get_primary_key.each do |key_part| if key_part.is_a?(Enumerable) keys << "(#{key_part.join(',')})" else keys << key_part end end s = "CREATE TABLE #{record_class.table_name} (\n" col_statement_parts = record_class.columns.keys.map {|col_name| record_class.columns[col_name].to_cql } s << col_statement_parts.join(",\n") s << ",\n" s << "PRIMARY KEY (#{keys.join(',')})" s << "\n)" s end |