class Wukong::Load::SQLLoader

Loads data into SQL databases.

Uses the 'mysql' gem to connect and write data. Yes, MySQL != SQL but we'll get there, I promise…

Allows loading records into a given database and table. Records can have fields `_database` and `_table` which override the given database and table on a per-record basis.

Records can have an `_id` field which indicates an update, not an insert.

The names of these fields within each record (`_database`, `_table`, and `_id`) can be customized.

Attributes

client[RW]

The Mongo::MongoClient we'll use for talking to MongoDB.

Public Instance Methods

setup() click to toggle source

Creates the client connection.

# File lib/wukong-load/loaders/sql.rb, line 60
def setup
  begin
    require 'mysql2'
  rescue LoadError => e
    raise Error.new("Please ensure that the 'mysql2' gem is installed and available (in your Gemfile)")
  end
  log.debug("Connecting to SQL server at <#{host}:#{port}> as <#{username}>#{' using password' if password}...")
  begin
    self.client = Mysql2::Client.new(sql_params)
  rescue => e
    raise Error.new(e)
  end
end