Class: MultiCompress::DBDeployment::ReadableView
- Inherits:
-
Object
- Object
- MultiCompress::DBDeployment::ReadableView
- Defined in:
- lib/multi_compress/db_deployment.rb
Constant Summary collapse
- IDENTIFIER =
/\A[A-Za-z_][A-Za-z0-9_]*\z/.freeze
Instance Method Summary collapse
-
#initialize(target, options) ⇒ ReadableView
constructor
A new instance of ReadableView.
- #to_sql ⇒ Object
Constructor Details
#initialize(target, options) ⇒ ReadableView
Returns a new instance of ReadableView.
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/multi_compress/db_deployment.rb', line 440 def initialize(target, ) @target = target @table = qualified_identifier!(.fetch(:table), "--table") @view = qualified_identifier!(.fetch(:view), "--view") @column = identifier!(.fetch(:column), "--column") @columns = Array(.fetch(:columns)).reject(&:empty?).map { |value| identifier!(value, "--columns") } @decoded_name = identifier!(.fetch(:as), "--as") @extension_schema = identifier!(.fetch(:extension_schema, "multi_compress"), "--extension-schema") @dictionary_table = [:dictionary_table] && qualified_identifier!([:dictionary_table], "--dictionary-table") @dictionary_id_column = [:dictionary_id_column] && identifier!([:dictionary_id_column], "--dictionary-id-column") @registry_id_column = identifier!(.fetch(:registry_id_column, "id"), "--registry-id-column") @dictionary_sha256_column = identifier!(.fetch(:dictionary_sha256_column, "sha256"), "--dictionary-sha256-column") @dictionary_bytes_column = identifier!(.fetch(:dictionary_bytes_column, "bytes"), "--dictionary-bytes-column") if !!@dictionary_table != !!@dictionary_id_column raise Error, "--dictionary-table and --dictionary-id-column must be used together for MCDB2" end raise Error, "--columns must contain at least one plain column" if @columns.empty? raise Error, "--columns must not contain duplicate names" unless @columns.uniq.length == @columns.length raise Error, "--as must not duplicate a selected column" if @columns.include?(@decoded_name) rescue KeyError raise Error, "--table, --column, --view and --columns are required" end |
Instance Method Details
#to_sql ⇒ Object
463 464 465 466 467 468 469 |
# File 'lib/multi_compress/db_deployment.rb', line 463 def to_sql case @target when "postgres" then postgres_sql when "mysql" then mysql_sql else raise Error, "unsupported database target: #{@target.inspect}" end end |