# Sequel Newbie question

**URL:** <https://www.ruby-forum.com/t/sequel-newbie-question/156235>\
**Category:** Ruby\
**Created:** [December 23, 2008, 7:25am UTC](https://www.ruby-forum.com/t/sequel-newbie-question/156235 "2008-12-23T07:25:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [December 23, 2008, 7:25am UTC](https://www.ruby-forum.com/t/sequel-newbie-question/156235/1 "2008-12-23T07:25:03Z")

</div>

Hello Folks, I am trying out sequel and have a simple question.

Here is my sample:  
DB = Sequel.connect(‘mysql://blah:blah@localhost:3306/thyu’)

news\_stories = DB[:feed\_items].filter({:content\_grabbed =\> ‘0’} &  
(:url.like(/abcd.com/)))

puts news\_stories.count  
for story in news\_stories

# logic to grab content

```
 if (content.length > 0)
     contentDoc = Hpricot(content).to_plain_text
     File.open("#{article_id}.txt", 'w') {|f| f.write(contentDoc) }
     puts article_id
     story.update(:content_grabbed => '1') # does seem to update ..

```

WHY?

```
     # Also how do I save another data to ANother table?
     # I get an sql error.
     puts "Did it update?"
     exit
 end

```

end

I am sure I am missing something basic here…Can u help pls?

Thanks!  
Rubix

---

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [December 25, 2008, 2:51am UTC](https://www.ruby-forum.com/t/sequel-newbie-question/156235/2 "2008-12-25T02:51:08Z")

</div>

Ruby N. wrote:

> Hello Folks, I am trying out sequel and have a simple question.
> 
> Here is my sample:  
> DB = Sequel.connect(‘mysql://blah:blah@localhost:3306/thyu’)
> 
> news\_stories = DB[:feed\_items].filter({:content\_grabbed =\> ‘0’} &  
> (:url.like(/abcd.com/)))
> 
> puts news\_stories.count  
> for story in news\_stories
> 
> # logic to grab content
> 
> ```
> if (content.length > 0)
> contentDoc = Hpricot(content).to_plain_text
> File.open("#{article_id}.txt", 'w') {|f| f.write(contentDoc) }
> puts article_id
> story.update(:content_grabbed => '1') # does seem to update ..
> 
> ```

story is a Hash, not a Sequel::Model. You are calling Hash#update,  
which updates the Hash, but does not change the database. What you want  
to do is:

# Filter to just the record, then update

DB[:feed\_items].filter(:id=\>story[:id]).update(:content\_grabbed =\>  
‘1’)

Or you could just use a model, which will do basically the same thing.

> ```
> # Also how do I save another data to ANother table?
> 
> ```

Just change the table you are using, and assuming the record would be  
new in that table:

DB[:feed\_items2].insert(story)

> ```
> # I get an sql error.
> 
> ```

You need to post the error you are getting with a traceback in order to  
provide adequate support.

> ```
> puts "Did it update?"
> exit
> end
> 
> ```
> 
> end

Jeremy
