Skip to content

Latest commit

 

History

History
81 lines (64 loc) · 3.31 KB

File metadata and controls

81 lines (64 loc) · 3.31 KB

title: sqlalchemy.orm Query Example Code category: page slug: sqlalchemy-orm-query-examples sortorder: 500031057 toc: False sidebartitle: sqlalchemy.orm Query meta: Example code for understanding how to use the Query class from the sqlalchemy.orm module of the SQLAlchemy project.

Query is a class within the sqlalchemy.orm module of the SQLAlchemy project.

ColumnProperty, CompositeProperty, Load, Mapper, RelationshipProperty, Session, SynonymProperty, aliased, attributes, backref, class_mapper, column_property, composite, interfaces, mapper, mapperlib, object_mapper, object_session, query, relationship, session, sessionmaker, and strategies are several other callables with code examples from the same sqlalchemy.orm package.

Example 1 from SQLAlchemy Mixins

SQLAlchemy Mixins (PyPI package information) is a collection of mixins useful for extending SQLAlchemy and simplifying your database-interacting code for some common use cases. SQLAlchemy Mixins is open sourced under the MIT license.

SQLAlchemy Mixins / sqlalchemy_mixins / session.py

# session.py
~~from sqlalchemy.orm import Session, scoped_session, Query
from .utils import classproperty


class NoSessionError(RuntimeError):
    pass


class SessionMixin:
    _session = None

    @classmethod
    def set_session(cls, session):
        cls._session = session

    @classproperty
    def session(cls):
        if cls._session is not None:
            return cls._session
        else:
            raise NoSessionError('Cant get session.'
                                 'Please, call SaActiveRecord.set_session()')

    @classproperty
    def query(cls):


## ... source file continues with no further Query examples...