a loader option for statements to apply a specific shard id to the primary query as well as for additional relationship and column loaders. The :class:`_horizontal.set_shard_id` option may be applied using the :meth:`_sql.Executable.options` method of any executable statement::
| 374 | |
| 375 | |
| 376 | class set_shard_id(ORMOption): |
| 377 | """a loader option for statements to apply a specific shard id to the |
| 378 | primary query as well as for additional relationship and column |
| 379 | loaders. |
| 380 | |
| 381 | The :class:`_horizontal.set_shard_id` option may be applied using |
| 382 | the :meth:`_sql.Executable.options` method of any executable statement:: |
| 383 | |
| 384 | stmt = ( |
| 385 | select(MyObject) |
| 386 | .where(MyObject.name == "some name") |
| 387 | .options(set_shard_id("shard1")) |
| 388 | ) |
| 389 | |
| 390 | Above, the statement when invoked will limit to the "shard1" shard |
| 391 | identifier for the primary query as well as for all relationship and |
| 392 | column loading strategies, including eager loaders such as |
| 393 | :func:`_orm.selectinload`, deferred column loaders like :func:`_orm.defer`, |
| 394 | and the lazy relationship loader :func:`_orm.lazyload`. |
| 395 | |
| 396 | In this way, the :class:`_horizontal.set_shard_id` option has much wider |
| 397 | scope than using the "shard_id" argument within the |
| 398 | :paramref:`_orm.Session.execute.bind_arguments` dictionary. |
| 399 | |
| 400 | |
| 401 | .. versionadded:: 2.0.0 |
| 402 | |
| 403 | """ |
| 404 | |
| 405 | __slots__ = ("shard_id", "propagate_to_loaders") |
| 406 | |
| 407 | def __init__( |
| 408 | self, shard_id: ShardIdentifier, propagate_to_loaders: bool = True |
| 409 | ): |
| 410 | """Construct a :class:`_horizontal.set_shard_id` option. |
| 411 | |
| 412 | :param shard_id: shard identifier |
| 413 | :param propagate_to_loaders: if left at its default of ``True``, the |
| 414 | shard option will take place for lazy loaders such as |
| 415 | :func:`_orm.lazyload` and :func:`_orm.defer`; if False, the option |
| 416 | will not be propagated to loaded objects. Note that :func:`_orm.defer` |
| 417 | always limits to the shard_id of the parent row in any case, so the |
| 418 | parameter only has a net effect on the behavior of the |
| 419 | :func:`_orm.lazyload` strategy. |
| 420 | |
| 421 | """ |
| 422 | self.shard_id = shard_id |
| 423 | self.propagate_to_loaders = propagate_to_loaders |
| 424 | |
| 425 | |
| 426 | def execute_and_instances( |
no outgoing calls