Class: Tarantool::Model::Storage::Crud

Inherits:
Object
  • Object
show all
Defined in:
tarantool-model/lib/tarantool/model/storage/crud.rb

Overview

Storage over a Tarantool::Crud::Client; read/write defaults live in that client. crud has no schema lookup, so the format is not checked and index: nil means the index named primary_index:. crud reads an unknown index name as a field name and returns nothing, so that name must be right. Single-row operations return no tuple; only select rows can be continued after.

Constant Summary collapse

OPERATORS =
{ eq: '==', ge: '>=', gt: '>', le: '<=', lt: '<' }.freeze
DUPLICATE_KEY =
/Duplicate key exists/

Instance Method Summary collapse

Constructor Details

#initialize(crud, primary_index: :primary) ⇒ Crud

tarantool-model doesn't depend on tarantool-crud, yet rescues its errors.

Raises:



15
16
17
18
19
20
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 15

def initialize(crud, primary_index: :primary)
  raise Error, "tarantool-crud is not loaded; require 'tarantool/crud'" unless defined?(Tarantool::Crud)

  @crud = crud
  @primary_index = primary_index
end

Instance Method Details

#count(space, index:, key:, iterator:) ⇒ Object



47
48
49
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 47

def count(space, index:, key:, iterator:)
  @crud.space(space).count(conditions(index, key, iterator))
end

#delete(space, key) ⇒ Object



36
37
38
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 36

def delete(space, key)
  row(@crud.space(space).delete(key))
end

#get(space, key) ⇒ Object



24
25
26
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 24

def get(space, key)
  row(@crud.space(space).get(key))
end

#insert(space, attributes) ⇒ Object



28
29
30
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 28

def insert(space, attributes)
  row(unique { @crud.space(space).insert(attributes) })
end

#select(space, index:, key:, iterator:, limit:, after:) ⇒ Object



40
41
42
43
44
45
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 40

def select(space, index:, key:, iterator:, limit:, after:)
  options = { first: limit, after: }.compact
  result = @crud.space(space).select(conditions(index, key, iterator), **options)

  result.zip(result.tuples).map { |attributes, tuple| Row.new(attributes:, tuple:) }
end

#supports_transactions? ⇒ Boolean

Returns:

  • (Boolean)


51
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 51

def supports_transactions? = false

#transaction ⇒ Object

Raises:



53
54
55
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 53

def transaction(**)
  raise NotSupportedError, 'crud has no interactive transactions'
end

#update(space, key, operations) ⇒ Object



32
33
34
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 32

def update(space, key, operations)
  row(unique { @crud.space(space).update(key, operations) })
end

#verify ⇒ Object



22
# File 'tarantool-model/lib/tarantool/model/storage/crud.rb', line 22

def verify(*, **) = nil