-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement reset on query executor * make methods smaller * extract out query executor factory so we dont break lazy initialization of loggers
- Loading branch information
1 parent
dca4712
commit 24a3f34
Showing
5 changed files
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
# Entry point for PartitionManager | ||
# Entry point | ||
module PgDice | ||
# PartitionListerFactory is a class used to build PartitionListers | ||
# DatabaseConnectionFactory is a class used to build DatabaseConnections | ||
class DatabaseConnectionFactory | ||
extend Forwardable | ||
|
||
def_delegators :@configuration, :logger, :pg_connection, :dry_run | ||
def_delegators :@configuration, :logger, :dry_run | ||
|
||
def initialize(configuration, opts = {}) | ||
@configuration = configuration | ||
@query_executor = opts[:query_executor] ||= PgDice::QueryExecutor.new(logger: logger, | ||
connection_supplier: -> { pg_connection }) | ||
@query_executor_factory = opts[:query_executor_factory] ||= PgDice::QueryExecutorFactory.new(configuration, opts) | ||
end | ||
|
||
def call | ||
PgDice::DatabaseConnection.new(logger: logger, query_executor: @query_executor, dry_run: dry_run) | ||
PgDice::DatabaseConnection.new(logger: logger, query_executor: @query_executor_factory.call, dry_run: dry_run) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
# Entry point | ||
module PgDice | ||
# QueryExecutorFactory is a class used to build QueryExecutors | ||
class QueryExecutorFactory | ||
extend Forwardable | ||
|
||
def_delegators :@configuration, :logger, :pg_connection | ||
|
||
def initialize(configuration, opts = {}) | ||
@configuration = configuration | ||
@connection_supplier = opts[:connection_supplier] ||= -> { pg_connection } | ||
end | ||
|
||
def call | ||
PgDice::QueryExecutor.new(logger: logger, connection_supplier: @connection_supplier) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test_helper' | ||
|
||
class QueryExecutorFactoryTest < Minitest::Test | ||
def test_can_generate_query_executor | ||
assert PgDice::QueryExecutorFactory.new(PgDice.configuration).call | ||
end | ||
end |