Module: Exwiw::Adapter
- Defined in:
- lib/exwiw/adapter.rb,
lib/exwiw/adapter/mysql_client.rb,
lib/exwiw/adapter/mysql_adapter.rb,
lib/exwiw/adapter/sqlite_adapter.rb,
lib/exwiw/adapter/mongodb_adapter.rb,
lib/exwiw/adapter/sql_bulk_insert.rb,
lib/exwiw/adapter/postgresql_adapter.rb
Defined Under Namespace
Modules: SqlBulkInsert Classes: Base, MongodbAdapter, MysqlAdapter, MysqlClient, PostgresqlAdapter, SqliteAdapter
Constant Summary collapse
- CANONICAL_ADAPTERS =
The adapter names exwiw uses internally. Deliberately driver-agnostic (e.g.
mysql, notmysql2) so they describe the database, not the Ruby driver or Rails ActiveRecord adapter that happens to talk to it. %w[mysql sqlite postgresql mongodb].freeze
- ADAPTER_ALIASES =
Maps the older driver-flavored spellings onto exwiw's canonical adapter name, so the CLI stays backward compatible (
--adapter=mysql2still works) and a Rails app'sconnection.adapter_name(e.g. "Mysql2", "SQLite") is absorbed — lookup is case-insensitive (see .normalize_name).NOTE: this only normalizes the name; exwiw always connects with the
mysql2gem (see MysqlAdapter#connection). It is deliberately not aliased fromtrilogy: a source app using the trilogy driver still needs themysql2gem available for exwiw to connect, so accepting--adapter=trilogywould falsely imply trilogy support. Use--adapter=mysqlin that case. { "mysql2" => "mysql", "sqlite3" => "sqlite", }.freeze
Class Method Summary collapse
- .build(connection_config, logger) ⇒ Object
-
.normalize_name(name) ⇒ Object
Normalize an adapter name to its canonical form.
Instance Method Summary collapse
- #execute(query_ast) ⇒ Object
- #to_bulk_delete(select_query_ast, table) ⇒ Object
- #to_bulk_insert(results, table) ⇒ Object
Class Method Details
.build(connection_config, logger) ⇒ Object
313 314 315 316 317 318 319 320 321 322 323 324 325 326 |
# File 'lib/exwiw/adapter.rb', line 313 def self.build(connection_config, logger) case normalize_name(connection_config.adapter) when 'sqlite' Adapter::SqliteAdapter.new(connection_config, logger) when 'mysql' Adapter::MysqlAdapter.new(connection_config, logger) when 'postgresql' Adapter::PostgresqlAdapter.new(connection_config, logger) when 'mongodb' Adapter::MongodbAdapter.new(connection_config, logger) else raise "Unsupported adapter: #{connection_config.adapter.inspect}" end end |
.normalize_name(name) ⇒ Object
Normalize an adapter name to its canonical form. Unknown names are passed through (downcased) so the caller can reject them with a clear message. Returns nil for nil input.
28 29 30 31 32 33 |
# File 'lib/exwiw/adapter.rb', line 28 def self.normalize_name(name) return nil if name.nil? key = name.to_s.downcase ADAPTER_ALIASES.fetch(key, key) end |
Instance Method Details
#execute(query_ast) ⇒ Object
297 298 299 |
# File 'lib/exwiw/adapter.rb', line 297 def execute(query_ast) raise NotImplementedError end |
#to_bulk_delete(select_query_ast, table) ⇒ Object
309 310 311 |
# File 'lib/exwiw/adapter.rb', line 309 def to_bulk_delete(select_query_ast, table) raise NotImplementedError end |
#to_bulk_insert(results, table) ⇒ Object
303 304 305 |
# File 'lib/exwiw/adapter.rb', line 303 def to_bulk_insert(results, table) raise NotImplementedError end |