Ruby 无法使用sequel gem断开与postgres数据库的连接
我刚刚开始使用Sequel rubygem,而“断开连接”方法似乎不起作用。以下是我的IRB测试会话的输出:Ruby 无法使用sequel gem断开与postgres数据库的连接,ruby,postgresql,sequel,Ruby,Postgresql,Sequel,我刚刚开始使用Sequel rubygem,而“断开连接”方法似乎不起作用。以下是我的IRB测试会话的输出: 1.9.3-p194 :002 > require 'sequel' => true 1.9.3-p194 :003 > DB = Sequel.connect('postgres://postgres:mypassword@my_pg_host:5432/my_db') => #<Sequel::Postgres::Database: "postgr
1.9.3-p194 :002 > require 'sequel'
=> true
1.9.3-p194 :003 > DB = Sequel.connect('postgres://postgres:mypassword@my_pg_host:5432/my_db')
=> #<Sequel::Postgres::Database: "postgres://postgres:mypassword@my_pg_host:5432/my_db">
1.9.3-p194 :004 > DB.test_connection
=> true
1.9.3-p194 :005 > DB.disconnect
=> []
1.9.3-p194 :006 > DB.test_connection
=> true
1.9.3-p194:002>要求“续集”
=>正确
1.9.3-p194:003>DB=Sequel.connect('postgres://postgres:mypassword@my_pg_主机:5432/my_db')
=> #
1.9.3-p194:004>DB.test\U连接
=>正确
1.9.3-p194:005>DB.断开
=> []
1.9.3-p194:006>DB.test_连接
=>正确
我在Sequel文档中没有看到任何东西表明这不起作用的原因:
我错过什么了吗
DB.disconnect
断开连接池中当前的所有连接,并从池中删除连接。之后调用DB.test\u connection
将在连接池中查找连接,由于连接池为空,将导致创建新连接
您发布的代码完全是预期的行为,但我猜您没有意识到
DB
并不表示与数据库的单个连接。Ahh,这是有道理的。谢谢你的澄清!