We are trying to find out if our Rails 3.1.12 app opens the SQLite3 database (version 3.6 or above) with gem sequel. Here is what we did:
rails console
In the Rails console session, typed the following command:
sequel = Sequel.connect('sqlite://development')
It returns:
=> #<Sequel::SQLite::Database: "sqlite://development">
Also sequel.class returns:
=> Sequel::SQLite::Database
However when trying to select from the database with sequel.execute
or check a table with sequel.schema
, the returned text says that the table does not exist.
We are not quite sure if the database (development here) has been opened or not. How do we check that?
Offhand I'd say you can try:
The documentation for
test_connection
says:Years ago we'd use a benign query to tell if the connection is alive. You can try:
Which returns:
You'll probably want to catch any exceptions that might be raised if the query fails, but that would indicate that the connection was down too.
Michael Berkowski's comment deserves to be an answer.
The Sequel.connect method accepts a
test: true
option. According to the docs:Under the hood it causes Sequel to call
#test_connection
on the new db object.