Class: SqlCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_tasks/sql_command.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, database_config) ⇒ SqlCommand

Returns a new instance of SqlCommand.



51
52
53
54
# File 'lib/sql_tasks/sql_command.rb', line 51

def initialize(path, database_config)
  @config = database_config
  @path = path
end

Instance Method Details

#create_dbObject



81
82
83
# File 'lib/sql_tasks/sql_command.rb', line 81

def create_db
  ShellCommand.new("mysql", config_hash, '--execute="create database %s;"' % @config["database"])
end

#drop_dbObject



77
78
79
# File 'lib/sql_tasks/sql_command.rb', line 77

def drop_db
  ShellCommand.new("mysql", config_hash, '--execute="drop database %s;"' % @config["database"])
end

#dump_dataObject



56
57
58
# File 'lib/sql_tasks/sql_command.rb', line 56

def dump_data
  command = ShellCommand.new("mysqldump", config_hash, "--skip-dump-date --skip-comments", @config["database"], { :tab => @path })
end

#import_schemaObject



64
65
66
# File 'lib/sql_tasks/sql_command.rb', line 64

def import_schema
  ShellCommand.new("mysql", config_hash, @config["database"], "<#{@path}")
end

#load_dataObject



60
61
62
# File 'lib/sql_tasks/sql_command.rb', line 60

def load_data
  ShellCommand.new("mysqlimport", config_hash, @config["database"], @path)
end

#truncate_dataObject



68
69
70
71
72
73
74
75
# File 'lib/sql_tasks/sql_command.rb', line 68

def truncate_data
  file = write_truncate_script
  if @config["password"] == nil
    ShellCommand.new(file.path, @config["username"], 'nopwd',  escaped(@config["database"]))
  else
    ShellCommand.new(file.path, @config["username"], escaped(@config["password"]), escaped(@config["database"]))
  end
end