5

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.

mcmlxxxiii
  • 913
  • 1
  • 9
  • 21

1 Answers1

15

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.

Jeremy Evans
  • 11,959
  • 27
  • 26
  • After you told that wouldn't make sense, I started to doubt that I understand connection pools right. The following code assumes that multiple modules can simultaneously use specific connection from DB hash: [[[ DB = {}; DB[:a] Sequel.postgres('a', opts); DB[:b] Sequel.postgres('b', opts); DB[:c] Sequel.postgres('c', opts) ]]]. The task is in disconnecting all the DB[:a] connections, actually in releasing the specific database. Is the above approach right? Is that possible? DB[:a].disconnect doesn't work as desired, or I do misunderstand? BTW, many thanks for the toolkit! – mcmlxxxiii May 08 '10 at 00:51
  • Sorry for the ugly message, I'm not yet unaccustomed to Stackoverflow's methods. The example code and clarifications should probably be in a question(( – mcmlxxxiii May 08 '10 at 01:02
  • 1
    You don't ever get to choose a specific connection to use. Assuming that DB[:a] is your Sequel::Database, DB[:a].disconnect will disconnect all available connections in DB[:a]'s connection pool. If you have more questions, you may want to post on Sequel's Google Group with the code you are using. – Jeremy Evans May 10 '10 at 16:28