class MysqlPartition::SqlMaker
Attributes
args[RW]
expression[RW]
table[RW]
type[RW]
Public Class Methods
new(hash)
click to toggle source
# File lib/mysql_partition/sql_maker.rb, line 7 def initialize(hash) if !(hash[:type] and hash[:table] and hash[:expression]) raise ArgumentError, "need type, table and expression" end @type = hash[:type].to_s.upcase @table = hash[:table] @expression = hash[:expression] @args = hash klass = Object.const_get "::MysqlPartition::Type::#{type.capitalize}" self.class.prepend klass end
Public Instance Methods
add_partitions(hash)
click to toggle source
# File lib/mysql_partition/sql_maker.rb, line 25 def add_partitions(hash) sprintf 'ALTER TABLE %s ADD PARTITION (%s)', table, build_partition_parts(hash) end
create_partitions(hash)
click to toggle source
# File lib/mysql_partition/sql_maker.rb, line 20 def create_partitions(hash) sprintf 'ALTER TABLE %s PARTITION BY %s (%s) (%s)', table, type, expression, build_partition_parts(hash) end
drop_partitions(*partition_names)
click to toggle source
# File lib/mysql_partition/sql_maker.rb, line 30 def drop_partitions(*partition_names) sprintf 'ALTER TABLE %s DROP PARTITION %s', table, partition_names.join(', ') end
Private Instance Methods
build_partition_parts(hash)
click to toggle source
build_partition_parts
(“p1” => 1, …)
# File lib/mysql_partition/sql_maker.rb, line 37 def build_partition_parts(hash) parts = [] hash.each do |partition_name, partition_description| part = build_partition_part(partition_name, partition_description) parts.push(part) end parts.join(", ") end