Closed purplesmoke05 closed 1 year ago
statement = select(User).where(name="test")
result = session.execute(statement).all()
print(result)
# [(User(name="test"), )]
# returned tupled value of select clause
statement = select(User).where(name="test")
result = session.execute(statement).scalars().all()
# same as "result = session.scalars(statement).all()"
print(result)
# [User(name="test")]
# returned a value of first entity in select clause
statement = select(User, Address).join(Address, User.name == Address.name)
result = session.execute(statement).all()
print(result)
# [(User(name="test"), Address)]
# returned tupled value of select clause
statement = select(User, Address).join(Address, User.name == Address.name)
result = session.execute(statement).scalars().all()
# same as "result = session.scalars(statement).all()"
print(result)
# [User(name="test")]
# returned a value of first entity in select clause
# Address is missing
statement = select(User).where(name="test")
result = session.execute(statement.limit(1)).first()
print(result)
# (User(name="test"), )
statement = select(User).where(name="test")
result = session.execute(statement.limit(1)).scalars().first()
# same as "result = session.scalars(statement.limit(1)).first()"
print(result)
# User(name="test")
stmt = select(User).where(name="test")
result = session.execute(select(func.count()).select_from(stmt)).all()
print(result)
# [(3,), ]
result = session.execute(select(func.count()).select_from(stmt)).first()
print(result)
# (3,)
statement = select(User).where(name="test")
result = session.execute(select(func.count()).select_from(stmt)).scalars().all()
print(result)
# [3]
result = session.execute(select(func.count()).select_from(stmt)).scalars().first()
print(result)
# 3
result = session.execute(select(func.count()).select_from(stmt)).scalar()
print(result)
# 3
Close: #1391