Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disconnect an existing ruby sequel connection to a database?

Tags:

ruby

sequel

I mean the one which was previously established as

DB = Sequel.sqlite('my_blog.db')

or

DB = Sequel.connect('postgres://user:password@localhost/my_db')

or

DB = Sequel.postgres('my_db', :user => 'user', :password => 'password', :host => 'localhost')

or etcetera.

The Sequel::Database class has no public instance method called "disconnect" or so though it has "connect" one.

Maybe somebody already faced that problem. I would appreciate any idea.

like image 571
mcmlxxxiii Avatar asked May 06 '10 18:05

mcmlxxxiii


1 Answers

As Mladen Jablanović points out, you can just do:

DB.disconnect

Which will disconnect all of the available connections in that Sequel::Database instance's connection pool. You can't choose a specific connection to disconnect, and it wouldn't make sense to. The sharded connection pools do support disconnecting all connections for a specific shard, though.

like image 153
Jeremy Evans Avatar answered Oct 15 '22 05:10

Jeremy Evans