Skip to content

Command Services

The most of the time you will never initiate these services directly, you will use Container to register or get the instances of these services instead.

amsdal_glue.services.DefaultSchemaCommandService

Bases: SchemaCommandService

DefaultSchemaCommandService is responsible for executing schema commands.

Example

Here is an example to run a delete schema command:

from amsdal_glue import init_default_containers
from amsdal_glue import Container
from amsdal_glue import SchemaCommand, SchemaReference, Version
from amsdal_glue.services import SchemaCommandService

# Register default containers
init_default_containers()

# Get the registered DefaultSchemaCommandService
service = Container.services.get(SchemaCommandService)

# Delete `user` schema
service.execute(
    SchemaCommand(
        mutations=[
            DeleteSchema(
                schema_reference=SchemaReference(
                    name='user',
                    version=Version.LATEST,
                ),
            ),
        ],
    ),
)

execute

execute(command)

Executes the given schema command.

Parameters:

Name Type Description Default
command SchemaCommand

The schema command to be executed.

required

Returns:

Name Type Description
SchemaResult SchemaResult

The result of the schema command execution.

amsdal_glue.services.DefaultDataCommandService

Bases: DataCommandService

DefaultDataCommandService is responsible for executing data commands.

Example

Here is an example to run a create data command:

from amsdal_glue import init_default_containers
from amsdal_glue import Container
from amsdal_glue import DataCommand, Data, SchemaReference
from amsdal_glue.services import DataCommandService

# Register default containers
init_default_containers()

# Get the registered DefaultDataCommandService
service = Container.services.get(DataCommandService)

# Insert data into `customers` and `logs` schemas
service.execute(
    command=DataCommand(
        mutations=[
            InsertData(
                schema=SchemaReference(name='customers', version=Version.LATEST),
                data=[
                    Data(data={'customer_id': 1, 'name': 'John Doe', 'email': 'e1@example.com'}),
                    Data(data={'customer_id': 2, 'name': 'Jane Doe', 'email': 'e2@example.com'}),
                    Data(data={'customer_id': 3, 'name': 'Josh Doe', 'email': 'e3@example.com'}),
                    Data(data={'customer_id': 4, 'name': 'Jane Doe', 'email': 'e4@example.com'}),
                ],
            ),
            InsertData(
                schema=SchemaReference(name='logs', version=Version.LATEST),
                data=[
                    Data(data={'created_at': '2021-01-01 00:00:00', 'message': 'Lorem ipsum dolor sit amet'}),
                    Data(data={'created_at': '2021-01-02 00:00:00', 'message': 'consectetur adipiscing elit'}),
                    Data(data={'created_at': '2021-01-03 00:00:00', 'message': 'sed do eiusmod tempor'}),
                    Data(data={'created_at': '2021-01-04 00:00:00', 'message': 'ut labore et dolore magna'}),
                ],
            ),
        ],
    ),
)

execute

execute(command)

Executes the given data command.

Parameters:

Name Type Description Default
command DataCommand

The data command to be executed.

required

Returns:

Name Type Description
DataResult DataResult

The result of the data command execution.

amsdal_glue.services.DefaultTransactionCommandService

Bases: TransactionCommandService

DefaultTransactionCommandService is responsible for executing transaction commands.

Example

Here is an example to run a transaction command:

from amsdal_glue import init_default_containers
from amsdal_glue import Container
from amsdal_glue import TransactionCommand, Transaction, TransactionAction
from amsdal_glue import SchemaReference, Version
from amsdal_glue.services import TransactionCommandService

# Register default containers
init_default_containers()

# Get the registered DefaultTransactionCommandService
service = Container.services.get(TransactionCommandService)

# Begin a transaction command
service.execute(
    TransactionCommand(
        transaction_id='test_transaction',
        schema=SchemaReference(name='customers', version=Version.LATEST),
        action=TransactionAction.BEGIN,
    ),
)

execute

execute(command)

Executes the given transaction command.

Parameters:

Name Type Description Default
command TransactionCommand

The transaction command to be executed.

required

Returns:

Name Type Description
TransactionResult TransactionResult

The result of the transaction command execution.

amsdal_glue.services.DefaultLockCommandService

Bases: LockCommandService

DefaultLockCommandService is responsible for executing lock commands.

Example

Here is an example to run a lock command:

from amsdal_glue import init_default_containers
from amsdal_glue import Container
from amsdal_glue import LockCommand, LockAction, LockMode, LockParameter, LockSchemaReference
from amsdal_glue import SchemaReference, Version
from amsdal_glue.services import LockCommandService

# Register default containers
init_default_containers()

# Get the registered DefaultLockCommandService
service = Container.services.get(LockCommandService)

# Lock a resource
service.execute(
    LockCommand(
        lock_id=None,
        transaction_id=None,
        action=LockAction.ACQUIRE,
        mode=LockMode.EXCLUSIVE,
        parameter=LockParameter.SKIP_LOCKED,
        locked_objects=[LockSchemaReference(schema=SchemaReference(name='customers', version=Version.LATEST))],
    ),
)

execute

execute(command)

Executes the given lock command.

Parameters:

Name Type Description Default
command LockCommand

The lock command to be executed.

required

Returns:

Name Type Description
LockResult LockResult

The result of the lock command execution.