victorpacheco3107
victorpacheco3107

Reputation: 862

Ruby - plsql gem. How manage multiple connections

I have a ruby project, without rails. In my project I exceute some plsql, using ruby_plsql gem, like this:

require 'ruby_plsql' 
plsql.connection = OCI8.new('user','password',"//host:1521/my-db") # This only execute one time
def execute_pl
    ds = plsql.my_package.my_procedure(company, country) # This execute many time, reuse the connection
    ds
end

At this point, every work nice. Now, for some requirement, y need execute plsql in other db, its depend of some parameter.

If I do this:

plsql.connection = OCI8.new('user','password',"//host2:1521/my-other-db")

From now on, all the plsql will be executed in the other database, and it is not the idea, the idea is that it can be dynamically executed in any of the two databases, without the need to be creating a connection every time you go to run some plsql.

How do I build another method that executes a plsql in the other database, without the need to be creating a connection every time you go to run some plsql?

Upvotes: 0

Views: 95

Answers (1)

victorpacheco3107
victorpacheco3107

Reputation: 862

For user another connection using plsql gem, we can use alias:

plsql(:my_alias).connection = OCI8.new('user','password',"//host2:1521/my-other-db")

And the methods:

def execute_pl
    ds = plsql.my_package.my_procedure(company, country)
    ds
end
def execute_pl_in_other_db
    ds = plsql(:my_alias).my_package.my_procedure(company, country)
    ds
end

end

Upvotes: 1

Related Questions