pub struct Space { /* private fields */ }
Implementations§
source§impl Space
impl Space
sourcepub fn builder(name: &str) -> Builder<'_>
pub fn builder(name: &str) -> Builder<'_>
Return a space builder.
name
- name of space to be created
sourcepub fn find(name: &str) -> Option<Self>
pub fn find(name: &str) -> Option<Self>
Find space by name.
This function performs SELECT request to _vspace
system space.
name
- space name
Returns:
None
if not foundSome(space)
otherwise
sourcepub fn find_cached(name: &str) -> Option<Self>
pub fn find_cached(name: &str) -> Option<Self>
Memorized version of Space::find
function.
The function performs SELECT request to _vspace
system space only if
it was never called for target space.
name
- space name
NOTE the cache can become invalid for a number of reasons. If an
operation with a space returned from this function results in a
TarantoolError
with code NoSuchSpace
, try calling clear_cache
before trying to find the space again.
Returns:
None
if not foundSome(space)
otherwise
sourcepub fn index(&self, name: &str) -> Option<Index>
pub fn index(&self, name: &str) -> Option<Index>
Find index by name.
This function performs SELECT request to _vindex
system space.
name
- index name
Returns:
None
if not foundSome(index)
otherwise
sourcepub fn index_cached(&self, name: &str) -> Option<Index>
pub fn index_cached(&self, name: &str) -> Option<Index>
Memorized version of Space::index
function.
This function performs SELECT request to _vindex
system space.
name
- index name
NOTE the cache can become invalid for a number of reasons. If an
operation with an index returned from this function results in a
TarantoolError
with code NoSuchSpace
or NoSuchIndexID
, try
calling clear_cache
before trying to get the index again.
Returns:
None
if not foundSome(index)
otherwise
sourcepub fn primary_key(&self) -> Index
pub fn primary_key(&self) -> Index
Returns index with id = 0
sourcepub fn insert<T>(&self, value: &T) -> Result<Tuple, Error>where
T: ToTupleBuffer,
pub fn insert<T>(&self, value: &T) -> Result<Tuple, Error>where
T: ToTupleBuffer,
Insert a tuple into a space.
value
- tuple value to insert
Returns a new tuple.
See also: box.space[space_id]:insert(tuple)
sourcepub fn replace<T>(&self, value: &T) -> Result<Tuple, Error>where
T: ToTupleBuffer,
pub fn replace<T>(&self, value: &T) -> Result<Tuple, Error>where
T: ToTupleBuffer,
Insert a tuple into a space. If a tuple with the same primary key already exists, space.replace() replaces the existing tuple with a new one. The syntax variants space.replace() and space.put() have the same effect; the latter is sometimes used to show that the effect is the converse of space.get().
value
- tuple value to replace with
Returns a new tuple.
sourcepub fn put<T>(&self, value: &T) -> Result<Tuple, Error>where
T: ToTupleBuffer,
pub fn put<T>(&self, value: &T) -> Result<Tuple, Error>where
T: ToTupleBuffer,
Insert a tuple into a space. If a tuple with the same primary key already exists, it replaces the existing tuple with a new one. Alias for space.replace()
sourcepub fn truncate(&self) -> Result<(), Error>
pub fn truncate(&self) -> Result<(), Error>
Deletes all tuples. The method is performed in background and doesn’t block consequent requests.
sourcepub fn len(&self) -> Result<usize, Error>
pub fn len(&self) -> Result<usize, Error>
Return the number of tuples in the space.
Compared with space.count(), this method works faster because space.len() does not scan the entire space to count the tuples.
pub fn is_empty(&self) -> Result<bool, Error>
sourcepub fn bsize(&self) -> Result<usize, Error>
pub fn bsize(&self) -> Result<usize, Error>
Number of bytes in the space.
This number, which is stored in Tarantool’s internal memory, represents the total number of bytes in all tuples, excluding index keys. For a measure of index size, see index.bsize().
sourcepub fn get<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer,
pub fn get<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer,
Search for a tuple in the given space.
sourcepub fn select<K>(
&self,
iterator_type: IteratorType,
key: &K
) -> Result<IndexIterator, Error>where
K: ToTupleBuffer,
pub fn select<K>(
&self,
iterator_type: IteratorType,
key: &K
) -> Result<IndexIterator, Error>where
K: ToTupleBuffer,
Search for a tuple or a set of tuples in the given space. This method doesn’t yield (for details see Сooperative multitasking).
type
- iterator typekey
- encoded key in the MsgPack Array format ([part1, part2, ...]
).
sourcepub fn count<K>(
&self,
iterator_type: IteratorType,
key: &K
) -> Result<usize, Error>where
K: ToTupleBuffer,
pub fn count<K>(
&self,
iterator_type: IteratorType,
key: &K
) -> Result<usize, Error>where
K: ToTupleBuffer,
Return the number of tuples. Compared with space.len(), this method works slower because space.count() scans the entire space to count the tuples.
type
- iterator typekey
- encoded key in the MsgPack Array format ([part1, part2, ...]
).
sourcepub fn delete<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer,
pub fn delete<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer,
Delete a tuple identified by a primary key.
key
- encoded key in the MsgPack Array format ([part1, part2, ...]
).
Returns the deleted tuple
sourcepub fn update<K, Op>(
&self,
key: &K,
ops: impl AsRef<[Op]>
) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer,
Op: ToTupleBuffer,
pub fn update<K, Op>(
&self,
key: &K,
ops: impl AsRef<[Op]>
) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer,
Op: ToTupleBuffer,
Update a tuple.
The update
function supports operations on fields — assignment, arithmetic (if the field is numeric),
cutting and pasting fragments of a field, deleting or inserting a field. Multiple operations can be combined in
a single update request, and in this case they are performed atomically and sequentially. Each operation
requires specification of a field number. When multiple operations are present, the field number for each
operation is assumed to be relative to the most recent state of the tuple, that is, as if all previous
operations in a multi-operation update have already been applied.
In other words, it is always safe to merge multiple update
invocations into a single invocation with no
change in semantics.
key
- encoded key in the MsgPack Array format ([part1, part2, ...]
).ops
- encoded operations in the MsgPack array format, e.g.[['=', field_id, value], ['!', 2, 'xxx']]
Returns a new tuple.
See also: space.upsert()
sourcepub unsafe fn update_mp<K>(
&self,
key: &K,
ops: &[Vec<u8>]
) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer,
👎Deprecated: use update_raw instead
pub unsafe fn update_mp<K>(
&self,
key: &K,
ops: &[Vec<u8>]
) -> Result<Option<Tuple>, Error>where
K: ToTupleBuffer,
Update a tuple using ops
already encoded in the message pack format.
This function is similar to update
but instead
of a generic type parameter Op
it accepts preencoded message pack
values. This is usefull when the operations have values of different
types.
Returns a new tuple.
Safety
ops
must be a slice of valid msgpack arrays.
sourcepub unsafe fn update_raw(
&self,
key: &[u8],
ops: &[u8]
) -> Result<Option<Tuple>, Error>
pub unsafe fn update_raw(
&self,
key: &[u8],
ops: &[u8]
) -> Result<Option<Tuple>, Error>
Update a tuple using already encoded arguments.
This function is similar to update
but instead
of generic type parameters T
& Op
it accepts preencoded message
pack arrays. This is usefull when the operations have values of
different types.
Safety
key
must be a valid msgpack array.
ops
must be a valid msgpack array of msgpack arrays.
sourcepub fn upsert<T, Op>(&self, value: &T, ops: impl AsRef<[Op]>) -> Result<(), Error>where
T: ToTupleBuffer,
Op: ToTupleBuffer,
pub fn upsert<T, Op>(&self, value: &T, ops: impl AsRef<[Op]>) -> Result<(), Error>where
T: ToTupleBuffer,
Op: ToTupleBuffer,
Update or insert a tuple.
If there is an existing tuple which matches the tuple key fields, then the request has the same effect as
space.update() and the {{operator, field_no, value}, ...}
parameter is used.
If there is no existing tuple which matches the tuple key fields, then the request has the same effect as
space.insert() and the {tuple}
parameter is used.
However, unlike insert
or update
, upsert
will not read a tuple and perform error checks before
returning – this is a design feature which enhances throughput but requires more cautious use.
value
- encoded tuple in the MsgPack Array format ([field1, field2, ...]
)ops
- encoded operations in the MsgPack array format, e.g.[['=', field_id, value], ['!', 2, 'xxx']]
See also: space.update()
sourcepub unsafe fn upsert_mp<K>(&self, key: &K, ops: &[Vec<u8>]) -> Result<(), Error>where
K: ToTupleBuffer,
👎Deprecated: use upsert_raw instead
pub unsafe fn upsert_mp<K>(&self, key: &K, ops: &[Vec<u8>]) -> Result<(), Error>where
K: ToTupleBuffer,
Upsert a tuple using ops
already encoded in the message pack format.
This function is similar to upsert
but instead
of a generic type parameter Op
it accepts preencoded message pack
values. This is usefull when the operations have values of different
types.
Safety
ops
must be a slice of valid msgpack arrays.
sourcepub unsafe fn upsert_raw(&self, value: &[u8], ops: &[u8]) -> Result<(), Error>
pub unsafe fn upsert_raw(&self, value: &[u8], ops: &[u8]) -> Result<(), Error>
Upsert a tuple using already encoded arguments.
This function is similar to upsert
but instead
of generic type parameters T
& Op
it accepts preencoded message
pack arrays. This is usefull when the operations have values of
different types.
Safety
value
must be a valid msgpack array.
ops
must be a valid msgpack array of msgpack arrays.