Class: MultiCompress::DBDeployment::ReadableView

Inherits:
Object
  • Object
show all
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

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, options)
  @target = target
  @table = qualified_identifier!(options.fetch(:table), "--table")
  @view = qualified_identifier!(options.fetch(:view), "--view")
  @column = identifier!(options.fetch(:column), "--column")
  @columns = Array(options.fetch(:columns)).reject(&:empty?).map { |value| identifier!(value, "--columns") }
  @decoded_name = identifier!(options.fetch(:as), "--as")
  @extension_schema = identifier!(options.fetch(:extension_schema, "multi_compress"), "--extension-schema")
  @dictionary_table = options[:dictionary_table] && qualified_identifier!(options[:dictionary_table], "--dictionary-table")
  @dictionary_id_column = options[:dictionary_id_column] && identifier!(options[:dictionary_id_column], "--dictionary-id-column")
  @registry_id_column = identifier!(options.fetch(:registry_id_column, "id"), "--registry-id-column")
  @dictionary_sha256_column = identifier!(options.fetch(:dictionary_sha256_column, "sha256"), "--dictionary-sha256-column")
  @dictionary_bytes_column = identifier!(options.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_sqlObject



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