module Adapter::Sqlite3

Constants

VERSION

Public Instance Methods

clear(options = nil) click to toggle source
# File lib/adapter/sqlite3.rb, line 27
def clear(options = nil)
  do_setup
  @clear.execute!
end
delete(key, options = nil) click to toggle source
# File lib/adapter/sqlite3.rb, line 22
def delete(key, options = nil)
  do_setup
  @delete.execute!(key)
end
key?(key, options = nil) click to toggle source
# File lib/adapter/sqlite3.rb, line 6
def key?(key, options = nil)
  @exists.execute!(key).first.first.to_i == 1
end
read(key, options = nil) click to toggle source
# File lib/adapter/sqlite3.rb, line 10
def read(key, options = nil)
  do_setup
  rows = @select.execute!(key)
  rows.empty? ? nil : rows.first.first
end
write(key, attributes, options = nil) click to toggle source
# File lib/adapter/sqlite3.rb, line 16
def write(key, attributes, options = nil)
  do_setup
  @replace.execute!(key, attributes)
  attributes
end

Private Instance Methods

do_setup() click to toggle source
# File lib/adapter/sqlite3.rb, line 33
def do_setup
  return if @sqlite_setup_done
  table = 'adapter'
  client.busy_timeout(options[:busy_timeout] || 1000)
  client.execute("create table if not exists #{table} (k blob not null primary key, v blob)")
  @statements =
    [@exists  = client.prepare("select exists(select 1 from #{table} where k = ?)"),
     @select  = client.prepare("select v from #{table} where k = ?"),
     @replace = client.prepare("replace into #{table} values (?, ?)"),
     @delete  = client.prepare("delete from #{table} where k = ?"),
     @clear   = client.prepare("delete from #{table}")]
  @sqlite_setup_done=true
end