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.

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.



465
466
467
468
469
470
471
# File 'lib/moneta/adapters/sequel.rb', line 465

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.



528
529
530
531
# File 'lib/moneta/adapters/sequel.rb', line 528

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.



513
514
515
516
517
518
519
520
521
522
523
524
525
526
# File 'lib/moneta/adapters/sequel.rb', line 513

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.



496
497
498
499
500
501
502
# File 'lib/moneta/adapters/sequel.rb', line 496

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.



560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/moneta/adapters/sequel.rb', line 560

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.



504
505
506
507
508
509
510
511
# File 'lib/moneta/adapters/sequel.rb', line 504

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)


473
474
475
476
477
478
479
480
# File 'lib/moneta/adapters/sequel.rb', line 473

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.



490
491
492
493
494
# File 'lib/moneta/adapters/sequel.rb', line 490

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.



549
550
551
552
553
554
555
556
557
558
# File 'lib/moneta/adapters/sequel.rb', line 549

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.



541
542
543
544
545
546
547
# File 'lib/moneta/adapters/sequel.rb', line 541

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.



482
483
484
485
486
487
488
# File 'lib/moneta/adapters/sequel.rb', line 482

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.



533
534
535
536
537
538
539
# File 'lib/moneta/adapters/sequel.rb', line 533

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