Class: Moneta::Adapters::Sequel::PostgresHStore 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

#close, new

Methods included from Defaults

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

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options, backend) ⇒ PostgresHStore

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


245
246
247
248
249
250
# File 'lib/moneta/adapters/sequel.rb', line 245

def initialize(options, backend)
  @row = options.delete(:hstore).to_s
  backend.extension :pg_hstore
  ::Sequel.extension :pg_hstore_ops
  super
end

Instance Method Details

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


300
301
302
303
# File 'lib/moneta/adapters/sequel.rb', line 300

def clear(options = {})
  @table.where(key_column => @row).update(value_column => '')
  self
end

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


292
293
294
295
296
297
298
# File 'lib/moneta/adapters/sequel.rb', line 292

def create(key, value, options = {})
  create_row
  1 == @table.
    where(key_column => @row).
    exclude(::Sequel[value_column].hstore.key?(key)).
    update(value_column => ::Sequel[value_column].hstore.merge(key => value))
end

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


268
269
270
271
272
# File 'lib/moneta/adapters/sequel.rb', line 268

def delete(key, options = {})
  value = load(key, options)
  @table.where(key_column => @row).update(value_column => ::Sequel[value_column].hstore.delete(key))
  value
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.


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/moneta/adapters/sequel.rb', line 274

def increment(key, amount = 1, options = {})
  create_row
  pair = ::Sequel[:hstore].function(
    key,
    (::Sequel[:coalesce].function(
      ::Sequel[value_column].hstore[key].cast(Integer),
      0) + amount).cast(String))

  if row = @table.
    returning(::Sequel[value_column].hstore[key].as(:value)).
    where(key_column => @row).
    update(value_column => ::Sequel.join([value_column, pair])).
    first
  then
    row[:value].to_i
  end
end

#key?(key, options = {}) ⇒ Boolean

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:

  • (Boolean)

252
253
254
# File 'lib/moneta/adapters/sequel.rb', line 252

def key?(key, options = {})
  !!@table.where(key_column => @row).get(::Sequel[value_column].hstore.key?(key))
end

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


264
265
266
# File 'lib/moneta/adapters/sequel.rb', line 264

def load(key, options = {})
  @table.where(key_column => @row).get(::Sequel[value_column].hstore[key])
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.


256
257
258
259
260
261
262
# File 'lib/moneta/adapters/sequel.rb', line 256

def store(key, value, options = {})
  create_row
  @table.
    where(key_column => @row).
    update(value_column => ::Sequel[@table_name][value_column].hstore.merge(key => value))
  value
end