· 8 years ago · Apr 22, 2018, 09:36 PM
1# -*- coding: utf-8 -*-
2
3require 'sqlite3'
4
5module Termtter::Storage
6 class SQLite3
7 attr_reader :db
8
9 def initialize
10 @db = SQLite3::Database.new(Termtter::CONF_DIR + '/storage.db')
11 @db.type_translation = true
12 create_table
13 end
14
15 def create_table
16 sql =<<-SQL
17CREATE TABLE IF NOT EXISTS user (
18 id int NOT NULL,
19 screen_name text,
20 PRIMARY KEY (id)
21);
22CREATE TABLE IF NOT EXISTS post (
23 post_id int NOT NULL, -- twitterå´ã®postã®id
24 created_at int, -- 日付(Rubyã§UNIX時間ã«å¤‰æ›)
25 in_reply_to_status_id int, -- ã‚ã£ãŸã»ã†ãŒã‚ˆã„らã—ã„
26 in_reply_to_user_id int, -- ã‚ã£ãŸã»ã†ãŒã‚ˆã„らã—ã„
27 post_text text,
28 user_id int NOT NULL,
29 PRIMARY KEY (post_id)
30);
31 SQL
32 @db.execute_batch(sql)
33 end
34 end
35end