Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

Missing/Empty? import/postgresql.rb

#22

I am just trying out ar-extensions (0.9.1) for the first time and when I do this:

    require 'ar-extensions/adapters/postgresql'
    require 'ar-extensions/import/postgresql'
...
      if new_rates.size % batch_size == 0 
        CurrencyExchangeRate.import new_rates, 
          :validate => validate
        new_rates = [] # empty the rates array
      end
...

Then I see this:

undefined method `import' for #Class:0x2b2e4c6dd850 (NoMethodError)

If I look at gems/ar-extensions-0.9.1/lib/ar-extensions/import/postgresql,rb I see an empty file:

$ ll /usr/lib64/ruby/gems/1.8/gems/ar-extensions-0.9.1/lib/ar-extensions/import/* ... -rw-r--r-- 1 root root 0 May 11 09:43 /usr/lib64/ruby/gems/1.8/gems/ar-extensions-0.9.1/lib/ar-extensions/import/postgresql.rb ...

Is this intended?

Reported by James B. Byrne · May 12th, 2009 @ 02:40 PM

State: new
Milestone: none
Assigned to: Zach Dennis Zach Dennis

Activity

  1. Zach Dennis
    Zach Dennis

    Hi James,

    I know this hasn't been implemented as I don't use PostgreSQL, but I am surprised by the error. It should fall back one insert per row. I'll look into this.

    May 12th, 2009 @ 02:44 PM

  2. James B. Byrne
    James B. Byrne

    Maybe it is something that I am doing wrong in my call. I back dated to 0.8.2 and get the same result.

    I am trying to do this within an ActiverRecord model so perhaps that is the problem. The entire code looks like this:

    class CurrencyExchangeRate < ActiveRecord::Base
      # This is a class method not an instance.
      def self.load(rates,date=false)
        # date can be nil, false, true or a date
        date = Time.now.strftime("%Y-%m-%d") unless date  
          # not nil or false
        date = date unless date == true                   
          # not a date
        # otherwise we use the individual dates passed in the array
        
        # Now, require ar-extensions for mass update
        require 'ar-extensions/adapters/postgresql'
        require 'ar-extensions/import/postgresql'
    
        # Now, set the number of rates to update per batch
        batch_size = 100
    
        # Now, define the row update array
        new_rates = Array.new # could use [] but this is clearer
    
        rates.each do |rate|  # rate is a hash
          new_rates << CurrencyExchangeRate.new(rate)
          if new_rates.size % batch_size == 0 
            # if we have exactly batch_size
            CurrencyExchangeRate.import new_rates, 
              :validate => validate
            new_rates = [] # empty the rates array
          end
        end
        if new_rates.size > 0
          # load last batch regardless of size
          CurrencyExchangeRate.import new_rates, 
            :validate => validate
        end
        puts 'forex loader end'
      end
    

    May 12th, 2009 @ 03:23 PM

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.