Class: Tarantool::Model::Storage::Box
- Inherits:
-
Object
- Object
- Tarantool::Model::Storage::Box
- Defined in:
- tarantool-model/lib/tarantool/model/storage/box.rb,
tarantool-model/lib/tarantool/model/storage/box/layout.rb
Overview
Storage over a Tarantool::Client or Client::Pool. read options go to get and select, write options
to insert, update and delete, verbatim. The client converts tuples by the format of the schema each request
ran against, so alter and reconnect are picked up without a cache here. Inside Model.transaction operations,
including space_info, go through the open stream.
Instance Method Summary collapse
-
#count(_space) ⇒ Object
IPROTO has no count request, and calling box.space.X.index.Y:count needs execute grants (lua_call on 3.x, universe on 2.11) that an application user usually lacks.
- #delete(space, key) ⇒ Object
- #get(space, key) ⇒ Object
-
#initialize(caller, read: {}, write: {}) ⇒ Box
constructor
A new instance of Box.
- #insert(space, attributes) ⇒ Object
- #select(space, index:, key:, iterator:, limit:, after:) ⇒ Object
- #supports_transactions? ⇒ Boolean
- #transaction(**options, &block) ⇒ Object
- #update(space, key, operations) ⇒ Object
- #verify(space, attributes:, primary_key:) ⇒ Object
Constructor Details
#initialize(caller, read: {}, write: {}) ⇒ Box
Returns a new instance of Box.
14 15 16 17 18 19 20 21 22 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 14 def initialize(caller, read: {}, write: {}) if [read, write].any? { || .key?(:mode) } && !caller.is_a?(Tarantool::Client::Pool) raise ArgumentError, 'mode: needs a Tarantool::Client::Pool' end @caller = caller @read_options = read @write_options = write end |
Instance Method Details
#count(_space) ⇒ Object
IPROTO has no count request, and calling box.space.X.index.Y:count needs execute grants (lua_call on 3.x, universe on 2.11) that an application user usually lacks.
53 54 55 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 53 def count(_space, **) raise NotSupportedError, 'Storage::Box does not count' end |
#delete(space, key) ⇒ Object
40 41 42 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 40 def delete(space, key) row(client.delete(space, key, as: :row, **write)) end |
#get(space, key) ⇒ Object
28 29 30 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 28 def get(space, key) row(client.select(space, key, limit: 1, as: :row, **read).first) end |
#insert(space, attributes) ⇒ Object
32 33 34 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 32 def insert(space, attributes) row(unique { client.insert(space, attributes, as: :row, **write) }) end |
#select(space, index:, key:, iterator:, limit:, after:) ⇒ Object
44 45 46 47 48 49 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 44 def select(space, index:, key:, iterator:, limit:, after:) = { index: index || 0, iterator:, after:, as: :row, **read } [:limit] = limit if limit client.select(space, key, **).map { |found| row(found) } end |
#supports_transactions? ⇒ Boolean
57 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 57 def supports_transactions? = true |
#transaction(**options, &block) ⇒ Object
59 60 61 62 63 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 59 def transaction(**, &block) @caller.transaction(**) do |stream| Transactions.open(self, stream, &block) end end |
#update(space, key, operations) ⇒ Object
36 37 38 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 36 def update(space, key, operations) row(unique { client.update(space, key, operations, as: :row, **write) }) end |
#verify(space, attributes:, primary_key:) ⇒ Object
24 25 26 |
# File 'tarantool-model/lib/tarantool/model/storage/box.rb', line 24 def verify(space, attributes:, primary_key:) Layout.new(client.space_info(space, **read.slice(:mode, :timeout))).verify!(attributes:, primary_key:) end |