Module: Rutt::DB::Item

Extended by:
Item
Included in:
Item
Defined in:
lib/rutt/db/item.rb

Instance Method Summary collapse

Instance Method Details

#all(feed) ⇒ Object



25
26
27
# File 'lib/rutt/db/item.rb', line 25

def all(feed)
  $db.execute("select * from items where feed_id = ? order by published_at desc", feed['id'])
end

#make_table!Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rutt/db/item.rb', line 7

def make_table!
  $db.execute(%{
    create table if not exists items (
                id integer PRIMARY KEY,
                feed_id integer,
                title text,
                url text,
                description text,
                read int default 0,
                prioritize int default 0,
                published_at DATE NOT NULL DEFAULT (datetime('now','localtime')),
                created_at NOT NULL DEFAULT CURRENT_TIMESTAMP,
                updated_at NOT NULL DEFAULT CURRENT_TIMESTAMP,
                UNIQUE(url),
                FOREIGN KEY(feed_id) REFERENCES feeds(id))
  })
end

#mark_as_read(item) ⇒ Object



37
38
39
# File 'lib/rutt/db/item.rb', line 37

def mark_as_read(item)
  $db.execute("update items set read = 1 where id = #{item['id']}")
end

#mark_as_unread(item) ⇒ Object



33
34
35
# File 'lib/rutt/db/item.rb', line 33

def mark_as_unread(item)
  $db.execute("update items set read = 0 where id = #{item['id']}")
end

#sent_to_instapaper(item) ⇒ Object

Weak abstraction.



42
43
44
# File 'lib/rutt/db/item.rb', line 42

def sent_to_instapaper(item)
  $db.execute("update items set read = 2 where id = #{item['id']}")
end

#unread(feed, limit = 10) ⇒ Object



29
30
31
# File 'lib/rutt/db/item.rb', line 29

def unread(feed, limit=10)
  $db.execute("select * from items where feed_id = ? and read = 0 order by published_at desc limit #{limit}", feed['id'])
end