Class: MysqlPartition::SqlMaker
- Inherits:
-
Object
- Object
- MysqlPartition::SqlMaker
- Defined in:
- lib/mysql_partition/sql_maker.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#expression ⇒ Object
Returns the value of attribute expression.
-
#table ⇒ Object
Returns the value of attribute table.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_partitions(hash) ⇒ Object
- #create_partitions(hash) ⇒ Object
- #drop_partitions(*partition_names) ⇒ Object
-
#initialize(hash) ⇒ SqlMaker
constructor
A new instance of SqlMaker.
Constructor Details
#initialize(hash) ⇒ SqlMaker
Returns a new instance of SqlMaker.
7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/mysql_partition/sql_maker.rb', line 6 def args @args end |
#expression ⇒ Object
Returns the value of attribute expression.
6 7 8 |
# File 'lib/mysql_partition/sql_maker.rb', line 6 def expression @expression end |
#table ⇒ Object
Returns the value of attribute table.
6 7 8 |
# File 'lib/mysql_partition/sql_maker.rb', line 6 def table @table end |
#type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/mysql_partition/sql_maker.rb', line 6 def type @type end |
Instance Method Details
#add_partitions(hash) ⇒ Object
25 26 27 28 |
# 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) ⇒ Object
20 21 22 23 |
# 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) ⇒ Object
30 31 32 33 |
# 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 |