I am trying to query for 3 fields in a table like this in sqlalchemy:
if request.method == 'GET':
search_form = SearchForm()
result = dbSession.execute(
"SELECT * FROM books WHERE (isbn LIKE '%:text%') OR (title LIKE '%:text%') OR (author LIKE '%:text%') LIMIT 10",
{ "text": search_form.searchText.data }
)
return jsonify({'result': result})
Is my query correct? why would i have this error?
TypeError: Object of type ResultProxy is not JSON serializable
Simply error says result
is not a dictionary. To solve it:
jsonify({'result': [dict(row) for row in result]})
It will convert each row to a dictionary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With