On Jan 29, 3:04 pm, Jeremy Evans <[email protected]> wrote:
> Phrogz wrote:
> > The part that (I think) is making it painfully slow for large data
> > sets is that Dataset#<< does not always return the primary key of the
> > record inserted. So I have this code:
> > mapping = @transformation.call( ...rowdata... )
> > # mapping is a hash of field symbols to data
> > self << mapping
> > new_row = self.first( mapping )
> > �...@pk_after_transload[ orig_pk ] = new_row.pk
>
> > Is there a better Sequel, DB-agnostic way to be sure about the new
> > primary key values?
>
> Sequel adapters are supposed to return the new primary key value upon
> insert, but not all do. I'll accept patches for any that don't. It's
> especially hard to use those adapters with models, since they
> generally raise errors on model creation.
FWIW, the case I ran into was when explicitly inserting a PK in
SQLite3 on a table without autoincrement.
C:\>irb
irb(main):001:0> require 'rubygems'; require 'sequel'
=> true
irb(main):002:0> DB = Sequel.sqlite
=> #<Sequel::SQLite::Database: "sqlite:/">
irb(main):003:0> DB.execute "create table bobs (a smallint primary
key, b text )"; nil
=> nil
irb(main):004:0> class Bob < Sequel::Model; end
=> nil
irb(main):005:0> Bob << { :a=> 1, :b=>"hi" }
=> 1
irb(main):006:0> Bob << { :a=> 99, :b=>"oops" }
=> 2
> > Anyhow, in case anyone is interested, here's the code in two files.
> > The first file shows how I'm using it to specify transloading of data
> > for a simple site, and the second file is the library itself in its
> > current form.
>
> Do you have plans on packing this into a gem for others to use? Even
> just a bare repository on github would probably be helpful.
I do plan on packaging it up as a gem and/or Sequel Model plugin. I'll
want to clean up some of the hackiness first, especially surrounding
my nonsense CSV parser. (For some reason FasterCSV was barfing in the
middle of one of my large CSV files, so I had to resort to this
fragile parsing for now.) Before I released it I'd also need to make
it more robust in the areas of associations with :primary_key
specified.
Any suggestions on where proper abstractions should lie, how common
circular dependencies might be, etc. are welcome.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---