Module: Moneta::Adapters::Sequel::PostgresHStore Private

Defined in:
lib/moneta/adapters/sequel/postgres_hstore.rb

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(mod) ⇒ 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.



8
9
10
11
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 8

def self.extended(mod)
  mod.backend.extension :pg_hstore
  mod.backend.extension :pg_array
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.



68
69
70
71
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 68

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 53

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



36
37
38
39
40
41
42
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 36

def delete(key, options = {})
  @backend.transaction do
    value = load(key, options)
    @delete.call(row: config.hstore, 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.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 100

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

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



44
45
46
47
48
49
50
51
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 44

def increment(key, amount = 1, options = {})
  @backend.transaction do
    create_row
    if row = @increment.call(row: config.hstore, 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)


13
14
15
16
17
18
19
20
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 13

def key?(key, options = {})
  if @key
    row = @key.call(row: config.hstore, 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.



30
31
32
33
34
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 30

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



89
90
91
92
93
94
95
96
97
98
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 89

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: config.hstore, 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.



81
82
83
84
85
86
87
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 81

def slice(*keys, **options)
  if row = @slice.call(row: config.hstore, 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.



22
23
24
25
26
27
28
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 22

def store(key, value, options = {})
  @backend.transaction do
    create_row
    @store.call(row: config.hstore, 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.



73
74
75
76
77
78
79
# File 'lib/moneta/adapters/sequel/postgres_hstore.rb', line 73

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