Class: Believer::CreateTable
- Includes:
- CqlHelper
- Defined in:
- lib/believer/create_table.rb
Constant Summary
Constants included from CqlHelper
Believer::CqlHelper::CQL_TIMESTAMP_FORMAT
Instance Attribute Summary collapse
-
#table_properties ⇒ Object
Returns the value of attribute table_properties.
Attributes inherited from Command
#consistency_level, #record_class
Instance Method Summary collapse
Methods included from CqlHelper
#escape_special_chars, #to_cql_literal, #to_cql_properties, #to_hex_literal
Methods inherited from Command
#can_execute?, #clone, #command_name, #consistency, #execute, #execution_options, #execution_options=, #initialize, #override_execution_options, #query_attributes
Constructor Details
This class inherits a constructor from Believer::Command
Instance Attribute Details
#table_properties ⇒ Object
Returns the value of attribute table_properties.
5 6 7 |
# File 'lib/believer/create_table.rb', line 5 def table_properties @table_properties end |
Instance Method Details
#to_cql ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/believer/create_table.rb', line 7 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)" unless table_properties.nil? || table_properties.empty? s << " WITH #{to_cql_properties(table_properties)}" end s end |