Class: Moneta::Adapters::Sequel::Postgres 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, #initialize, #key?, #load, new

Methods included from Defaults

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

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

This class inherits a constructor from Moneta::Adapters::Sequel

Instance Method Details

#delete(key, 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.


236
237
238
239
240
# File 'lib/moneta/adapters/sequel.rb', line 236

def delete(key, options = {})
  if row = @table.returning(value_column).where(key_column => key).delete.first
    row[value_column]
  end
end

#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.


219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/moneta/adapters/sequel.rb', line 219

def increment(key, amount = 1, options = {})
  update_expr = ::Sequel[:convert_to].function(
    (::Sequel[:convert_from].function(
      ::Sequel[@table_name][value_column],
      'UTF8').cast(Integer) + amount).cast(String),
    'UTF8')

  if row = @table.
    returning(value_column).
    insert_conflict(target: key_column, update: {value_column => update_expr}).
    insert(key_column => key, value_column => blob(amount.to_s)).
    first
  then
    row[value_column].to_i
  end
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.


210
211
212
213
214
215
216
217
# File 'lib/moneta/adapters/sequel.rb', line 210

def store(key, value, options = {})
  @table.
    insert_conflict(
      target: key_column,
      update: {value_column => ::Sequel[:excluded][value_column]}).
    insert(key_column => key, value_column => blob(value))
  value
end