title: What is the equivalent of Query.count in the SQLAlchemy 1.4 ORM?
body: <p>Given a SQLAlchemy ORM model like this</p>
  <pre class="lang-py prettyprint-override"><code>class Foo(Base):
      __tablename__ = 'foo'
  
      id = sa.Column(sa.Integer, primary_key=True)
      name = sa.Column(sa.String())
  </code></pre>
  <p>In SQLAlchemy 1.4 / 2.0, the ORM's <code>session.query</code> idiom is being unified with the SQLAlchemy core <code>select</code> function*, so to fetch all <code>Foo</code>s we would do</p>
  <pre><code>foos = session.execute(Foo).scalars().all()
  </code></pre>
  <p>instead of</p>
  <pre><code>foos = session.query(Foo).all()
  </code></pre>
  <p>In the current (sqlalchemy&lt;=1.3) ORM we can obtain the number of <code>Foo</code>s in the database with this query:</p>
  <pre><code>nfoos = session.query(Foo).count()
  </code></pre>
  <p>But how can we get the count in SQLALchemy 1.4?</p>
  <pre><code>session.execute(sa.select(Foo).count())
  </code></pre>
  <p>raises</p>
  <blockquote>
  <p>AttributeError: 'Select' object has no attribute 'count'</p>
  </blockquote>
  <pre><code>session.execute(sa.select(Foo)).count()
  </code></pre>
  <p>raises</p>
  <blockquote>
  <p>AttributeError: 'ChunkedIteratorResult' object has no attribute 'count'</p>
  </blockquote>
  <pre><code>session.execute(sa.select(sa.func.count(Foo)))
  </code></pre>
  <p>raises</p>
  <blockquote>
  <p>sqlalchemy.exc.ArgumentError: SQL expression element expected, got <code>&lt;class '__main__.Foo'&gt;</code>.</p>
  </blockquote>
  <p>This works,</p>
  <pre><code>session.execute(sa.select(sa.func.count(Foo.id))).scalars()
  </code></pre>
  <p>but specifying an attribute seems less OO / elegant than the <code>Query.count</code> version.  Moreover, it precludes building a query but deferring the decision of whether to retrieve the count or the model instances.</p>
  <p>What is the idiomatic way to get the <code>count()</code> of an ORM query in the new SQLAlchemy 1.4 world?</p>
  <hr />
  <p>* the <code>session.query()</code> API will still work in 1.4 and later</p>