Object
Sqlite3 backend @api public
@param [Hash] options @option options [String] :file Database file @option options [String] :table ('moneta') Table name @option options [Fixnum] :busy_timeout (1000) Sqlite timeout if database is busy @option options [::Sqlite3::Database] :backend Use existing backend instance
# File lib/moneta/adapters/sqlite.rb, line 19 def initialize(options = {}) table = options[:table] || 'moneta' @backend = options[:backend] || begin raise ArgumentError, 'Option :file is required' unless options[:file] ::SQLite3::Database.new(options[:file]) end @backend.busy_timeout(options[:busy_timeout] || 1000) @backend.execute("create table if not exists #{table} (k blob not null primary key, v blob)") @stmts = [@exists = @backend.prepare("select exists(select 1 from #{table} where k = ?)"), @select = @backend.prepare("select v from #{table} where k = ?"), @replace = @backend.prepare("replace into #{table} values (?, ?)"), @delete = @backend.prepare("delete from #{table} where k = ?"), @clear = @backend.prepare("delete from #{table}"), @create = @backend.prepare("insert into #{table} values (?, ?)")] end
(see Proxy#clear)
# File lib/moneta/adapters/sqlite.rb, line 67 def clear(options = {}) @clear.execute! self end
(see Proxy#close)
# File lib/moneta/adapters/sqlite.rb, line 84 def close @stmts.each {|s| s.close } @backend.close nil end
(see Default#create)
# File lib/moneta/adapters/sqlite.rb, line 73 def create(key, value, options = {}) @create.execute!(key,value) true rescue SQLite3::ConstraintException # If you know a better way to detect whether an insert-ignore # suceeded, please tell me. @create.reset! false end
(see Proxy#delete)
# File lib/moneta/adapters/sqlite.rb, line 55 def delete(key, options = {}) value = load(key, options) @delete.execute!(key) value end
(see Proxy#increment)
# File lib/moneta/adapters/sqlite.rb, line 62 def increment(key, amount = 1, options = {}) @backend.transaction(:exclusive) { return super } end
(see Proxy#key?)
# File lib/moneta/adapters/sqlite.rb, line 38 def key?(key, options = {}) @exists.execute!(key).first.first.to_i == 1 end
(see Proxy#load)
# File lib/moneta/adapters/sqlite.rb, line 43 def load(key, options = {}) rows = @select.execute!(key) rows.empty? ? nil : rows.first.first end
(see Proxy#store)
# File lib/moneta/adapters/sqlite.rb, line 49 def store(key, value, options = {}) @replace.execute!(key, value) value end
Generated with the Darkfish Rdoc Generator 2.