0

So in Python, I am used to using something like

pd.read_sql(sql_query, connection_object)

in order to grab data from a remote database. But when forming a similar connection object in Ruby:

require 'pg'

@connect_obj = PG.connect(:host => host, :dbname => db , :user => user , :password => pwd , :port => port )

what can Ruby do in order to run something like pd.read_sql(sql_query, connection_object)?

Raj
  • 22,346
  • 14
  • 99
  • 142
Flair
  • 2,609
  • 1
  • 29
  • 41

1 Answers1

2

With Rails, the usual way is to create a model class for your table and then use ActiveRecord methods.

But if you want to run some general queries without using any model classes, you can try it this way:

ActiveRecord::Base.connection.execute('SELECT * FROM users').each { |row| puts row }
Raj
  • 22,346
  • 14
  • 99
  • 142