Plugin for auto-update "updated_at" field
Hello Team, Greetings!
I am trying to write a plugin that will auto-update the "updated_at" column when there will be an update operation.
So far, I have implemented the following code:
But not sure how to implement further for auto-updating the column, any help or suggestion will really helpful. Thanks š
Note: I am using Postgres.
Solution:Jump to solution
Something like this:
```ts
class UpdatedAtPlugin implements KyselyPlugin {
transformQuery(args: PluginTransformQueryArgs): RootOperationNode {...
6 Replies
Going further, i have removed
SetUpdatedAtTransformer
class and my modified plugin is follows:
But, getting type error
Solution
Something like this:
But I don't recommend doing things like this inside a query builder. You're trying to turn a query builder into an ORM. You'll end up with a really shitty and unpredictable ORM š
Instead consider having another layer on top of Kysely that handles stuff like this.
Absolutely, I agree š
What will your recommendation be for separating this functionality be?
I can go with the DB triggers but they also cause performance issues.
Depends completely on what you like and how you structure your code but at its simplest, just a
updatePerson
function:
Thanks š