class Qwik::SiteDB

Attributes

db[R]

Public Class Methods

new(config, site) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 16
def initialize(config, site)
  require 'sqlite'          # SQLite
  #require 'sqlite3'        # SQLite3
  file = "#{config.cache_dir.path.to_win_dir}/#{site.sitename}.db"
  @db = ::SQLite::Database.new(file, 0)
# @db = ::SQLite3::Database.new(file)
end

Public Instance Methods

check_table(table) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 43
def check_table(table)
  raise unless /\A[a-z]+\z/ =~ table
  quote(table) # make sure
end
decode(org) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 39
def decode(org)
  ::SQLite::Database.decode(org)
end
delete(t, k) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 62
def delete(t, k)
  t = check_table(t)
  k = quote(k)
  @db.execute("delete from #{t} where key='#{k}';")
end
encode(org) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 35
def encode(org)
  ::SQLite::Database.encode(org)
end
get(t, k) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 76
def get(t, k)
  t = check_table(t)
  k = quote(k)
  v = @db.get_first_value("select value from #{t} where key='#{k}'" )
  return nil if v.nil?
  decode(v)
end
quote(org) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 31
def quote(org)
  ::SQLite::Database.quote(org)
end
set(t, k, v) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 68
def set(t, k, v)
  t = check_table(t)
  k = quote(k)
  delete(t, k) if get(t, k)
  v = encode(v)
  @db.execute("insert into #{t} values (NULL, '#{k}', '#{v}');")
end
table_create(table) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 48
    def table_create(table)
      t = check_table(table)
      sql = <<'EOT'
create table #{t}
(
  id INTEGER PRIMARY KEY,
  key TEXT,
  value VARCHAR
);
create index idx_#{t}_key on #{t} ( key );
EOT
      @db.execute(sql)
    end
table_exist?(table) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 24
def table_exist?(table)
  @db.table_info(table) {|row|
    return true
  }
  false
end
test(t) click to toggle source
# File vendor/qwik/lib/qwik/site-db.rb, line 98
def test(t)
end