Class: Moneta::Adapters::Sequel::PostgresHStore Private
- Inherits:
-
Moneta::Adapters::Sequel
- Object
- Moneta::Adapters::Sequel
- Moneta::Adapters::Sequel::PostgresHStore
- 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
Instance Attribute Summary
Attributes inherited from Moneta::Adapters::Sequel
#backend, #key_column, #value_column
Instance Method Summary collapse
- #clear(options = {}) ⇒ Object private
- #create(key, value, options = {}) ⇒ Object private
- #delete(key, options = {}) ⇒ Object private
- #each_key ⇒ Object private
- #increment(key, amount = 1, options = {}) ⇒ Object private
-
#initialize(options) ⇒ PostgresHStore
constructor
private
A new instance of PostgresHStore.
- #key?(key, options = {}) ⇒ Boolean private
- #load(key, options = {}) ⇒ Object private
- #merge!(pairs, options = {}, &block) ⇒ Object private
- #slice(*keys, **options) ⇒ Object private
- #store(key, value, options = {}) ⇒ Object private
- #values_at(*keys, **options) ⇒ Object private
Methods inherited from Moneta::Adapters::Sequel
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() @row = .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( = {}) @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, = {}) @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, = {}) @backend.transaction do value = load(key, ) @delete.call(row: @row, key: key) value end end |
#each_key ⇒ 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.
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, = {}) @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.
477 478 479 480 481 482 483 484 |
# File 'lib/moneta/adapters/sequel.rb', line 477 def key?(key, = {}) 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, = {}) 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, = {}, &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, **) 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, = {}) @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, **) if row = @values_at.call(row: @row, keys: ::Sequel.pg_array(keys)) row[:values].to_a else [] end end |