Module spin_sdk.wit.imports.key_value

Expand source code
from typing import TypeVar, Generic, Union, Optional, Union, Protocol, Tuple, List, Any, Self
from enum import Flag, Enum, auto
from dataclasses import dataclass
from abc import abstractmethod
import weakref

from ..types import Result, Ok, Err, Some



@dataclass
class ErrorStoreTableFull:
    pass


@dataclass
class ErrorNoSuchStore:
    pass


@dataclass
class ErrorAccessDenied:
    pass


@dataclass
class ErrorOther:
    value: str


Error = Union[ErrorStoreTableFull, ErrorNoSuchStore, ErrorAccessDenied, ErrorOther]
"""
The set of errors which may be raised by functions in this interface
"""


class Store:
    """
    An open key-value store
    """
    
    @classmethod
    def open(cls, label: str) -> Self:
        """
        Open the store with the specified label.
        
        `label` must refer to a store allowed in the spin.toml manifest.
        
        `error::no-such-store` will be raised if the `label` is not recognized.
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def get(self, key: str) -> Optional[bytes]:
        """
        Get the value associated with the specified `key`
        
        Returns `ok(none)` if the key does not exist.
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def set(self, key: str, value: bytes) -> None:
        """
        Set the `value` associated with the specified `key` overwriting any existing value.
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def delete(self, key: str) -> None:
        """
        Delete the tuple with the specified `key`
        
        No error is raised if a tuple did not previously exist for `key`.
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def exists(self, key: str) -> int:
        """
        Return whether a tuple exists for the specified `key`
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def get_keys(self) -> List[str]:
        """
        Return a list of all the keys
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def __enter__(self):
        """Returns self"""
        return self
                                                                    
    def __exit__(self, *args):
        """
        Release this resource.
        """
        raise NotImplementedError

Global variables

var Error

The set of errors which may be raised by functions in this interface

Classes

class ErrorAccessDenied

ErrorAccessDenied()

Expand source code
@dataclass
class ErrorAccessDenied:
    pass
class ErrorNoSuchStore

ErrorNoSuchStore()

Expand source code
@dataclass
class ErrorNoSuchStore:
    pass
class ErrorOther (value: str)

ErrorOther(value: str)

Expand source code
@dataclass
class ErrorOther:
    value: str

Class variables

var value : str
class ErrorStoreTableFull

ErrorStoreTableFull()

Expand source code
@dataclass
class ErrorStoreTableFull:
    pass
class Store

An open key-value store

Expand source code
class Store:
    """
    An open key-value store
    """
    
    @classmethod
    def open(cls, label: str) -> Self:
        """
        Open the store with the specified label.
        
        `label` must refer to a store allowed in the spin.toml manifest.
        
        `error::no-such-store` will be raised if the `label` is not recognized.
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def get(self, key: str) -> Optional[bytes]:
        """
        Get the value associated with the specified `key`
        
        Returns `ok(none)` if the key does not exist.
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def set(self, key: str, value: bytes) -> None:
        """
        Set the `value` associated with the specified `key` overwriting any existing value.
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def delete(self, key: str) -> None:
        """
        Delete the tuple with the specified `key`
        
        No error is raised if a tuple did not previously exist for `key`.
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def exists(self, key: str) -> int:
        """
        Return whether a tuple exists for the specified `key`
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def get_keys(self) -> List[str]:
        """
        Return a list of all the keys
        
        Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
        """
        raise NotImplementedError

    def __enter__(self):
        """Returns self"""
        return self
                                                                    
    def __exit__(self, *args):
        """
        Release this resource.
        """
        raise NotImplementedError

Static methods

def open(label: str) ‑> Self

Open the store with the specified label.

label must refer to a store allowed in the spin.toml manifest.

error::no-such-store will be raised if the label is not recognized.

Raises: Err(Error)

Expand source code
@classmethod
def open(cls, label: str) -> Self:
    """
    Open the store with the specified label.
    
    `label` must refer to a store allowed in the spin.toml manifest.
    
    `error::no-such-store` will be raised if the `label` is not recognized.
    
    Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
    """
    raise NotImplementedError

Methods

def delete(self, key: str) ‑> None

Delete the tuple with the specified key

No error is raised if a tuple did not previously exist for key.

Raises: Err(Error)

Expand source code
def delete(self, key: str) -> None:
    """
    Delete the tuple with the specified `key`
    
    No error is raised if a tuple did not previously exist for `key`.
    
    Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
    """
    raise NotImplementedError
def exists(self, key: str) ‑> int

Return whether a tuple exists for the specified key

Raises: Err(Error)

Expand source code
def exists(self, key: str) -> int:
    """
    Return whether a tuple exists for the specified `key`
    
    Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
    """
    raise NotImplementedError
def get(self, key: str) ‑> Optional[bytes]

Get the value associated with the specified key

Returns ok(none) if the key does not exist.

Raises: Err(Error)

Expand source code
def get(self, key: str) -> Optional[bytes]:
    """
    Get the value associated with the specified `key`
    
    Returns `ok(none)` if the key does not exist.
    
    Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
    """
    raise NotImplementedError
def get_keys(self) ‑> List[str]

Return a list of all the keys

Raises: Err(Error)

Expand source code
def get_keys(self) -> List[str]:
    """
    Return a list of all the keys
    
    Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
    """
    raise NotImplementedError
def set(self, key: str, value: bytes) ‑> None

Set the value associated with the specified key overwriting any existing value.

Raises: Err(Error)

Expand source code
def set(self, key: str, value: bytes) -> None:
    """
    Set the `value` associated with the specified `key` overwriting any existing value.
    
    Raises: `spin_sdk.wit.types.Err(spin_sdk.wit.imports.key_value.Error)`
    """
    raise NotImplementedError