aboutsummaryrefslogtreecommitdiffstats
path: root/lib/dbshell/client/postgres.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dbshell/client/postgres.rb')
-rw-r--r--lib/dbshell/client/postgres.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/dbshell/client/postgres.rb b/lib/dbshell/client/postgres.rb
new file mode 100644
index 0000000..1c1c663
--- /dev/null
+++ b/lib/dbshell/client/postgres.rb
@@ -0,0 +1,23 @@
+class DBShell::PostgresClient
+ EXECUTABLE_NAME = 'psql'
+
+ def self.runshell(db_info)
+ args = self.build_command(db_info)
+ exec(*args)
+ end
+
+ 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('-U', user) if user
+ args.push('-h', host) if host
+ args.push('-p', port) if port
+ args.push(db_name)
+ end
+end