将 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
对象。试试 row.id
你的 ID 等等。
我正在尝试将 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
对象。试试 row.id
你的 ID 等等。