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 ="CREATE TABLE IF NOT EXISTS user (\nid          int NOT NULL,\nscreen_name text,\nPRIMARY KEY (id)\n);\nCREATE TABLE IF NOT EXISTS post (\npost_id          int NOT NULL,  -- twitter\u5074\u306Epost\u306Eid\ncreated_at       int,          -- \u65E5\u4ED8(Ruby\u3067UNIX\u6642\u9593\u306B\u5909\u63DB)\nin_reply_to_status_id int,      -- \u3042\u3063\u305F\u307B\u3046\u304C\u3088\u3044\u3089\u3057\u3044\nin_reply_to_user_id int,        -- \u3042\u3063\u305F\u307B\u3046\u304C\u3088\u3044\u3089\u3057\u3044\npost_text text,\nuser_id int NOT NULL,\nPRIMARY KEY (post_id)\n);\n  SQL\n  @db.execute_batch(sql)\nend\n"