lib/heroku/command/pg.rb
# pg:psql [DATABASE]
#
#  -c, --command COMMAND      # optional SQL command to run
#
# open a psql shell to the database
#
# defaults to DATABASE_URL databases if no DATABASE is specified
#
psql [DATABASE]
c, --command COMMAND      # optional SQL command to run

open a psql shell to the database

defaults to DATABASE_URL databases if no DATABASE is specified
psql [ DATABASE ] c -- command COMMAND # optional SQL command to run open a psql shell to the database defaults to DATABASE_URL databases if no DATABASE is specified
def psql
    attachment = generate_resolver.resolve(shift_argument, "DATABASE_URL")
    validate_arguments!
    uri = URI.parse( attachment.url )
    begin
      ENV["PGPASSWORD"] = uri.password
      ENV["PGSSLMODE"]  = 'require'
      if command = options[:command]
        command = "-c '#{command}'"
      end
      shorthand = "#{attachment.app}::#{attachment.name.sub(/^HEROKU_POSTGRESQL_/,'').gsub(/\W+/, '-')}"
      prompt_expr = "#{shorthand}%R%# "
      prompt_flags = %Q(--set "PROMPT1=#{prompt_expr}" --set "PROMPT2=#{prompt_expr}")
      puts "---> Connecting to #{attachment.display_name}"
      exec "psql -U #{uri.user} -h #{uri.host} -p #{uri.port || 5432} #{prompt_flags} #{command} #{uri.path[1..-1]}"
    rescue Errno::ENOENT
      output_with_bang "The local psql command could not be located"
      output_with_bang "For help installing psql, see http://devcenter.heroku.com/articles/local-postgresql"
      abort
    end
  end
def psql attachment = generate_resolver . resolve ( shift_argument , "DATABASE_URL" ) validate_arguments! uri = URI . parse ( attachment . url ) begin ENV [ "PGPASSWORD" ] = uri . password ENV [ "PGSSLMODE" ] = 'require' if command = options [ :command ] command = "-c '#{command}'" end shorthand = "#{attachment.app}::#{attachment.name.sub(/^HEROKU_POSTGRESQL_/,'').gsub(/\W+/, '-')}" prompt_expr = "#{shorthand}%R%# " prompt_flags = %Q(--set "PROMPT1=#{prompt_expr}" --set "PROMPT2=#{prompt_expr}") puts "---> Connecting to #{attachment.display_name}" exec "psql -U #{uri.user} -h #{uri.host} -p #{uri.port || 5432} #{prompt_flags} #{command} #{uri.path[1..-1]}" rescue Errno :: ENOENT output_with_bang "The local psql command could not be located" output_with_bang "For help installing psql, see http://devcenter.heroku.com/articles/local-postgresql" abort end end
pg:psql [DATABASE]
c, --command COMMAND      # optional SQL command to run
pg : psql [ DATABASE ] c -- command COMMAND # optional SQL command to run