module DbSucker::Adapters::Mysql2::Api
Public Class Methods
require_dependencies()
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 5 def self.require_dependencies begin; require "mysql2"; rescue LoadError; end end
Public Instance Methods
client_binary()
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 9 def client_binary source["client_binary"] || "mysql" end
client_call()
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 21 def client_call [].tap do |r| r << "#{client_binary}" r << "-u#{source["username"]}" if source["username"] r << "-p#{source["password"]}" if source["password"] r << "-h#{source["hostname"]}" if source["hostname"] end * " " end
database_list(include_tables = false)
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 81 def database_list include_tables = false dbs = blocking_channel_result(%{#{client_call} -N -e 'SHOW DATABASES;'}).for_group(:stdout).join("").split("\n") if include_tables dbs.map do |db| [db, table_list(db)] end else dbs end end
dump_binary()
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 17 def dump_binary source["dump_binary"] || "mysqldump" end
dump_call()
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 39 def dump_call [].tap do |r| r << "#{dump_binary}" r << "-u#{source["username"]}" if source["username"] r << "-p#{source["password"]}" if source["password"] r << "-h#{source["hostname"]}" if source["hostname"] end * " " end
dump_command_for(table)
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 48 def dump_command_for table [].tap do |r| r << dump_call if c = constraint(table) r << "--compact --skip-extended-insert --no-create-info --complete-insert" r << Shellwords.escape("-w#{c}") end r << source["database"] r << table r << "#{source["args"]}" end * " " end
hostname()
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 97 def hostname blocking_channel_result(%{#{client_call} -N -e 'select @@hostname;'}).for_group(:stdout).join("").strip end
import_instruction_for(file, flags = {})
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 61 def import_instruction_for file, flags = {} {}.tap do |instruction| instruction[:bin] = [local_client_call, data["database"], data["args"]].join(" ") instruction[:file] = file if flags[:dirty] && flags[:deferred] instruction[:file_prepend] = %{ echo "SET AUTOCOMMIT=0;" echo "SET UNIQUE_CHECKS=0;" echo "SET FOREIGN_KEY_CHECKS=0;" } instruction[:file_append] = %{ echo "SET FOREIGN_KEY_CHECKS=1;" echo "SET UNIQUE_CHECKS=1;" echo "SET AUTOCOMMIT=1;" echo "COMMIT;" } end end end
local_client_binary()
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 13 def local_client_binary data["client_binary"] || "mysql" end
local_client_call()
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 30 def local_client_call [].tap do |r| r << "#{local_client_binary}" r << "-u#{data["username"]}" if data["username"] r << "-p#{data["password"]}" if data["password"] r << "-h#{data["hostname"]}" if data["hostname"] end * " " end
table_list(database)
click to toggle source
# File lib/db_sucker/adapters/mysql2.rb, line 93 def table_list database blocking_channel_result(%{#{client_call} -N -e 'SHOW FULL TABLES IN #{database};'}).for_group(:stdout).join("").split("\n").map{|r| r.split("\t") } end