On Tuesday, May 1, 2012 11:52:49 AM UTC-7, Joel VanderWerf wrote:
>
>
> Is it possible to marshal a dataset? I really mean the Dataset instance 
> itself, not the result set. 
>
> On unmarshalling, the dataset would have to be reassociated with the 
> database somehow. 
>
> To be precise, this is what I wanted: 
>
> require 'sequel' 
>
> DB = Sequel.sqlite 
>
> DB.create_table :t do 
>    primary_key :id 
>    float :f 
> end 
>
> q = DB[:t].filter{ f > 3 } 
> puts q.sql        # => SELECT * FROM `t` WHERE (`f` > 3) 
>
> s = Marshal.dump(q) 
>   # fails here, because there's a proc in q, and a database 
>

Well, the proc isn't the same proc you passed to filter, since that proc is 
eagerly evaluated.  The Database object has many procs in it, though.
 

>
> qq = Marshal.load(s) 
> # qq.connect DB ? 
> puts qq.sql       # => SELECT * FROM `t` WHERE (`f` > 3) 
>
>
Dataset and Database instances are not designed to be marshalable.  This 
may work for your use case:

  q.db = nil
  s = Marshal.dump(q)
  qq = Marshal.load(s)
  qq.db = DB
 
I don't guarantee this works for all datasets, though.  Many adapters use 
datasets that are instances of anonymous classes, for example.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/iewcGWN-kkQJ.
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