Class: SqlCommand
- Inherits:
-
Object
- Object
- SqlCommand
- Defined in:
- lib/sql_tasks/sql_command.rb
Instance Method Summary collapse
- #create_db ⇒ Object
- #drop_db ⇒ Object
- #dump_data ⇒ Object
- #import_schema ⇒ Object
-
#initialize(path, database_config) ⇒ SqlCommand
constructor
A new instance of SqlCommand.
- #load_data ⇒ Object
- #truncate_data ⇒ Object
Constructor Details
#initialize(path, database_config) ⇒ 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_db ⇒ Object
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_db ⇒ Object
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_data ⇒ Object
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_schema ⇒ Object
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_data ⇒ Object
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_data ⇒ Object
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 |