drift icon indicating copy to clipboard operation
drift copied to clipboard

createdAt & updatedAt columns

Open dickermoshe opened this issue 1 year ago • 4 comments

  • Boilerplate for a DateTime column that defaults to the currentDateTime.
  • A way to have a updatedAt column that gets updated on every save to the database

dickermoshe avatar Jun 19 '24 16:06 dickermoshe

We can define these as mixins, which drift will consider if applied to a table, e.g

mixin DateColumns on Table {
  DateTimeColumn get createdAt => dateTime().default(currentDateAndTime)();
}

Dealing with updatedAt is more complicated of course, I usually advice using triggers but I'm not sure if something that invasive should be a simple thing to apply.

simolus3 avatar Jun 19 '24 21:06 simolus3

Well, I wanted to ignore this and just live with the fact that I couldn't have a simple updatedAt column but this was just a week ago so I may as well ask it

I'd honestly love having updatedAt/deletedAt as a simple-to-apply strategy, they are both really useful and a lot of ORMs implement them. Emphasis on the deletedAt though, as it was not mentioned in the original post

Thus being said, if I may be a little greedy, it'd be wonderful if, not only it'd be simple to apply, but also being able to soft delete a row with a simple boolean + the select doesn't count soft deleted (if not explicitely stated)

im-trisha avatar Jun 29 '24 02:06 im-trisha

deletedAt sounds like a really smart idea, but It's out of scope for an ORM, which Drift aims to be. Even the Django ORM, which borders on being a "Data Framework", doesn't have such a feature.

I love the idea though. It's sick.

dickermoshe avatar Jun 30 '24 01:06 dickermoshe

Yes i get what you're saying, I've "had" the idea from GORM, I didn't even need it but at that point that was just too cool to not use :)

im-trisha avatar Jun 30 '24 14:06 im-trisha