Query class used with :class:`.ShardedSession`. .. legacy:: The :class:`.ShardedQuery` is a subclass of the legacy :class:`.Query` class. The :class:`.ShardedSession` now supports 2.0 style execution via the :meth:`.ShardedSession.execute` method.
Method | __init__ |
Construct a :class:`_query.Query` directly. |
Method | set |
Return a new query, limited to a single shard ID. |
Instance Variable | execute |
Undocumented |
Instance Variable | identity |
Undocumented |
Instance Variable | _shard |
Undocumented |
Inherited from Query
:
Method | __clause |
Undocumented |
Method | __getitem__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | add |
Add a column expression to the list of result columns to be returned. |
Method | add |
Add one or more column expressions to the list of result columns to be returned. |
Method | add |
add a mapped entity to the list of result columns to be returned. |
Method | all |
Return the results represented by this :class:`_query.Query` as a list. |
Method | as |
Return the full SELECT statement represented by this :class:`_query.Query`, converted to a scalar subquery. |
Method | autoflush |
Return a Query with a specific 'autoflush' setting. |
Method | correlate |
Return a :class:`.Query` construct which will correlate the given FROM clauses to that of an enclosing :class:`.Query` or :func:`~.expression.select`. |
Method | count |
Return a count of rows this the SQL formed by this :class:`Query` would return. |
Method | cte |
Return the full SELECT statement represented by this :class:`_query.Query` represented as a common table expression (CTE). |
Method | delete |
Perform a DELETE with an arbitrary WHERE clause. |
Method | distinct |
Apply a ``DISTINCT`` to the query and return the newly resulting ``Query``. |
Method | enable |
Control whether assertions are generated. |
Method | enable |
Control whether or not eager joins and subqueries are rendered. |
Method | except_ |
Produce an EXCEPT of this Query against one or more queries. |
Method | except |
Produce an EXCEPT ALL of this Query against one or more queries. |
Method | execution |
Set non-SQL options which take effect during execution. |
Method | exists |
A convenience method that turns a query into an EXISTS subquery of the form EXISTS (SELECT 1 FROM ... WHERE ...). |
Method | filter |
Apply the given filtering criterion to a copy of this :class:`_query.Query`, using SQL expressions. |
Method | filter |
Apply the given filtering criterion to a copy of this :class:`_query.Query`, using keyword expressions. |
Method | first |
Return the first result of this ``Query`` or None if the result doesn't contain any row. |
Method | from |
Execute the given SELECT statement and return results. |
Method | get |
Return an instance based on the given primary key identifier, or ``None`` if not found. |
Method | get |
Get the non-SQL options which will take effect during execution. |
Method | group |
Apply one or more GROUP BY criterion to the query and return the newly resulting :class:`_query.Query`. |
Method | having |
Apply a HAVING criterion to the query and return the newly resulting :class:`_query.Query`. |
Method | instances |
Return an ORM result given a :class:`_engine.CursorResult` and :class:`.QueryContext`. |
Method | intersect |
Produce an INTERSECT of this Query against one or more queries. |
Method | intersect |
Produce an INTERSECT ALL of this Query against one or more queries. |
Method | join |
Create a SQL JOIN against this :class:`_query.Query` object's criterion and apply generatively, returning the newly resulting :class:`_query.Query`. |
Method | label |
Return the full SELECT statement represented by this :class:`_query.Query`, converted to a scalar subquery with a label of the given name. |
Method | limit |
Apply a ``LIMIT`` to the query and return the newly resulting ``Query``. |
Method | merge |
Merge a result into this :class:`_query.Query` object's Session. |
Method | offset |
Apply an ``OFFSET`` to the query and return the newly resulting ``Query``. |
Method | one |
Return exactly one result or raise an exception. |
Method | one |
Return at most one result or raise an exception. |
Method | only |
When set to True, the query results will always be a :class:`.Row` object. |
Method | options |
Return a new :class:`_query.Query` object, applying the given list of mapper options. |
Method | order |
Apply one or more ORDER BY criteria to the query and return the newly resulting :class:`_query.Query`. |
Method | outerjoin |
Create a left outer join against this ``Query`` object's criterion and apply generatively, returning the newly resulting ``Query``. |
Method | params |
Add values for bind parameters which may have been specified in filter(). |
Method | populate |
Return a :class:`_query.Query` that will expire and refresh all instances as they are loaded, or reused from the current :class:`.Session`. |
Method | reset |
Return a new :class:`.Query`, where the "join point" has been reset back to the base FROM entities of the query. |
Method | scalar |
Return the first element of the first result or None if no rows present. If multiple rows are returned, raises MultipleResultsFound. |
Method | scalar |
Return the full SELECT statement represented by this :class:`_query.Query`, converted to a scalar subquery. |
Method | select |
Set the FROM clause of this :class:`.Query` explicitly. |
Method | set |
Apply column labels to the return value of Query.statement. |
Method | slice |
Computes the "slice" of the :class:`_query.Query` represented by the given indices and returns the resulting :class:`_query.Query`. |
Method | subquery |
Return the full SELECT statement represented by this :class:`_query.Query`, embedded within an :class:`_expression.Alias`. |
Method | tuples |
return a tuple-typed form of this :class:`.Query`. |
Method | union |
Produce a UNION of this Query against one or more queries. |
Method | union |
Produce a UNION ALL of this Query against one or more queries. |
Method | update |
Perform an UPDATE with an arbitrary WHERE clause. |
Method | value |
Return a scalar result corresponding to the given column expression. |
Method | values |
Return an iterator yielding result tuples corresponding to the given list of columns |
Method | where |
A synonym for :meth:`.Query.filter`. |
Method | with |
Return a new :class:`_query.Query` replacing the SELECT list with the given entities. |
Method | with |
return a new :class:`_query.Query` with the specified options for the ``FOR UPDATE`` clause. |
Method | with |
Undocumented |
Method | with |
Add filtering criterion that relates the given instance to a child object or collection, using its attribute state as well as an established :func:`_orm.relationship()` configuration. |
Method | with |
Return a :class:`_query.Query` that will use the given :class:`.Session`. |
Method | with |
Return a new :class:`_query.Query` object transformed by the given function. |
Method | yield |
Yield only ``count`` rows at a time. |
Class Variable | dispatch |
Undocumented |
Class Variable | load |
Undocumented |
Instance Variable | session |
Undocumented |
Property | column |
Return metadata about the columns which would be returned by this :class:`_query.Query`. |
Property | get |
Retrieve the current label style. |
Property | is |
Indicates if this :class:`_query.Query` returns tuples or single entities. |
Property | lazy |
An :class:`.InstanceState` that is using this :class:`_query.Query` for a lazy load operation. |
Property | selectable |
Return the :class:`_expression.Select` object emitted by this :class:`_query.Query`. |
Property | statement |
The full SELECT statement represented by this Query. |
Property | whereclause |
A readonly attribute which returns the current WHERE criterion for this Query. |
Method | _clone |
clone this element |
Method | _compile |
Undocumented |
Method | _compile |
Create an out-of-compiler ORMCompileState object. |
Method | _entity |
Undocumented |
Method | _filter |
for the filter_by() method, return the target entity for which we will attempt to derive an expression from based on string name. |
Method | _final |
Return the 'final' SELECT statement for this :class:`.Query`. |
Method | _from |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
used by legacy BakedQuery |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _get |
Undocumented |
Method | _iter |
Undocumented |
Method | _legacy |
Undocumented |
Method | _no |
Undocumented |
Method | _no |
Undocumented |
Method | _no |
Undocumented |
Method | _no |
Undocumented |
Method | _no |
Undocumented |
Method | _only |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _set |
Undocumented |
Method | _statement |
Undocumented |
Method | _with |
Undocumented |
Method | _with |
indicate that this query applies to objects loaded within a certain path. |
Method | _with |
Set the 'invoke all eagers' flag which causes joined- and subquery loaders to traverse into already-loaded related objects and collections. |
Class Variable | _having |
Undocumented |
Class Variable | _memoized |
Undocumented |
Class Variable | _with |
Undocumented |
Instance Variable | _auto |
Undocumented |
Instance Variable | _correlate |
Undocumented |
Instance Variable | _distinct |
Undocumented |
Instance Variable | _distinct |
Undocumented |
Instance Variable | _enable |
Undocumented |
Instance Variable | _execution |
Undocumented |
Instance Variable | _for |
Undocumented |
Instance Variable | _from |
Undocumented |
Instance Variable | _group |
Undocumented |
Instance Variable | _label |
Undocumented |
Instance Variable | _last |
Undocumented |
Instance Variable | _limit |
Undocumented |
Instance Variable | _offset |
Undocumented |
Instance Variable | _order |
Undocumented |
Instance Variable | _params |
Undocumented |
Instance Variable | _propagate |
Undocumented |
Instance Variable | _raw |
Undocumented |
Instance Variable | _setup |
Undocumented |
Instance Variable | _statement |
Undocumented |
Instance Variable | _where |
Undocumented |
Property | _current |
Undocumented |
Property | _has |
Undocumented |
Inherited from _SelectFromElements
(via Query
):
Class Variable | __slots__ |
Undocumented |
Method | _iterate |
Undocumented |
Inherited from SupportsCloneAnnotations
(via Query
, _SelectFromElements
):
Method | _annotate |
return a copy of this ClauseElement with annotations updated by the given dictionary. |
Method | _deannotate |
return a copy of this :class:`_expression.ClauseElement` with annotations removed. |
Method | _with |
return a copy of this ClauseElement with annotations replaced by the given dictionary. |
Class Variable | _clone |
Undocumented |
Inherited from SupportsWrappingAnnotations
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
):
Property | entity |
Undocumented |
Class Variable | _constructor |
Undocumented |
Inherited from SupportsAnnotations
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
):
Class Variable | proxy |
Undocumented |
Method | _gen |
Undocumented |
Class Variable | _is |
Undocumented |
Property | _annotations |
Undocumented |
Inherited from ExternallyTraversible
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
):
Method | get |
Return immediate child :class:`.visitors.HasTraverseInternals` elements of this :class:`.visitors.HasTraverseInternals`. |
Method | _copy |
Reassign internal elements to be clones of themselves. |
Inherited from HasTraverseInternals
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
):
Class Variable | _traverse |
Undocumented |
Inherited from Visitable
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
):
Method | __class |
Undocumented |
Method | __init |
Undocumented |
Class Variable | __visit |
Undocumented |
Class Method | _generate |
Undocumented |
Method | _compiler |
Undocumented |
Class Variable | _original |
Undocumented |
Inherited from HasPrefixes
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
):
Method | prefix |
Add one or more expressions following the statement keyword, i.e. SELECT, INSERT, UPDATE, or DELETE. Generative. |
Class Variable | _has |
Undocumented |
Instance Variable | _prefixes |
Undocumented |
Inherited from HasSuffixes
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
, HasPrefixes
):
Method | suffix |
Add one or more expressions following the statement as a whole. |
Class Variable | _has |
Undocumented |
Instance Variable | _suffixes |
Undocumented |
Inherited from HasHints
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
, HasPrefixes
, HasSuffixes
):
Method | with |
Add an indexing or other executional context hint for the given selectable to this :class:`_expression.Select` or other selectable object. |
Method | with |
Add a statement hint to this :class:`_expression.Select` or other selectable object. |
Method | _with |
Undocumented |
Class Variable | _has |
Undocumented |
Class Variable | _hints |
Undocumented |
Class Variable | _statement |
Undocumented |
Inherited from Identified
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
, HasPrefixes
, HasSuffixes
, HasHints
):
Class Variable | logger |
Undocumented |
Class Variable | logging |
Undocumented |
Method | _should |
Undocumented |
Method | _should |
Undocumented |
Class Variable | _echo |
Undocumented |
Inherited from Generative
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
, HasPrefixes
, HasSuffixes
, HasHints
, Identified
):
Method | _generate |
Undocumented |
Inherited from Executable
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
, HasPrefixes
, HasSuffixes
, HasHints
, Identified
, Generative
):
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | is |
Undocumented |
Class Variable | supports |
Undocumented |
Method | _add |
Add a context option to this statement. |
Method | _compile |
Undocumented |
Method | _execute |
Undocumented |
Method | _execute |
Undocumented |
Method | _set |
Assign the compile options to a new value. |
Method | _update |
update the _compile_options with new keys. |
Class Variable | _executable |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _with |
Undocumented |
Instance Variable | _compile |
Undocumented |
Property | _all |
Undocumented |
Property | _effective |
Undocumented |
Inherited from StatementRole
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
, HasPrefixes
, HasSuffixes
, HasHints
, Identified
, Generative
, Executable
):
Class Variable | _role |
Undocumented |
Inherited from SQLRole
(via Query
, _SelectFromElements
, SupportsCloneAnnotations
, SupportsWrappingAnnotations
, SupportsAnnotations
, ExternallyTraversible
, HasTraverseInternals
, Visitable
, HasPrefixes
, HasSuffixes
, HasHints
, Identified
, Generative
, Executable
, StatementRole
):
Class Variable | allows |
Undocumented |
Class Variable | uses |
Undocumented |
sqlalchemy.orm.query.Query.__init__
Construct a :class:`_query.Query` directly. E.g.:: q = Query([User, Address], session=some_session) The above is equivalent to:: q = some_session.query(User, Address) :param entities: a sequence of entities and/or SQL expressions. :param session: a :class:`.Session` with which the :class:`_query.Query` will be associated. Optional; a :class:`_query.Query` can be associated with a :class:`.Session` generatively via the :meth:`_query.Query.with_session` method as well. .. seealso:: :meth:`.Session.query` :meth:`_query.Query.with_session`
Return a new query, limited to a single shard ID. All subsequent operations with the returned query will be against the single shard regardless of other state. The shard_id can be passed for a 2.0 style execution to the bind_arguments dictionary of :meth:`.Session.execute`:: results = session.execute( stmt, bind_arguments={"shard_id": "my_shard"} )