Created
May 24, 2016 19:53
-
-
Save joseluistorres/05d5bb20b3f84692e469488ead554baa to your computer and use it in GitHub Desktop.
Run a custom query function from rails console to another DB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# whenever you need to do a custom query/function/sproc into another DB that is not development | |
app = ActiveRecord::Base.establish_connection( | |
adapter: "mysql", | |
host: "localhost", | |
username: "myuser", | |
password: "mypass", | |
database: "somedatabase" | |
) | |
# if you have already defined an entry in database.yml | |
# -------------- READ THIS TOO --------------------------------- | |
# use app = ActiveRecord::Base.establish_connection(:your_custom_db) | |
sql = <<-SQL | |
select * FROM whatever_table( 'somestring', 2016 ); | |
SQL | |
app.connection.execute(sql) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment