Thanks, Jeremy

I finally got a chance to address this today.  Your solution solved
the problem.  I guess the class accessor methods aren't accessible
within the block's scope, but assigning their results to variables
immediately before entering the create table block and using the
variables solved the problem.  This is what I ended up with:

    def create_staging_table
      puts "creating staging table..."
      flds = fields
      fdefs = field_defs
      Db.staging.create_table!(table, :engine => "innodb") do
        primary_key :id
        flds.each do |field|
          field_def = fdefs[field]
          dim_field = field_def["dimension"] ? "#{field}_id".to_sym : nil
          column(field, eval(field_def["type"]), :index => true)
          column(dim_field, Integer, :index => true) if dim_field
        end
      end

Regards,

Michael

On Tue, Oct 11, 2011 at 11:06 AM, Jeremy Evans <[email protected]> wrote:
> On Oct 11, 5:48 am, Michael Lang <[email protected]> wrote:
>> Hello,
>>
>> I'm trying to set up an ETL process to load some data from various
>> data sources into a data warehouse oriented database using Sequel.
>> I'm trying to dynamically construct the DB.create_table! block, but
>> the "field_defs" variable I have is out of scope and I can't access it
>> within the create table block.
>>
>> Any suggestion how I can do this?
>>
>> DB.create_table!(table) do
>>   primary_key :id
>>   field_defs.each do |field_def|
>>     column(field_def["field_name"], field_def["type"], :index =>
>> field_def["indexed"])
>>   end
>> end
>
> I'm not sure what you mean by "out of scope", but I assume you mean
> it's a method and not a local variable, in which case you just need to
> assign it to a local variable outside the block:
>
>  fds = field_defs
>  DB.create_table!(table) do
>    primary_key :id
>    fds.each do |fd|
>      column(fd["field_name"], fd["type"], :index => fd["indexed"])
>    end
>  end
>
> Jeremy
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sequel-talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sequel-talk?hl=en.
>
>



-- 
http://codeconnoisseur.org

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to