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/postgresql_adapter.rb
Defined Under Namespace
Classes: Base, MongodbAdapter, MysqlAdapter, MysqlClient, PostgresqlAdapter, SqliteAdapter
Constant Summary collapse
- CANONICAL_ADAPTERS =
The adapter names exwiw uses internally. Deliberately driver-agnostic (e.g. ‘mysql`, not `mysql2`) 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=mysql2` still works) and a Rails app’s ‘connection.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 ‘mysql2` gem (see MysqlAdapter#connection). It is deliberately not aliased from `trilogy`: a source app using the trilogy driver still needs the `mysql2` gem available for exwiw to connect, so accepting `–adapter=trilogy` would falsely imply trilogy support. Use `–adapter=mysql` in 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
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/exwiw/adapter.rb', line 161 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
145 146 147 |
# File 'lib/exwiw/adapter.rb', line 145 def execute(query_ast) raise NotImplementedError end |
#to_bulk_delete(select_query_ast, table) ⇒ Object
157 158 159 |
# File 'lib/exwiw/adapter.rb', line 157 def to_bulk_delete(select_query_ast, table) raise NotImplementedError end |
#to_bulk_insert(results, table) ⇒ Object
151 152 153 |
# File 'lib/exwiw/adapter.rb', line 151 def to_bulk_insert(results, table) raise NotImplementedError end |