Class: Exwiw::Adapter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/exwiw/adapter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection_config, logger) ⇒ Base

Returns a new instance of Base.



8
9
10
11
# File 'lib/exwiw/adapter.rb', line 8

def initialize(connection_config, logger)
  @connection_config = connection_config
  @logger = logger
end

Instance Attribute Details

#connection_configObject (readonly)

Returns the value of attribute connection_config.



6
7
8
# File 'lib/exwiw/adapter.rb', line 6

def connection_config
  @connection_config
end

Class Method Details

.table_config_classObject

The config class that this adapter consumes. Runner uses this to decide which Serdes type to load scenario JSON into. SQL adapters share the SQL-shaped TableConfig; non-SQL adapters override.



16
17
18
# File 'lib/exwiw/adapter.rb', line 16

def self.table_config_class
  TableConfig
end

Instance Method Details

#build_query(table, dump_target, table_by_name) ⇒ Object

Returns adapter-specific query object (e.g. Exwiw::QueryAst::Select for SQL).

Returns:

  • (Object)

    adapter-specific query object (e.g. Exwiw::QueryAst::Select for SQL)

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/exwiw/adapter.rb', line 24

def build_query(table, dump_target, table_by_name)
  raise NotImplementedError
end

#dump_schema(ordered_tables, output_path) ⇒ Object

Write the leading schema-creation file for this adapter to ‘output_path`. Default is a no-op; subclasses override to emit idempotent DDL so the generated dump can be applied to an empty database.

Parameters:

  • ordered_tables (Array)

    table configs in dependency order

  • output_path (String)

    absolute path to write to



46
47
# File 'lib/exwiw/adapter.rb', line 46

def dump_schema(ordered_tables, output_path)
end

#dumpable?(_config) ⇒ Boolean

Whether the given config produces its own dump output and needs an independent processing pass. SQL adapters always do; non-SQL adapters may exclude e.g. embedded subdocument configs.

Returns:

  • (Boolean)


57
58
59
# File 'lib/exwiw/adapter.rb', line 57

def dumpable?(_config)
  true
end

#output_extensionObject

File extension used for dump output (e.g. ‘sql’ for SQL, ‘jsonl’ for MongoDB).



29
30
31
# File 'lib/exwiw/adapter.rb', line 29

def output_extension
  'sql'
end

#post_insert_sql(_table) ⇒ Object

Optional SQL appended to the per-table insert-NNN-<table>.* file after the bulk INSERT statements. Use to bring side-state in sync with the explicit IDs that were just inserted (e.g. PostgreSQL sequences). Default: nil (nothing appended).



70
71
72
# File 'lib/exwiw/adapter.rb', line 70

def post_insert_sql(_table)
  nil
end

#schema_output_extensionObject

File extension used for the leading ‘insert-000-schema.*` file. SQL adapters emit `.sql` (CREATE TABLE IF NOT EXISTS …); MongodbAdapter overrides to `.js` (mongosh-runnable createCollection / createIndex).



36
37
38
# File 'lib/exwiw/adapter.rb', line 36

def schema_output_extension
  'sql'
end

#supports_bulk_delete?Boolean

Whether this adapter emits delete-NNN-*.sql files.

Returns:

  • (Boolean)


50
51
52
# File 'lib/exwiw/adapter.rb', line 50

def supports_bulk_delete?
  true
end

#validate_as_dump_target!(_config) ⇒ Object

Hook for adapter-specific validation when this config is used as the dump_target. Default: nothing to validate.



63
64
# File 'lib/exwiw/adapter.rb', line 63

def validate_as_dump_target!(_config)
end