class SQL::TableCreator

Attributes

opts[RW]
table_name[RW]

Public Class Methods

new(adapter, table_name, opts = {}, &block) click to toggle source
# File lib/dm-migrations/sql/table_creator.rb, line 5
def initialize(adapter, table_name, opts = {}, &block)
  @adapter = adapter
  @table_name = table_name.to_s
  @opts = opts

  @columns = []

  self.instance_eval &block
end

Public Instance Methods

column(name, type, opts = {}) click to toggle source
# File lib/dm-migrations/sql/table_creator.rb, line 19
def column(name, type, opts = {})
  @columns << Column.new(@adapter, name, type, opts)
end
now() click to toggle source

A helper for using the native NOW() SQL function in a default

# File lib/dm-migrations/sql/table_creator.rb, line 28
def now
  SqlExpr.new('NOW()')
end
quoted_table_name() click to toggle source
# File lib/dm-migrations/sql/table_creator.rb, line 15
def quoted_table_name
  @adapter.send(:quote_name, table_name)
end
to_sql() click to toggle source
# File lib/dm-migrations/sql/table_creator.rb, line 23
def to_sql
  "CREATE TABLE #{quoted_table_name} (#{@columns.map{ |c| c.to_sql }.join(', ')})#{@adapter.table_options}"
end
uuid() click to toggle source

A helper for using the native UUID() SQL function in a default

# File lib/dm-migrations/sql/table_creator.rb, line 33
def uuid
  SqlExpr.new('UUID()')
end