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

Version Path
flydata-0.8.10.2 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.10.1 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.9.11 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.10 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.9 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.8 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.7 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.6 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.5 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.4 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.3 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.2 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.1 lib/flydata/source_postgresql/command/psql.rb
flydata-0.8.0 lib/flydata/source_postgresql/command/psql.rb
flydata-0.7.19 lib/flydata/source_postgresql/command/psql.rb
flydata-0.7.18 lib/flydata/source_postgresql/command/psql.rb
flydata-0.7.17 lib/flydata/source_postgresql/command/psql.rb
flydata-0.7.16 lib/flydata/source_postgresql/command/psql.rb
flydata-0.7.15 lib/flydata/source_postgresql/command/psql.rb
flydata-0.7.14 lib/flydata/source_postgresql/command/psql.rb