Class: Cequel::Schema::TableWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/cequel/schema/table_writer.rb

Overview

Creates a new table schema in the database

Since:

  • 1.0.0

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table) ⇒ TableWriter

Returns a new instance of TableWriter.

Parameters:

  • keyspace (Keyspace)

    keyspace in which to create the table

  • table (Table)

    object representation of table schema

Since:

  • 1.0.0



23
24
25
# File 'lib/cequel/schema/table_writer.rb', line 23

def initialize(table)
  @table = table
end

Class Method Details

.apply(keyspace, table) ⇒ void

This method returns an undefined value.

Creates a new table schema in the database given an object representation of the schema to create

Parameters:

  • keyspace (Keyspace)

    keyspace in which to create the table

  • table (Table)

    object representation of table schema

Since:

  • 1.0.0



15
16
17
# File 'lib/cequel/schema/table_writer.rb', line 15

def self.apply(keyspace, table)
  new(table).apply(keyspace)
end

Instance Method Details

#apply(keyspace) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Create the table in the keyspace

Since:

  • 1.0.0



34
35
36
# File 'lib/cequel/schema/table_writer.rb', line 34

def apply(keyspace)
  statements.each { |statement| keyspace.execute(statement) }
end

#statementsObject

Since:

  • 1.0.0



38
39
40
# File 'lib/cequel/schema/table_writer.rb', line 38

def statements
  [create_statement] + index_statements
end