Skip to content

dorm.contrib.bulk_copy

PostgreSQL COPY FROM / COPY TO helpers.

See Bulk COPY for recipes.

API

dorm.contrib.bulk_copy.bulk_copy_from(model: Any, objs: Iterable[Any], *, columns: list[str] | None = None, using: str | None = None, binary: bool = False) -> int

Stream objs into model's table via PostgreSQL COPY FROM STDIN.

Each item in objs may be a model instance, a dict keyed by field attname / column name, or a pre-prepared tuple aligned with columns. Returns the number of rows written.

dorm.contrib.bulk_copy.abulk_copy_from(model: Any, objs: Any, *, columns: list[str] | None = None, using: str | None = None, binary: bool = False) -> int async

Async counterpart of :func:bulk_copy_from. Accepts both sync and async iterables of model instances / dicts / tuples.

dorm.contrib.bulk_copy.copy_to(sql: str, params: list[Any] | None = None, *, using: str = 'default', binary: bool = False)

Yield rows from COPY (<sql>) TO STDOUT. sql is a plain SELECT — the helper wraps it. Useful for full-table exports.

dorm.contrib.bulk_copy.acopy_to(sql: str, params: list[Any] | None = None, *, using: str = 'default', binary: bool = False) async

Async generator counterpart of :func:copy_to.