kurtbuilds / ormlite

An ORM in Rust for developers that love SQL.
https://crates.io/crates/ormlite
MIT License
216 stars 11 forks source link

How to have a field be auto set every time the model is modified? #50

Open Thermatix opened 3 months ago

Thermatix commented 3 months ago

I can have a field for setting the creation date:

#[ormlite(default_value = "chrono::Utc::now()")]
pub updated_at: Option<DateTime<Utc>>,

but how can I have a field that is auto set every time the model is modified, I.e. an updated_at field?

kurtbuilds commented 3 months ago

The library doesn't support this yet.

I think db triggers is the right approach, so that the update logic isn't dependent on the ORM.

PR is welcome, and happy to answer any questions that come up.