Sqlalchemy - 数据查询(无条件查询+条件查询)

Sqlalchemy - 数据查询(无条件查询+条件查询)_第1张图片



专题:【Python - 闭包 Closure

from connect_mysql import engine,User
from sqlalchemy.orm import sessionmaker
Session = sessionmaker(engine)
db_session = Session()

# 查询数据(指定的一个数据)
# user = db_session.query(User).first()
# print(user.id)

user_object_list = db_session.query(User).all()
print(user_object_list)
print(type(user_object_list))
for i in user_object_list:
    print(i.id,i.name)

#带条件的查询(使用逗号表示且,两个等号)
# user_object_list = db_session.query(User).filter(User.id==179074002).all()
# for row in user_object_list:
#     print(row.id,row.name)

 

你可能感兴趣的:(Sqlalchemy)