Class: Termtter::Storage::DB

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/plugins/storage/DB.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDB

Returns a new instance of DB.



11
12
13
14
15
# File 'lib/plugins/storage/DB.rb', line 11

def initialize
  @db = SQLite3::Database.new(Termtter::CONF_DIR + '/storage.db')
  @db.type_translation = true
  create_table
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



9
10
11
# File 'lib/plugins/storage/DB.rb', line 9

def db
  @db
end

Instance Method Details

#create_tableObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/plugins/storage/DB.rb', line 17

def create_table
  sql =<<-SQL
CREATE TABLE IF NOT EXISTS user (
id          int NOT NULL,
screen_name text,
PRIMARY KEY (id)
);
CREATE TABLE IF NOT EXISTS post (
post_id          int NOT NULL,  -- twitter側のpostのid
created_at	     int,    	    -- 日付(RubyでUNIX時間に変換)
in_reply_to_status_id int, 	    -- あったほうがよいらしい
in_reply_to_user_id int,  	    -- あったほうがよいらしい
post_text text,
user_id int NOT NULL,
PRIMARY KEY (post_id)
);
  SQL
  @db.execute_batch(sql)
end