### Home Classes Methods

### In Files

- lib/plugins/storage/sqlite3.rb

### Parent

Object

### Methods

- ::new
- #create_table
- #find_id
- #find_text
- #find_user
- #find_user_id
- #insert
- #name
- #size
- #update
- #update_user

### Files

- ChangeLog
- README.rdoc

### Class/Module Index

Quicksearch

- Termtter
- Termtter::API
- Termtter::ActiveRubytter
- Termtter::Client
- Termtter::Client::DirectMessage
- Termtter::Client::Jakigan
- Termtter::Client::SearchEvent
- Termtter::Client::UserSearchEvent
- Termtter::Command
- Termtter::CommandCanceled
- Termtter::CommandLine
- Termtter::CommandNotFound
- Termtter::Config
- Termtter::ConfigSetup
- Termtter::Crypt
- Termtter::English
- Termtter::Event
- Termtter::HTTPpool
- Termtter::Hook
- Termtter::HookCanceled
- Termtter::Hookable
- Termtter::JSONError
- Termtter::MemoryCache
- Termtter::MemoryCache::MemCacheMock
- Termtter::OptParser
- Termtter::Plugin
- Termtter::Plugin::Screen
- Termtter::Plugins
- Termtter::Plugins::Haml
- Termtter::Plugins::ListSwitch
- Termtter::RubytterProxy
- Termtter::RubytterProxy::FrequentAccessError
- Termtter::RubytterProxy::LimitManager
- Termtter::Status
- Termtter::StdOut
- Termtter::Storage
- Termtter::Storage::SQLite3
- Termtter::Storage::Status
- Termtter::Task
- Termtter::TaskManager
- Termtter::TypableIdGenerator
- Termtter::UserStreamReceiver
- Yharian
- Yharian::Alex
- Yharian::Jenifer
- Yharian::Remark
- Yharian::Speaker
- Yharian::Vicki
- Yharian::Yhara
- HatenaKeywordHaiku
- HatenaKeywordHaiku::Word
- OAuth
- OAuth::AccessToken
- Readline
- Readline::LIBREADLINE
- AAMaker
- Array
- BrowserNotFound
- Growl
- IRB
- Object
- Status
- String
- Symbol
- TermColor
- TermtterIrcGateway
- User

No matching classes.

# Termtter::Storage::SQLite3

### Constants

CREATE_TABLE
FIND
FIND_ID
FIND_USER
FIND_USER_ID

### Public Class Methods

new(file = Termtter::CONF_DIR + '/storage.db') click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 8
    def initialize(file = Termtter::CONF_DIR + '/storage.db')
      @db = ::SQLite3::Database.new(file)
      @db.type_translation = true
      create_table
    end

### Public Instance Methods

create_table() click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 34
    def create_table
      @db.execute_batch(CREATE_TABLE)
    end

find_id(id) click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 85
    def find_id(id)
      result = nil
      @db.execute(FIND_ID, id) do |created_at, screen_name, post_text, in_reply_to_status_id, post_id, user_id|
        result = Termtter::ActiveRubytter.new({
            :id => post_id,
            :created_at => created_at,
            :text => post_text,
            :in_reply_to_status_id => in_reply_to_status_id,
            :in_reply_to_user_id => nil,
            :user => {
              :id => user_id,
              :screen_name => screen_name
            }
          })
      end
      result
    end

find_text(text = '') click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 107
    def find_text(text = '')
      result = []
      @db.execute(FIND, text) do |created_at, screen_name, post_text, in_reply_to_status_id, post_id, user_id|
        created_at = Time.at(created_at).to_s
        result << Termtter::ActiveRubytter.new({
            :id => post_id,
            :created_at => created_at,
            :text => post_text,
            :in_reply_to_status_id => in_reply_to_status_id,
            :in_reply_to_user_id => nil,
            :user => {
              :id => user_id,
              :screen_name => screen_name
            }
          })
      end
      result
    end

find_user(user = "") click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 130
    def find_user(user = "")
      result = []
      sql = FIND_USER + user.split(' ').map!{|que| que.gsub(/(\w+)/, 'screen_name like \%\1%\')}.join(' or ')
      @db.execute(sql) do |created_at, screen_name, post_text, in_reply_to_status_id, post_id, user_id|
        created_at = Time.at(created_at).to_s
        result << Termtter::ActiveRubytter.new({
            :id => post_id,
            :created_at => created_at,
            :text => post_text,
            :in_reply_to_status_id => in_reply_to_status_id,
            :in_reply_to_user_id => nil,
            :user => {
              :id => user_id,
              :screen_name => screen_name
            }
          })
      end
      result
    end

find_user_id(user_id) click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 60
    def find_user_id(user_id)
      result = nil
      @db.execute(FIND_USER_ID, user_id) do |id, screen_name|
        result = { :id => id, :screen_name => screen_name}
      end
      result
    end

insert(status) click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 68
    def insert(status)
      return nil unless status[:text]
      @db.execute(
        "insert into post values(?,?,?,?,?,?)",
        status[:post_id],
        status[:created_at],
        status[:in_reply_to_status_id],
        status[:in_reply_to_user_id],
        status[:text],
        status[:user_id])
      update_user(status[:user_id], status[:screen_name])
    end

name() click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 14
    def name
      "sqlite3"
    end

size() click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 150
    def size
      @db.get_first_value("select count(*) from post").to_i
    end

update(status) click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 38
    def update(status)
      @db.transaction
      begin
        return nil if find_id(status[:post_id])
        insert(status)
      ensure
        @db.commit
      end
    end

update_user(user_id, screen_name) click to toggle source

    # File lib/plugins/storage/sqlite3.rb, line 48
    def update_user(user_id, screen_name)
      return nil if find_user_id(user_id)
      @db.execute(
        "insert into user values(?,?)",
        status[:user_id],
        status[:screen_name])
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.