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, #fetch_values, new

Methods included from Defaults

#[], #[]=, #close, #decrement, #features, #fetch, #fetch_values, included, #supports?, #update

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options) ⇒ 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



469
470
471
472
473
474
475
# File 'lib/moneta/adapters/sequel.rb', line 469

def initialize(options)
  @row = options.delete(:hstore).to_s
  @backend.extension :pg_hstore
  ::Sequel.extension :pg_hstore_ops
  @backend.extension :pg_array
  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.



532
533
534
535
# File 'lib/moneta/adapters/sequel.rb', line 532

def clear(options = {})
  @clear.call(row: @row)
  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.



517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'lib/moneta/adapters/sequel.rb', line 517

def create(key, value, options = {})
  @backend.transaction do
    create_row
    1 ==
      if @create
        @create.call(row: @row, key: key, pair: ::Sequel.hstore(key => value))
      else
        @table.
          where(key_column => @row).
          exclude(::Sequel[value_column].hstore.key?(key)).
          update(value_column => ::Sequel[value_column].hstore.merge(key => value))
      end
  end
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.



500
501
502
503
504
505
506
# File 'lib/moneta/adapters/sequel.rb', line 500

def delete(key, options = {})
  @backend.transaction do
    value = load(key, options)
    @delete.call(row: @row, key: key)
    value
  end
end

#each_keyObject

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.



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/moneta/adapters/sequel.rb', line 564

def each_key
  return enum_for(:each_key) { @size.call(row: @row)[:size] } unless block_given?

  ds =
    if @each_key_server
      @table.server(@each_key_server)
    else
      @table
    end
  ds = ds.order(:skeys) unless @table.respond_to?(:use_cursor)
  ds.where(key_column => @row).
    select(::Sequel[value_column].hstore.skeys).
    paged_each do |row|
      yield row[:skeys]
    end
  self
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.



508
509
510
511
512
513
514
515
# File 'lib/moneta/adapters/sequel.rb', line 508

def increment(key, amount = 1, options = {})
  @backend.transaction do
    create_row
    if row = @increment.call(row: @row, key: key, amount: amount).first
      row[:value].to_i
    end
  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)


477
478
479
480
481
482
483
484
# File 'lib/moneta/adapters/sequel.rb', line 477

def key?(key, options = {})
  if @key
    row = @key.call(row: @row, key: key) || false
    row && row[:present]
  else
    @key_pl.get(key)
  end
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.



494
495
496
497
498
# File 'lib/moneta/adapters/sequel.rb', line 494

def load(key, options = {})
  if row = @load.call(row: @row, key: key)
    row[:value]
  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.



553
554
555
556
557
558
559
560
561
562
# File 'lib/moneta/adapters/sequel.rb', line 553

def merge!(pairs, options = {}, &block)
  @backend.transaction do
    create_row
    pairs = yield_merge_pairs(pairs, &block) if block_given?
    hash = Hash === pairs ? pairs : Hash[pairs.to_a]
    @store.call(row: @row, pair: ::Sequel.hstore(hash))
  end

  self
end

#slice(*keys, **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.



545
546
547
548
549
550
551
# File 'lib/moneta/adapters/sequel.rb', line 545

def slice(*keys, **options)
  if row = @slice.call(row: @row, keys: ::Sequel.pg_array(keys))
    row[:pairs].to_h
  else
    []
  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.



486
487
488
489
490
491
492
# File 'lib/moneta/adapters/sequel.rb', line 486

def store(key, value, options = {})
  @backend.transaction do
    create_row
    @store.call(row: @row, pair: ::Sequel.hstore(key => value))
  end
  value
end

#values_at(*keys, **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.



537
538
539
540
541
542
543
# File 'lib/moneta/adapters/sequel.rb', line 537

def values_at(*keys, **options)
  if row = @values_at.call(row: @row, keys: ::Sequel.pg_array(keys))
    row[:values].to_a
  else
    []
  end
end