繁体   English   中英

将 SQLAlchemy 查询的结果存储在数组中

[英]Storing the results of a SQLAlchemy query in an array

我正在尝试将 SQLAlchemy 语句的结果存储在一个数组中。 但它给了我属性错误。 请帮忙。

qry = ( db.session.query(客户) )

print(qry)

results = [
    {
        
        "customerID": getModelField(row.Customer, "id"),
        "network": getModelField(row.Customer, "network_num"),
        "customer": getModelField(row.Customer,"customer_name"),
        "email": getModelField(row.Customer, "customer_email"),
             
    }
    for row in qry.all()
]

out = {"results": results, "total": len(results)}

在控制台中,我得到 - AttributeError: 'Customer' object has no attribute 'Customer'

查询结果的每一行都是Customer object。尝试row.id作为您的 ID 等等。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM