Sha256: 12f707eaf965dab8a0ab51468522abb68fc1410d73c184e15ba5315caf4af581

Contents?: true

Size: 851 Bytes

Versions: 3

Compression:

Stored size: 851 Bytes

Contents

class Baza::Driver::Mysql::Sql::CreateTable
  def initialize(args)
    @name = args.fetch(:name)
    @columns = args.fetch(:columns)
    @indexes = args[:indexes]
    @temporary = args[:temporary]
  end

  def sql
    sql = "CREATE"
    sql << " TEMPORARY" if @temporary
    sql << " TABLE #{Baza::Driver::Mysql.quote_table(@name)} ("

    first = true
    @columns.each do |col_data|
      sql << ", " unless first
      first = false if first
      col_data.delete(:after) if col_data[:after]

      sql << Baza::Driver::Mysql::Sql::Column.new(col_data).sql.first
    end

    if @indexes && !@indexes.empty?
      sql << ", "
      sql << Baza::Driver::Mysql::Sql::CreateIndexes.new(
        indexes: @indexes,
        create: false,
        on_table: false,
        table_name: @name
      ).sql.first
    end

    sql << ")"

    [sql]
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
baza-0.0.38 lib/baza/driver/mysql/sql/create_table.rb
baza-0.0.37 lib/baza/driver/mysql/sql/create_table.rb
baza-0.0.36 lib/baza/driver/mysql/sql/create_table.rb