Skip to content

Instantly share code, notes, and snippets.

@koichiro
Created November 13, 2009 08:36
Show Gist options
  • Save koichiro/233681 to your computer and use it in GitHub Desktop.
Save koichiro/233681 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
config.plugins.storage.set_default(:backend, :sqlite3)
module Termtter::Storage
DATABASE_BACKEND = {
:sqlite3 => "sqlite3",
:sequel => "squerl",
:groonga => "groonga"
}
class DB
def initialize
@db = nil
end
end
end
# -*- coding: utf-8 -*-
require 'groonga'
module Termtter::Storage
DATABASE_FILE = Termtter::CONF_DIR + '/termtter.grn'
if File.exist?(DATABASE_FILE)
Groonga::Database.open(DATABASE_FILE)
else
Groonga::Database.create(:path => DATABASE_FILE)
Groonga::Schema.define do |schema|
schema.create_table("statuses") do |table|
table.integer("id")
table.integer("user_id")
table.string("text")
table.string("source")
table.time("created_at")
table.integer("in_reply_to_status_id")
table.integer("in_reply_to_user_id")
end
schema.create_table("users") do |table|
table.integer("id")
talbe.string("screen_name")
table.boolean("protected")
end
schema.create_table("terms",
:type => :patricia_trie,
:key_normalize => true,
:default_tokenizer => "TokenBigram") do |table|
table.index("statuses.text")
table.index("users.screen_name")
end
end
end
class Groonga
end
end
# -*- coding: utf-8 -*-
require 'sqlite3'
module Termtter::Storage
class SQLite3
attr_reader :db
def initialize
@db = SQLite3::Database.new(Termtter::CONF_DIR + '/storage.db')
@db.type_translation = true
create_table
end
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
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment