Sha256: 6ddb6411827df4d435ebedd2ad09498f2c53127eea5992902925e0e9398e8390

Contents?: true

Size: 840 Bytes

Versions: 4

Compression:

Stored size: 840 Bytes

Contents

module ETL
  module Control
    class DatabaseSource < Source
      def initialize(control, configuration, definition)
        super
        connect
      end
      
      # Returns each row from the source
      def each
        conn = ActiveRecord::Base.connection
        conn.select_all("SELECT * FROM #{configuration[:table]}").each do |row|
          yield row
        end
      end
      
      private
      def connect
        # set up the DB connection
        ActiveRecord::Base.establish_connection(
            :adapter  => (configuration[:adapter] || :mysql),
            :username => (configuration[:username] || 'root'),
            :host     => (configuration[:host] || 'localhost'),
            :password => configuration[:password],
            :database => configuration[:database] 
        )
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
activewarehouse-etl-0.1.0 lib/etl/control/source/database_source.rb
activewarehouse-etl-0.2.0 lib/etl/control/source/database_source.rb
activewarehouse-etl-0.3.0 lib/etl/control/source/database_source.rb
activewarehouse-etl-0.4.0 lib/etl/control/source/database_source.rb