Sha256: 45dba8bb787dcf3728a4b8b108e88e8728fa36324558f3934877edc09f680647
Contents?: true
Size: 1.29 KB
Versions: 33
Compression:
Stored size: 1.29 KB
Contents
require 'open3' require 'shellwords' require 'flydata/command/sync' # Command class must be in module Flydata::Command module Flydata module Command class Psql < Sync def run(*args) de = data_entry cmd = generate_command(de['postgresql_data_entry_preference'], args) return if cmd.to_s.empty? $stderr.puts "command:#{cmd}" if FLYDATA_DEBUG if $stdin.tty? # interactive shell system cmd else # execute queries given to $stdin Open3.popen2e(cmd) do |i, o, wt| $stdin.each_line do |line| i.print line end i.close while line = o.gets print line end end end end def generate_command(dbconf, args) password = Shellwords.escape(dbconf['password']) database = Shellwords.escape(dbconf['database']) host = Shellwords.escape(dbconf['host']) port = Shellwords.escape(dbconf['port']) username = Shellwords.escape(dbconf['username']) "PGCONNECT_TIMEOUT=5 PGPASSWORD=#{password} psql -d #{database} -h #{host} -p #{port} -U #{username}" end def flush; end def reset; end def skip; end def generate_table_ddl; end end end end
Version data entries
33 entries across 33 versions & 1 rubygems