service
A generic service object implementation.
Service object is generic on the domain model type.
RepositoryService object is generic on the domain model type which should be a SQLAlchemy model.
RepositoryService ¶
Bases: Service[ModelT]
, Generic[ModelT]
Service object that operates on a repository object.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
**repo_kwargs |
Any
|
passed as keyword args to repo instantiation. |
{}
|
create
async
¶
Wrap repository instance creation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ModelT
|
Representation to be created. |
required |
Returns:
Type | Description |
---|---|
ModelT
|
Representation of created instance. |
delete
async
¶
Wrap repository delete operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
Any
|
Identifier of instance to be deleted. |
required |
Returns:
Type | Description |
---|---|
ModelT
|
Representation of the deleted instance. |
get
async
¶
Wrap repository scalar operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
Any
|
Identifier of instance to be retrieved. |
required |
Returns:
Type | Description |
---|---|
ModelT
|
Representation of instance with identifier |
list
async
¶
Wrap repository scalars operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*filters |
FilterTypes
|
Collection route filters. |
()
|
**kwargs |
Any
|
Keyword arguments for attribute based filtering. |
{}
|
Returns:
Type | Description |
---|---|
list[ModelT]
|
The list of instances retrieved from the repository. |
new
classmethod
async
¶
Context manager that returns instance of service object.
Handles construction of the database session.
Returns:
Type | Description |
---|---|
AsyncIterator[RepoServiceT]
|
The service object instance. |
Service ¶
Bases: Generic[T]
Generic Service object.
__init_subclass__ ¶
Map the service object to a unique identifier.
Important that the id is deterministic across running
application instances, e.g., using something like hash()
or
id()
won't work as those would be different on different
instances of the running application. So we use the full import
path to the object.
create
async
¶
Create an instance of T
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
T
|
Representation to be created. |
required |
Returns:
Type | Description |
---|---|
T
|
Representation of created instance. |
delete
async
¶
Delete T
that is identified by id_
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
Any
|
Identifier of instance to be deleted. |
required |
Returns:
Type | Description |
---|---|
T
|
Representation of the deleted instance. |
enqueue_background_task
async
¶
Enqueue an async callback for the operation and data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method_name |
str
|
Method on the service object that should be called by the async worker. |
required |
job_config |
JobConfig | None
|
Configuration object to control the job that is enqueued. |
None
|
**kwargs |
Any
|
Arguments to be passed to the method when called. Must be JSON serializable. |
{}
|
get
async
¶
Retrieve a representation of T
with that is identified by id_
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id_ |
Any
|
Identifier of instance to be retrieved. |
required |
Returns:
Type | Description |
---|---|
T
|
Representation of instance with identifier |
list
async
¶
new
classmethod
async
¶
Context manager that returns instance of service object.
Returns:
Type | Description |
---|---|
AsyncIterator[ServiceT]
|
The service object instance. |
make_service_callback
async
¶
Make an async service callback.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_ctx |
Context
|
the SAQ context |
required |
service_type_id |
str
|
Value of |
required |
service_method_name |
str
|
Method to be called on the service object. |
required |
**kwargs |
Any
|
Unpacked into the service method call as keyword arguments. |
{}
|