Skip to main content

Processing Database Actions

Processing database actions is done using db.execute(data) of the ductape.processor interface.

It executes a database action processor within the Ductape system, handling a database action request based on the provided environment, product tag, and other parameters.

await ductape.processor.db.execute(data: IDBActionProcessorInput)

This processes a defined database action in the specified environment and application context, passing along request input, metadata, and optionally session tracking.

Parameters

IDBActionProcessorInput

FieldTypeRequiredDescription
envstringYesEnvironment slug (e.g., "dev", "prd").
product_tagstringYesProduct tag associated with this database action.
eventstringYesEvent tag identifying the database action to be processed.
cachestringNoCache tag (if using request caching).
inputIDbActionRequestYesRequest input including data and optional filter.
sessionISessionNoOptional session tracking object.
retriesnumberNoNumber of retry attempts if execution fails.

IDbActionRequest Schema

interface IDbActionRequest {
data: Record<string, unknown>;
filter?: Record<string, unknown>;
}
FieldTypeRequiredDescription
dataRecord<string, unknown>YesPayload used in the action (e.g. create/update).
filterRecord<string, unknown>NoCriteria for selecting records (for update/delete). If not used, pass {}.

Note: If any of the above fields are undefined or empty, pass them as {}.

ISession Schema

The session field enables optional session tracking for any database action run.

interface ISession {
tag: string; // session tag
token: string; // session token (e.g. signed JWT)
}
FieldTypeRequiredDescription
tagstringYesSession tag identifying the session.
tokenstringYesEncoded token used to validate and track the session.

Returns

A Promise<unknown> — resolves with the database action's output. The shape of the response depends on the implementation of the triggered database action.

Example

const data: IDBActionProcessorInput = {
env: 'dev',
product_tag: 'my-product',
event: 'postgres-db-tag:update_user',
input: {
data: { name: 'John Doe', email: 'john@example.com' },
filter: { userId: '123' }
},
session: {
tag: 'session-123',
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
},
retries: 2
};

const res = await ductape.processor.db.execute(data);

See Also