Module: Believer::DDL::ClassMethods
- Defined in:
- lib/believer/ddl.rb
Instance Method Summary collapse
Instance Method Details
#create_table ⇒ Object
7 8 9 10 11 12 |
# File 'lib/believer/ddl.rb', line 7 def create_table cql = create_table_cql puts "Creating table #{table_name} using CQL:\n#{cql}" connection.execute(cql) puts "Created table #{table_name}" end |
#create_table_cql ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/believer/ddl.rb', line 14 def create_table_cql s = "CREATE TABLE #{table_name} (\n" col_statement_parts = columns.keys.map {|col| "#{col} #{columns[col].cql_column_type}"} s << col_statement_parts.join(",\n") keys = [] get_primary_key.each do |key_part| if key_part.is_a?(Enumerable) keys << "(#{key_part.join(',')})" else keys << key_part end end s << ",\n" s << "PRIMARY KEY (#{keys.join(',')})" s << "\n)" s end |