abc

class litestar.repository.abc.AbstractAsyncRepository[源代码]

基类:Generic[T]

Interface for persistent data interaction.

__init__(**kwargs: Any) None[源代码]

Repository constructors accept arbitrary kwargs.

abstractmethod async add(data: T) T[源代码]

Add data to the collection.

参数:

data -- Instance to be added to the collection.

返回:

The added instance.

abstractmethod async add_many(data: list[T]) list[T][源代码]

Add multiple data to the collection.

参数:

data -- Instances to be added to the collection.

返回:

The added instances.

static check_not_found(item_or_none: T | None) T[源代码]

Raise NotFoundError if item_or_none is None.

参数:

item_or_none -- Item (T) to be tested for existence.

返回:

The item, if it exists.

abstractmethod async count(*filters: FilterTypes, **kwargs: Any) int[源代码]

Get the count of records returned by a query.

参数:
  • *filters -- Types for specific filtering operations.

  • **kwargs -- Instance attribute value filters.

返回:

The count of instances

abstractmethod async delete(item_id: Any) T[源代码]

Delete instance identified by item_id.

参数:

item_id -- Identifier of instance to be deleted.

返回:

The deleted instance.

抛出:

NotFoundError -- If no instance found identified by item_id.

abstractmethod async delete_many(item_ids: list[Any]) list[T][源代码]

Delete multiple instances identified by list of IDs item_ids.

参数:

item_ids -- list of Identifiers to be deleted.

返回:

The deleted instances.

abstractmethod async exists(*filters: FilterTypes, **kwargs: Any) bool[源代码]

Return true if the object specified by kwargs exists.

参数:
  • *filters -- Types for specific filtering operations.

  • **kwargs -- Identifier of the instance to be retrieved.

返回:

True if the instance was found. False if not found.

abstractmethod filter_collection_by_kwargs(collection: CollectionT, /, **kwargs: Any) CollectionT[源代码]

Filter the collection by kwargs.

Has AND semantics where multiple kwargs name/value pairs are provided.

参数:
  • collection -- the objects to be filtered

  • **kwargs -- key/value pairs such that objects remaining in the collection after filtering have the property that their attribute named key has value equal to value.

返回:

The filtered objects

抛出:

RepositoryError -- if a named attribute doesn't exist on model_type.

abstractmethod async get(item_id: Any, **kwargs: Any) T[源代码]

Get instance identified by item_id.

参数:
  • item_id -- Identifier of the instance to be retrieved.

  • **kwargs -- Additional arguments

返回:

The retrieved instance.

抛出:

NotFoundError -- If no instance found identified by item_id.

classmethod get_id_attribute_value(item: T | type[T], id_attribute: str | None = None) Any[源代码]

Get value of attribute named as id_attribute on item.

参数:
  • item -- Anything that should have an attribute named as id_attribute value.

  • id_attribute -- Allows customization of the unique identifier to use for model fetching. Defaults to None, but can reference any surrogate or candidate key for the table.

返回:

The value of attribute on item named as id_attribute.

abstractmethod async get_one(**kwargs: Any) T[源代码]

Get an instance specified by the kwargs filters if it exists.

参数:

**kwargs -- Instance attribute value filters.

返回:

The retrieved instance.

抛出:

NotFoundError -- If no instance found identified by kwargs.

abstractmethod async get_one_or_none(**kwargs: Any) T | None[源代码]

Get an instance if it exists or None.

参数:

**kwargs -- Instance attribute value filters.

返回:

The retrieved instance or None.

abstractmethod async get_or_create(**kwargs: Any) tuple[T, bool][源代码]

Get an instance specified by the kwargs filters if it exists or create it.

参数:

**kwargs -- Instance attribute value filters.

返回:

A tuple that includes the retrieved or created instance, and a boolean on whether the record was created or not

id_attribute: Any = 'id'

Name of the primary identifying attribute on model_type.

abstractmethod async list(*filters: FilterTypes, **kwargs: Any) list[T][源代码]

Get a list of instances, optionally filtered.

参数:
  • *filters -- filters for specific filtering operations

  • **kwargs -- Instance attribute value filters.

返回:

The list of instances, after filtering applied

abstractmethod async list_and_count(*filters: FilterTypes, **kwargs: Any) tuple[list[T], int][源代码]

List records with total count.

参数:
  • *filters -- Types for specific filtering operations.

  • **kwargs -- Instance attribute value filters.

返回:

a tuple containing The list of instances, after filtering applied, and a count of records returned by query, ignoring pagination.

classmethod set_id_attribute_value(item_id: Any, item: T, id_attribute: str | None = None) T[源代码]

Return the item after the ID is set to the appropriate attribute.

参数:
  • item_id -- Value of ID to be set on instance

  • item -- Anything that should have an attribute named as id_attribute value.

  • id_attribute -- Allows customization of the unique identifier to use for model fetching. Defaults to None, but can reference any surrogate or candidate key for the table.

返回:

Item with item_id set to id_attribute

abstractmethod async update(data: T) T[源代码]

Update instance with the attribute values present on data.

参数:

data -- An instance that should have a value for id_attribute that exists in the collection.

返回:

The updated instance.

抛出:

NotFoundError -- If no instance found with same identifier as data.

abstractmethod async update_many(data: list[T]) list[T][源代码]

Update multiple instances with the attribute values present on instances in data.

参数:

data -- A list of instance that should have a value for id_attribute that exists in the collection.

返回:

a list of the updated instances.

抛出:

NotFoundError -- If no instance found with same identifier as data.

abstractmethod async upsert(data: T) T[源代码]

Update or create instance.

Updates instance with the attribute values present on data, or creates a new instance if one doesn't exist.

参数:

data -- Instance to update existing, or be created. Identifier used to determine if an existing instance exists is the value of an attribute on data named as value of id_attribute.

返回:

The updated or created instance.

抛出:

NotFoundError -- If no instance found with same identifier as data.

abstractmethod async upsert_many(data: list[T]) list[T][源代码]

Update or create multiple instances.

Update instances with the attribute values present on data, or create a new instance if one doesn't exist.

参数:

data -- Instances to update or created. Identifier used to determine if an existing instance exists is the value of an attribute on data named as value of id_attribute.

返回:

The updated or created instances.

抛出:

NotFoundError -- If no instance found with same identifier as data.

model_type: type[T]

Type of object represented by the repository.

class litestar.repository.abc.AbstractSyncRepository[源代码]

基类:Generic[T]

Interface for persistent data interaction.

__init__(**kwargs: Any) None[源代码]

Repository constructors accept arbitrary kwargs.

abstractmethod add(data: T) T[源代码]

Add data to the collection.

参数:

data -- Instance to be added to the collection.

返回:

The added instance.

abstractmethod add_many(data: list[T]) list[T][源代码]

Add multiple data to the collection.

参数:

data -- Instances to be added to the collection.

返回:

The added instances.

static check_not_found(item_or_none: T | None) T[源代码]

Raise NotFoundError if item_or_none is None.

参数:

item_or_none -- Item (T) to be tested for existence.

返回:

The item, if it exists.

abstractmethod count(*filters: FilterTypes, **kwargs: Any) int[源代码]

Get the count of records returned by a query.

参数:
  • *filters -- Types for specific filtering operations.

  • **kwargs -- Instance attribute value filters.

返回:

The count of instances

abstractmethod delete(item_id: Any) T[源代码]

Delete instance identified by item_id.

参数:

item_id -- Identifier of instance to be deleted.

返回:

The deleted instance.

抛出:

NotFoundError -- If no instance found identified by item_id.

abstractmethod delete_many(item_ids: list[Any]) list[T][源代码]

Delete multiple instances identified by list of IDs item_ids.

参数:

item_ids -- list of Identifiers to be deleted.

返回:

The deleted instances.

abstractmethod exists(*filters: FilterTypes, **kwargs: Any) bool[源代码]

Return true if the object specified by kwargs exists.

参数:
  • *filters -- Types for specific filtering operations.

  • **kwargs -- Identifier of the instance to be retrieved.

返回:

True if the instance was found. False if not found.

abstractmethod filter_collection_by_kwargs(collection: CollectionT, /, **kwargs: Any) CollectionT[源代码]

Filter the collection by kwargs.

Has AND semantics where multiple kwargs name/value pairs are provided.

参数:
  • collection -- the objects to be filtered

  • **kwargs -- key/value pairs such that objects remaining in the collection after filtering have the property that their attribute named key has value equal to value.

返回:

The filtered objects

抛出:

RepositoryError -- if a named attribute doesn't exist on model_type.

abstractmethod get(item_id: Any, **kwargs: Any) T[源代码]

Get instance identified by item_id.

参数:
  • item_id -- Identifier of the instance to be retrieved.

  • **kwargs -- Additional arguments

返回:

The retrieved instance.

抛出:

NotFoundError -- If no instance found identified by item_id.

classmethod get_id_attribute_value(item: T | type[T], id_attribute: str | None = None) Any[源代码]

Get value of attribute named as id_attribute on item.

参数:
  • item -- Anything that should have an attribute named as id_attribute value.

  • id_attribute -- Allows customization of the unique identifier to use for model fetching. Defaults to None, but can reference any surrogate or candidate key for the table.

返回:

The value of attribute on item named as id_attribute.

abstractmethod get_one(**kwargs: Any) T[源代码]

Get an instance specified by the kwargs filters if it exists.

参数:

**kwargs -- Instance attribute value filters.

返回:

The retrieved instance.

抛出:

NotFoundError -- If no instance found identified by kwargs.

abstractmethod get_one_or_none(**kwargs: Any) T | None[源代码]

Get an instance if it exists or None.

参数:

**kwargs -- Instance attribute value filters.

返回:

The retrieved instance or None.

abstractmethod get_or_create(**kwargs: Any) tuple[T, bool][源代码]

Get an instance specified by the kwargs filters if it exists or create it.

参数:

**kwargs -- Instance attribute value filters.

返回:

A tuple that includes the retrieved or created instance, and a boolean on whether the record was created or not

id_attribute: Any = 'id'

Name of the primary identifying attribute on model_type.

abstractmethod list(*filters: FilterTypes, **kwargs: Any) list[T][源代码]

Get a list of instances, optionally filtered.

参数:
  • *filters -- filters for specific filtering operations

  • **kwargs -- Instance attribute value filters.

返回:

The list of instances, after filtering applied

abstractmethod list_and_count(*filters: FilterTypes, **kwargs: Any) tuple[list[T], int][源代码]

List records with total count.

参数:
  • *filters -- Types for specific filtering operations.

  • **kwargs -- Instance attribute value filters.

返回:

a tuple containing The list of instances, after filtering applied, and a count of records returned by query, ignoring pagination.

classmethod set_id_attribute_value(item_id: Any, item: T, id_attribute: str | None = None) T[源代码]

Return the item after the ID is set to the appropriate attribute.

参数:
  • item_id -- Value of ID to be set on instance

  • item -- Anything that should have an attribute named as id_attribute value.

  • id_attribute -- Allows customization of the unique identifier to use for model fetching. Defaults to None, but can reference any surrogate or candidate key for the table.

返回:

Item with item_id set to id_attribute

abstractmethod update(data: T) T[源代码]

Update instance with the attribute values present on data.

参数:

data -- An instance that should have a value for id_attribute that exists in the collection.

返回:

The updated instance.

抛出:

NotFoundError -- If no instance found with same identifier as data.

abstractmethod update_many(data: list[T]) list[T][源代码]

Update multiple instances with the attribute values present on instances in data.

参数:

data -- A list of instance that should have a value for id_attribute that exists in the collection.

返回:

a list of the updated instances.

抛出:

NotFoundError -- If no instance found with same identifier as data.

abstractmethod upsert(data: T) T[源代码]

Update or create instance.

Updates instance with the attribute values present on data, or creates a new instance if one doesn't exist.

参数:

data -- Instance to update existing, or be created. Identifier used to determine if an existing instance exists is the value of an attribute on data named as value of id_attribute.

返回:

The updated or created instance.

抛出:

NotFoundError -- If no instance found with same identifier as data.

abstractmethod upsert_many(data: list[T]) list[T][源代码]

Update or create multiple instances.

Update instances with the attribute values present on data, or create a new instance if one doesn't exist.

参数:

data -- Instances to update or created. Identifier used to determine if an existing instance exists is the value of an attribute on data named as value of id_attribute.

返回:

The updated or created instances.

抛出:

NotFoundError -- If no instance found with same identifier as data.

model_type: type[T]

Type of object represented by the repository.