I have defined a table with flask-sqlalchemy. Displayed below.
class Notes(db.Model):
id = db.Column(db.Integer, primary_key=True)
notes = db.Column(db.Text, nullable=False)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
added_at = db.Column(db.DateTime, default=db.func.now())
@staticmethod
def newest(num):
return Notes.query.order_by(desc(Notes.added_at)).limit(num)
I'm attempting to write a query that is to replace and already existing direct query, which looks like this.
select notes,user,added_at from notes where added_at >= now() - INTERVAL 8 HOUR;
However based on the documentation that I can find, I'm not able to find a method to do the same. I'm able to make simpler queries, but I'm struggling to recreate what's pretty simple in sql itself.
I'm more than willing to read some documentation surrounding it, wasn't able to precisely nail that down either. Any direction you could provide would be awesome.