Implicit Timestamps #168
pschuette22
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
Hi @pschuette22, we do provide tools for easily creating triggers that allow you to touch a date column after the row has been inserted/updated. This makes it so that the full process of having timestamp columns on a table looks like this: // 1
@Table struct Reminder {
…
let createdAt: Date
let updatedAt: Date?
}
// 2
migrator.registerMigration(…) { db in
#sql("""
CREATE TABLE "reminders" (
…
"createdAt" TEXT NOT NULL DEFAULT (datetime('subsec')),
"updatedAt" TEXT
""")
.execute(db)
}
// 3
try Reminder.createTemporaryTrigger(afterUpdateTouch: \.updatedAt).execute(db) I'm not really sure how much shorter this can be, even if the macro generates some code. One thing you certainly can do is use your try createTimestampTriggers(
for: Reminder.self, RemindersList.self, User.self, ...
)
.execute(db) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First off, thank you for the great work. iOS Development is more clear, stable, and maintainable using Pointfree libraries.
One of the things I added recently was implicit timestamps for table models using database triggers. The implementation we have is somewhat manual and I wonder if there's an appetite to try to work this into the Table macro (if it's not already there?) by default.
Here's the gist of what I have:
Simple protocol just enforces the existence of the created and updated columns
Note: these are internal because of how our app is modularized
While this is all fine and dandy, I wonder if this is interesting enough to work into the table macro? As a relative novice to swift macro writing, would it be possible to aggregate the boilerplate from above into the table macro, something like:
Are there other solutions to this I have not considered or didn't see? Are there any caveats to this that complicate it? I have done a lot of iOS development, but not too much Swift macro, so I'd love a trained eye here.
Thanks again!
Beta Was this translation helpful? Give feedback.
All reactions