python-gino / gino

GINO Is Not ORM - a Python asyncio ORM on SQLAlchemy core.
https://python-gino.org/
Other
2.68k stars 150 forks source link

Create PSQL onupdate trigger #689

Closed flapili closed 4 years ago

flapili commented 4 years ago

Hi, I have some difficulty with datetime default values and update's trigger

from what I understand I can handle default value with server_default=now but how handle update?

as example in this schema

class User(db.Model):
    __tablename__ = "users"

    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.DateTime, nullable=False, server_default="now")
    updated_at = db.Column(db.DateTime, nullable=False, server_default="now", onupdate=datetime.datetime.now)

but the problem is the onupdate is manager by python and not by postgress, so is it possible with Gino to define the onupdate trigger ?

fantix commented 4 years ago

I would recommend the use of database trigger. You may create triggers using Alembic.

wwwjfy commented 4 years ago

Closing due to inactivity. Feel free to reopen.