I am currently using a MySQL database and am considering moving to Postgres in the future. In my code I have:
client = Mysql2::Client.new(:host => "#{DB_HOST}", :username => "#{DB_USERNAME}",
:password => "#{DB_PASSWORD}", :database => "#{DB_NAME}")
sql = "SELECT /*complicated query with joins */ ASC"
data_setter = client.query(sql)
I am concerned that if I move to Postgres I will no longer be able to use the Mysql2 gem and perform queries similar to the code above.
Any advice would be greatly appreciated.
You can do the same sort of thing but you’ll have to switch to the
pggem as Mysql2 only knows how to talk to MySQL. The interface is similar:Generally you can go through ActiveRecord for most things (even raw SQL queries) but if you need to bypass all that and talk directly to the database then you can. You might have some issues with PostgreSQL not standing for the sort of sloppiness that MySQL will though.