diff options
| author | Teddy Wing | 2017-04-29 20:20:49 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2017-04-29 20:23:08 +0200 | 
| commit | f1c4164aef7ef88735a254e1301c3e4bf5978714 (patch) | |
| tree | 5453a707a8f547eeda908b9debd9206839f73a0d /lib/dbshell | |
| parent | 1156010222a51643c7921aa953aad052e91b666c (diff) | |
| download | dbshell-rails-f1c4164aef7ef88735a254e1301c3e4bf5978714.tar.bz2 | |
dbshell.rake: Use `DBShell::DatabaseClient`
Instead of calling `DBShell::Sqlite3Client` directly, call the wrapper
class that will delegate to `Sqlite3Client`, `PostgresClient`, etc.
depending on the value of `adapter` in the database connection params
passed in.
This allows us to have a single interface that we can call from the Rake
task that can handle any of the database adapters that we support.
Diffstat (limited to 'lib/dbshell')
| -rw-r--r-- | lib/dbshell/database_client.rb | 9 | ||||
| -rw-r--r-- | lib/dbshell/rails/tasks/dbshell.rake | 4 | 
2 files changed, 11 insertions, 2 deletions
| diff --git a/lib/dbshell/database_client.rb b/lib/dbshell/database_client.rb index 8d55095..edea777 100644 --- a/lib/dbshell/database_client.rb +++ b/lib/dbshell/database_client.rb @@ -1,3 +1,6 @@ +require 'dbshell/sqlite3_client' +require 'dbshell/postgres_client' +  class DBShell::DatabaseClient    def self.handler(connection_params)      case connection_params['adapter'] @@ -9,6 +12,12 @@ class DBShell::DatabaseClient        raise DBShell::InvalidDatabaseAdapter      end    end + +  def self.runshell(connection_params) +    self +      .handler(connection_params) +      .runshell(connection_params) +  end  end diff --git a/lib/dbshell/rails/tasks/dbshell.rake b/lib/dbshell/rails/tasks/dbshell.rake index 0505e38..7b192c3 100644 --- a/lib/dbshell/rails/tasks/dbshell.rake +++ b/lib/dbshell/rails/tasks/dbshell.rake @@ -1,10 +1,10 @@ -require 'dbshell/sqlite3_client' +require 'dbshell/database_client'  task :dbshell do  # {"default"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000}, "development"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/development.sqlite3"}, "test"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/test.sqlite3"}, "production"=>{"adapter"=>"sqlite3", "pool"=>5, "timeout"=>5000, "database"=>"db/production.sqlite3"}}    env = ENV.fetch('RAILS_ENV', 'development') -  DBShell::Sqlite3Client.runshell( +  DBShell::DatabaseClient.runshell(      Rails.application.config.database_configuration[env]    )  end | 
