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.
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.
465 466 467 468 469 470 471 |
# File 'lib/moneta/adapters/sequel.rb', line 465 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.
528 529 530 531 |
# File 'lib/moneta/adapters/sequel.rb', line 528 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.
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, = {}) @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, = {}) @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.
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, = {}) @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.
473 474 475 476 477 478 479 480 |
# File 'lib/moneta/adapters/sequel.rb', line 473 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.
490 491 492 493 494 |
# File 'lib/moneta/adapters/sequel.rb', line 490 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.
549 550 551 552 553 554 555 556 557 558 |
# File 'lib/moneta/adapters/sequel.rb', line 549 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.
541 542 543 544 545 546 547 |
# File 'lib/moneta/adapters/sequel.rb', line 541 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.
482 483 484 485 486 487 488 |
# File 'lib/moneta/adapters/sequel.rb', line 482 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.
533 534 535 536 537 538 539 |
# File 'lib/moneta/adapters/sequel.rb', line 533 def values_at(*keys, **) if row = @values_at.call(row: @row, keys: ::Sequel.pg_array(keys)) row[:values].to_a else [] end end |