Skip to content

API Reference parrot_formdesigner.services.sinks.asyncdb_store

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.sinks.asyncdb_store

View source

AsyncDBSink — Mongo / Arango (nested) and BigQuery (tabular) via asyncdb.

Reaches every other store the workspace already talks to through the existing asyncdb>=2.0 direct dependency (packages/parrot-formdesigner/pyproject.toml:36) — no new dependency.

The mapping mode is driver-dependent (spec section 8, resolved): document drivers (mongo, arango) store data NESTED via :func:~parrot_formdesigner.services.sinks.mapper.nest_submission; the tabular driver (bigquery) flattens via :func:~parrot_formdesigner.services.sinks.mapper.flatten_submission.

Verified against the installed asyncdb package (2026-08-24):

  • asyncdb.AsyncDB(driver=..., dsn=..., **kwargs) — factory __new__ that dynamically loads asyncdb.drivers.<driver> and returns a concrete driver instance (asyncdb/connections.py:31-44).
  • mongo.insert(collection_name, data, **kwargs) (asyncdb/drivers/mongo.py:1017), mongo.list_collections(...) (:997), mongo.create_collection(database, collection, ...) (:921), mongo.fetch_one(collection_name, query) (:602).
  • arangodb.insert_document(collection, document, return_new=True) (asyncdb/drivers/arangodb.py:608), arangodb.collection_exists(name) -> bool (:275), arangodb.create_collection(name, edge=False, **kwargs) (:233), arangodb.query(sentence, bind_vars=None, **kwargs) (:341).
  • bigquery.write(data, table_id=None, dataset_id=None, ...) (asyncdb/drivers/bigquery.py:297), bigquery.create_table(dataset_id, table_id, schema) (:145), bigquery.query(sentence, ...) (:225).
  • Every concrete driver's connection() is awaitable (asyncdb/interfaces/abstract.py:37) and close() is awaitable (:46).

AsyncDBTarget.collection is validated by validate_identifier() at construction (TASK-2417) and so cannot contain a . — the "<dataset_id>.<table_id>" convention floated in the spec's docstring sketch is therefore not representable as a single field. For the bigquery driver this sink instead uses the tenant as the dataset id (dataset_id = tenant, mirroring how tenant already scopes the Postgres schema elsewhere in this package) and collection as the table id.

Alias AbstractSubmissionSink

Re-exported from parrot_formdesigner.services.sinks.base.AbstractSubmissionSink.

Class AsyncDBSink

Any other asyncdb-backed store (Mongo / Arango / BigQuery).

Parameter Type Default Description
target AsyncDBTarget The validated :class:AsyncDBTarget this sink writes to.
alias_registry SinkAliasRegistry Resolves target.connection to a DSN.
tenant str Tenant scope used to resolve the connection alias.
driver Any | None None An existing asyncdb driver instance. When provided, this sink does NOT own it and will not close it. Primarily for tests (a fake driver) or externally managed connections.
form FormSchema | None None Optional cached form, used by :meth:write to compute the payload when the caller passes payload=None. Also set (overwritten) by every :meth:ensure_target call.

Attributes:

Attribute Type Description
capabilities frozenset[SinkCapability] Document drivers: WRITE/READ/LIST/PROVISION. The tabular driver (bigquery) additionally declares EXTEND — BigQuery genuinely supports additive schema change (ALTER TABLE ... ADD COLUMN-equivalent via load jobs).
family str "document" for mongo/arango, "tabular" for bigquery.

Method AsyncDBSink.close

Close the driver connection if this sink owns it. Idempotent.

close() -> None

Method AsyncDBSink.ensure_target

Create the collection/table if absent. Additive only.

ensure_target(form: FormSchema) -> None

Parameter Type Default Description
form FormSchema The form whose destination must exist. Cached on this sink so :meth:write can compute a payload when called with payload=None.

Raises:

  • SinkUnavailableError — If provisioning fails.

Method AsyncDBSink.write

Persist one submission, nested (document) or flattened (tabular).

write(submission: FormSubmission, payload: Any) -> str

Parameter Type Default Description
submission FormSubmission The submission record being persisted.
payload Any A pre-computed payload, or None to have this sink compute it itself (via :attr:_form, set by the most recent :meth:ensure_target call) using :func:nest_submission or :func:flatten_submission depending on the configured driver.

Returns: str — The persisted submission_id.

Raises:

  • SinkUnavailableError — If the driver connection or write fails.

Method AsyncDBSink.read

Fetch a single submission by submission_id.

read(submission_id: str) -> FormSubmission | None

Parameter Type Default Description
submission_id str

Returns: FormSubmission | None

Method AsyncDBSink.list_revisions

Return the full revision chain for a submission, oldest first.

list_revisions(root_submission_id: str) -> list[FormSubmission]

Parameter Type Default Description
root_submission_id str

Returns: list[FormSubmission]

Alias AsyncDBTarget

Re-exported from parrot_formdesigner.core.persistence.AsyncDBTarget.

Attribute DOCUMENT_DRIVERS

Alias FormSchema

Re-exported from parrot_formdesigner.core.schema.FormSchema.

Alias FormSubmission

Re-exported from parrot_formdesigner.services.submissions.FormSubmission.

Alias SinkAliasRegistry

Re-exported from parrot_formdesigner.services.sink_aliases.SinkAliasRegistry.

Alias SinkCapability

Re-exported from parrot_formdesigner.core.persistence.SinkCapability.

Alias SinkUnavailableError

Re-exported from parrot_formdesigner.services.sinks.base.SinkUnavailableError.

Attribute TABULAR_DRIVERS

Alias column_names_for

Re-exported from parrot_formdesigner.services.sinks.mapper.column_names_for.

Alias flatten_submission

Re-exported from parrot_formdesigner.services.sinks.mapper.flatten_submission.

Alias nest_submission

Re-exported from parrot_formdesigner.services.sinks.mapper.nest_submission.

Alias validate_identifier

Re-exported from parrot_formdesigner.services._identifiers.validate_identifier.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally