pub struct Space { /* private fields */ }
Implementations§
Source§impl Space
impl Space
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 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 primary_key(&self) -> Index
pub fn primary_key(&self) -> Index
Returns index with id = 0
Sourcepub fn insert<T>(&mut self, value: &T) -> Result<Option<Tuple>, Error>where
T: AsTuple,
pub fn insert<T>(&mut self, value: &T) -> Result<Option<Tuple>, Error>where
T: AsTuple,
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>(&mut self, value: &T) -> Result<Option<Tuple>, Error>where
T: AsTuple,
pub fn replace<T>(&mut self, value: &T) -> Result<Option<Tuple>, Error>where
T: AsTuple,
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>(&mut self, value: &T) -> Result<Option<Tuple>, Error>where
T: AsTuple,
pub fn put<T>(&mut self, value: &T) -> Result<Option<Tuple>, Error>where
T: AsTuple,
Insert a tuple into a space. If a tuple with the same primary key already exists, replaces the existing tuple with a new one. Alias for space.replace()
Sourcepub fn truncate(&mut self) -> Result<(), Error>
pub fn truncate(&mut 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.
If compared with space.count(), this method works faster because space.len() does not scan the entire space to count the tuples.
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, not including index keys. For a measure of index size, see index.bsize().
Sourcepub fn get<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: AsTuple,
pub fn get<K>(&self, key: &K) -> Result<Option<Tuple>, Error>where
K: AsTuple,
Search for a tuple in the given space.
Sourcepub fn select<K>(
&self,
iterator_type: IteratorType,
key: &K,
) -> Result<IndexIterator, Error>where
K: AsTuple,
pub fn select<K>(
&self,
iterator_type: IteratorType,
key: &K,
) -> Result<IndexIterator, Error>where
K: AsTuple,
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 MsgPack Array format ([part1, part2, ...]
).
Sourcepub fn count<K>(
&self,
iterator_type: IteratorType,
key: &K,
) -> Result<usize, Error>where
K: AsTuple,
pub fn count<K>(
&self,
iterator_type: IteratorType,
key: &K,
) -> Result<usize, Error>where
K: AsTuple,
Return the number of tuples. If 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 MsgPack Array format ([part1, part2, ...]
).
Sourcepub fn delete<K>(&mut self, key: &K) -> Result<Option<Tuple>, Error>where
K: AsTuple,
pub fn delete<K>(&mut self, key: &K) -> Result<Option<Tuple>, Error>where
K: AsTuple,
Delete a tuple identified by a primary key.
key
- encoded key in MsgPack Array format ([part1, part2, ...]
).
Returns the deleted tuple
Sourcepub fn update<K, Op>(
&mut self,
key: &K,
ops: &Vec<Op>,
) -> Result<Option<Tuple>, Error>
pub fn update<K, Op>( &mut self, key: &K, ops: &Vec<Op>, ) -> Result<Option<Tuple>, Error>
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 MsgPack Array format ([part1, part2, ...]
).ops
- encoded operations in MsgPack array format, e.g.[['=', field_id, value], ['!', 2, 'xxx']]
Returns a new tuple.
See also: space.upsert()
Sourcepub fn upsert<T, Op>(
&mut self,
value: &T,
ops: &Vec<Op>,
) -> Result<Option<Tuple>, Error>
pub fn upsert<T, Op>( &mut self, value: &T, ops: &Vec<Op>, ) -> Result<Option<Tuple>, Error>
Update or insert a tuple.
If there is an existing tuple which matches the key fields of tuple, 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 key fields of tuple, 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 caution on the part of the
user.
value
- encoded tuple in MsgPack Array format ([field1, field2, ...]
)ops
- encoded operations in MsgPack array format, e.g.[['=', field_id, value], ['!', 2, 'xxx']]
Returns a new tuple.
See also: space.update()