Class: Moneta::Adapters::Sequel::SQLite Private

Inherits:
Moneta::Adapters::Sequel show all
Defined in:
lib/moneta/adapters/sequel.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary

Constants inherited from Moneta::Adapters::Sequel

UniqueConstraintViolation

Instance Attribute Summary

Attributes inherited from Moneta::Adapters::Sequel

#backend, #key_column, #value_column

Instance Method Summary collapse

Methods inherited from Moneta::Adapters::Sequel

#clear, #close, #create, #delete, #each_key, #fetch_values, #key?, #load, new, #slice, #values_at

Methods included from Defaults

#[], #[]=, #close, #create, #decrement, #each_key, #features, #fetch, #fetch_values, included, #key?, #slice, #supports?, #update, #values_at

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options) ⇒ SQLite

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of SQLite



707
708
709
710
711
712
# File 'lib/moneta/adapters/sequel.rb', line 707

def initialize(options)
  @version = backend.get(::Sequel[:sqlite_version].function)
  # See https://sqlite.org/lang_UPSERT.html
  @can_upsert = ::Gem::Version.new(@version) >= ::Gem::Version.new('3.24.0')
  super
end

Instance Method Details

#increment(key, amount = 1, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



719
720
721
722
723
724
725
# File 'lib/moneta/adapters/sequel.rb', line 719

def increment(key, amount = 1, options = {})
  return super unless @can_upsert
  @backend.transaction do
    @increment.call(key: key, value: amount.to_s, amount: amount)
    Integer(load(key))
  end
end

#merge!(pairs, options = {}, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



727
728
729
730
731
732
733
734
# File 'lib/moneta/adapters/sequel.rb', line 727

def merge!(pairs, options = {}, &block)
  @backend.transaction do
    pairs = yield_merge_pairs(pairs, &block) if block_given?
    @table.insert_conflict(:replace).import([key_column, value_column], blob_pairs(pairs).to_a)
  end

  self
end

#store(key, value, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



714
715
716
717
# File 'lib/moneta/adapters/sequel.rb', line 714

def store(key, value, options = {})
  @table.insert_conflict(:replace).insert(key_column => key, value_column => blob(value))
  value
end