require 'jcr-db/command'

module JCR
  module DB

    class PsqlCommand
      include JCR::DB::Command

      def initialize(sql_command, options = nil)
        options ||= {}
        options[:database] ||= options.delete(:on)
        cmd_string = [
          'psql',
          ("-h #{options[:host]}" if options[:host]),
          ("-U #{options[:user]}" if options[:user]),
          ("-d #{options[:database]}" if options[:database]),
          "-c \"#{sql_command}\""
        ].compact.join(' ')
        super(cmd_string)
      end

    end

  end
end
