Class: Picky::Backends::SQLite::Value

Inherits:
Basic show all
Defined in:
lib/picky/backends/sqlite/value.rb

Instance Attribute Summary

Attributes inherited from Basic

#cache_path, #db

Instance Method Summary collapse

Methods inherited from Basic

#asynchronous, #clear, #drop_table, #dump, #dump_sqlite, #empty, #initial, #initialize, #load, #reset, #synchronous, #to_s, #transaction, #truncate_db

Methods included from Helpers::File

#create_directory

Constructor Details

This class inherits a constructor from Picky::Backends::SQLite::Basic

Instance Method Details

#[](key) ⇒ Object



21
22
23
24
25
26
# File 'lib/picky/backends/sqlite/value.rb', line 21

def [] key
  res = db.execute "SELECT value FROM key_value WHERE key = ? LIMIT 1;", key.to_s
  return nil if res.empty?

  MultiJson.decode res.first.first
end

#[]=(key, value) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/picky/backends/sqlite/value.rb', line 13

def []= key, value
  db.execute 'INSERT OR REPLACE INTO key_value (key, value) VALUES (?,?)',
             key.to_s,
             MultiJson.encode(value)

  value
end

#create_tableObject



9
10
11
# File 'lib/picky/backends/sqlite/value.rb', line 9

def create_table
  db.execute 'create table key_value (key varchar(255) PRIMARY KEY, value text);'
end

#delete(key) ⇒ Object



28
29
30
# File 'lib/picky/backends/sqlite/value.rb', line 28

def delete key
  db.execute "DELETE FROM key_value WHERE key = (?)", key.to_s
end