On Nov 14, 5:59 pm, Paul F Fraser <[email protected]> wrote: > DB.create_table? :fonts do > primary_key :id > String :name > File :font_file > end > > class FontModel < Sequel::Model(:fonts) > end > > font = FontModel.new do |m| > m.name = "A Font' > file = file.open(filepath)
I'm guessing you mean File.open here. > m.font_file = file.to_s # will not accept file.to_sequel_blob That's because file is a File, not a String, and File#to_sequel_blob is not defined. Since you are using models, it should due the blob typecasting in the setter, so you shouldn't need to call to_sequel_blob manually. > m.save > end I'd use the following code instead of the above, FWIW: font = FontModel.create(:name=>"A Font", :font_file=>File.read(filepath)) > ----------------------------- > font = FontModel[1] > > puts font.class #=> Sequel::SQL::Blob > > How do I retrieve the contents as a file? You can't. Database blobs are returned as Sequel::SQL::Blob, which is a subclass of String. Most databases don't support a File/IO-like interface (MSSQL 2008's FILESTREAM might, but Sequel doesn't support that). Since the entire blob is returned when the database query is made, using an IO subclass instead of a String subclass wouldn't make sense. 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 -~----------~----~----~----~------~----~------~--~---
