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