strategies
is a callable within the sqlalchemy.orm
module of the SQLAlchemy project.
ColumnProperty,
CompositeProperty,
Load,
Mapper,
Query,
RelationshipProperty,
Session,
SynonymProperty,
aliased,
attributes,
backref,
class_mapper,
column_property,
composite,
interfaces,
mapper,
mapperlib,
object_mapper,
object_session,
query,
relationship,
session,
and sessionmaker
are several other callables with code examples from the same sqlalchemy.orm
package.
graphene-sqlalchemy (project documentation and PyPI package information) is a SQLAlchemy integration for Graphene, which makes it easier to build GraphQL-based APIs into Python web applications. The package allows you to subclass SQLAlchemy classes and build queries around them with custom code to match the backend queries with the GraphQL-based request queries. The project is provided as open source under the MIT license.
graphene-sqlalchemy / graphene_sqlalchemy / batching.py
# batching.py
import sqlalchemy
from promise import dataloader, promise
from sqlalchemy.orm import Session, strategies
from sqlalchemy.orm.query import QueryContext
def get_batch_resolver(relationship_prop):
selectin_loader = strategies.SelectInLoader(relationship_prop, (('lazy', 'selectin'),))
class RelationshipLoader(dataloader.DataLoader):
cache = False
def batch_load_fn(self, parents): # pylint: disable=method-hidden
child_mapper = relationship_prop.mapper
parent_mapper = relationship_prop.parent
session = Session.object_session(parents[0])
for parent in parents:
assert session is Session.object_session(parent)
assert parent not in session.dirty
states = [(sqlalchemy.inspect(parent), True) for parent in parents]
query_context = QueryContext(session.query(parent_mapper.entity))
selectin_loader._load_for_path(
query_context,
parent_mapper._path_registry,
states,
None,
child_mapper,
)
## ... source file continues with no further strategies examples...