diff options
-rw-r--r-- | lib/dbshell/client/mysql.rb | 23 | ||||
-rw-r--r-- | spec/dbshell/client/mysql_spec.rb | 24 |
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/dbshell/client/mysql.rb b/lib/dbshell/client/mysql.rb new file mode 100644 index 0000000..6cb8233 --- /dev/null +++ b/lib/dbshell/client/mysql.rb @@ -0,0 +1,23 @@ +module DBShell + module Client + class MySQL + EXECUTABLE_NAME = 'mysql' + + def self.build_command(db_info) + args = [EXECUTABLE_NAME] + + host = db_info['host'] + port = db_info['port'] + db_name = db_info['database'] + user = db_info['username'] + password = db_info['password'] + + args.push("--user=#{user}") if user + args.push("--password=#{password}") if password + args.push("--host=#{host}") if host + args.push("--port=#{port}") if port + args.push(db_name) + end + end + end +end diff --git a/spec/dbshell/client/mysql_spec.rb b/spec/dbshell/client/mysql_spec.rb new file mode 100644 index 0000000..c98203e --- /dev/null +++ b/spec/dbshell/client/mysql_spec.rb @@ -0,0 +1,24 @@ +require 'minitest/autorun' +require 'dbshell/client/mysql' + +describe DBShell::Client::MySQL do + describe ".build_command" do + it "builds basic arguments" do + DBShell::Client::MySQL.build_command({ + 'adapter' => 'mysql2', + 'host' => 'mailmarehost', + 'port' => 6027, + 'username' => 'derpyhooves', + 'password' => 'somepassword', + 'database' => 'dbname' + }).must_equal([ + 'mysql', + '--user=derpyhooves', + '--password=somepassword', + '--host=mailmarehost', + '--port=6027', + 'dbname' + ]) + end + end +end |