hooks
CanRau opened this issue · 3 comments
Sorry I'm on phone right now so just referencing this right now drizzle-team/drizzle-orm#1426
Hello.
I am considering creating something proxy-like. So you can add virtual fields or methods to the row. Perhaps wrap it in a Class instance. But I need to consider implications first. But checking the query that is sent in, is not going to work, because this can be literally anything - not only id based.
Also, a delete interceptor can be tricky and give performance loss, because it won't cover bulkDeletes. If this should cover bulkDeletes, then delete mechinism would need to first check if hook is present, and then fetch the rows to memory insteading sending the delete query direcly to the db.
Ah haven't considered bulk queries at all.
Why would it need to fetch the rows to memory? 🤔
I was thinking the generated SQL query could be "just" transformed from something like this
DELETE FROM table WHERE id = :id;
to something like this
UPDATE table SET deleted_at = NOW() WHERE id = :id;
and in a bulk situation "just" map over each query and transform if there's an on-delete
hook present on the table schema 🤔
But I've no idea what's happening under the hood so 🤷🏼
On second thought, I think soft deletes is a totally separate concept that should handled by table mapping instead.
So soft deletes, should have it's own issue.