Reputation: 8055
Is there a way to execute a stored procedure and get back a class ? For example if i have :
class Event(db.Model):
__tablename__ = 'event'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), nullable=False)
Can I do :
db.engine.execute('select * from procedure(?,?)', [param1, param2])
and then get back a list of Event ?
Thanks
Upvotes: 2
Views: 2002
Reputation: 23322
This can be done by using the from_statement
function:
session.query().from_statement('select * from procedure(:p1,:p2)') \
.params(p1 = 1, p2 = 1).all()
Upvotes: 5