Datastructures

class acouchbase.datastructures.CouchbaseList(key: str, collection: AsyncCollection)

CouchbaseList provides a simplified interface for storing a list within a Couchbase document.

Parameters:
  • key (str) – Document key to use for the list.

  • collection (Collection) – The Collection where the list belongs.

async append(value: str | int | float | bool | None | Mapping[str, Any] | Sequence[Any]) → None

Add an item to the end of the list.

Parameters:

value (JSONType) – The value to add.

async clear() → None

Clears the list.

async get_all() → list[Any]

Returns the entire list of items in this list.

Returns:

The entire list.

Return type:

list[Any]

async get_at(index: int) → Any

Retrieves the item at a specific index in the list.

Parameters:

index (int) – The index to retrieve.

Returns:

The value of the element at the specified index.

Return type:

Any

Raises:

InvalidArgumentException – If the index is out of range.

async index_of(value: Any) → int

Returns the index of a specific value from the list.

Parameters:

value (JSONType) – The value to search for.

Returns:

The index of the value in the list. Returns -1 if value is not found.

Return type:

int

async prepend(value: str | int | float | bool | None | Mapping[str, Any] | Sequence[Any]) → None

Add an item to the beginning of the list.

Parameters:

value (JSONType) – The value to add.

async remove_at(index: int) → None

Removes an item at a specific index from the list.

Parameters:

index (int) – The index to remove.

Raises:

InvalidArgumentException – If the index is out of range.

async set_at(index: int, value: str | int | float | bool | None | Mapping[str, Any] | Sequence[Any]) → None

Sets an item within a list at a specified index.

Parameters:
  • index (int) – The index to retrieve.

  • value (JSONType) – The value to set.

Raises:

InvalidArgumentException – If the index is out of range.

async size() → int

Returns the number of items in the list.

Returns:

The number of items in the list.

Return type:

int

class acouchbase.datastructures.CouchbaseMap(key: str, collection: AsyncCollection)

CouchbaseMap provides a simplified interface for storing a map within a Couchbase document.

Parameters:
async add(mapkey: str, value: Any) → None

Sets a specific key to the specified value in the map.

Parameters:
  • mapkey (str) – The key to set.

  • value (JSONType) – The value to set.

async clear() → None

Clears the map.

async exists(key: str) → bool

Checks whether a specific key exists in the map.

Parameters:

key (str) – The key to set.

Returns:

True if the key exists in the map, False otherwise.

Return type:

bool

async get(mapkey: str) → Any

Fetches a specific key from the map.

Parameters:

mapkey (str) – The key to fetch.

Returns:

The value of the specified key.

Return type:

Any

async get_all() → dict[str, Any]

Retrieves the entire map.

Returns:

The entire CouchbaseMap.

Return type:

dict[str, Any]

async items() → Generator[tuple[str, Any], None, None]

Provides mechanism to loop over the entire map.

Returns:

A generator expression for the map

Return type:

Generator

async keys() → list[str]

Returns a list of all the keys which exist in the map.

Returns:

A list of all the keys that exist in the map.

Return type:

list[str]

async remove(mapkey: str) → None

Removes a specific key from the map.

Parameters:

mapkey (str) – The key in the map to remove.

Raises:

InvalidArgumentException – If the key is not in the map.

async size() → int

Returns the number of items in the map.

Returns:

The number of items in the map.

Return type:

int

async values() → list[Any]

Returns a list of all the values which exist in the map.

Returns:

A list of all the values that exist in the map.

Return type:

list[Any]

class acouchbase.datastructures.CouchbaseQueue(key: str, collection: AsyncCollection)

CouchbaseQueue provides a simplified interface for storing a queue within a Couchbase document.

Parameters:
  • key (str) – Document key to use for the queue.

  • collection (Collection) – The Collection where the queue belongs.

async clear() → None

Clears the queue.

async pop(timeout: timedelta | None = None) → Any

Removes an item from the front of the queue.

Parameters:

timeout (timedelta, optional) – Amount of time allowed when attempting to remove the value. Defaults to 10 seconds.

Returns:

The value that was removed from the front of the queue.

Return type:

Any

async push(value: str | int | float | bool | None | Mapping[str, Any] | Sequence[Any]) → None

Adds a new item to the back of the queue.

Parameters:

value (JSONType) – The value to push onto the queue.

async size() → int

Returns the number of items in the queue.

Returns:

The number of items in the queue.

Return type:

int

class acouchbase.datastructures.CouchbaseSet(key: str, collection: AsyncCollection)

CouchbaseSet provides a simplified interface for storing a set within a Couchbase document.

Parameters:
async add(value: Any) → bool

Adds a value to the set, unless the set already holds it.

Parameters:

value (Any) – The value to add.

Returns:

True if the value was added, False otherwise (meaning the value already

exists in the set).

Return type:

bool

async clear() → None

Clears the set.

async contains(value: Any) → bool

Returns whether a specific value already exists in the set.

Parameters:

value (Any) – The value to check for existence.

Returns:

True if the specified value exists in the set. False otherwise.

Return type:

bool

async remove(value: Any, timeout: timedelta | None = None) → None

Removes a specific value from the set.

Parameters:
  • value (Any) – The value to remove

  • timeout (timedelta, optional) – Amount of time allowed when attempting to remove the value. Defaults to 10 seconds.

async size() → int

Returns the number of items in the set.

Returns:

The number of items in the set.

Return type:

int

async values() → list[Any]

Returns a list of all the values which exist in the set.

Returns:

The values that exist in the set.

Return type:

list[Any]