alfateam / orange-orm

The ultimate ORM for Node and Typescript
https://orange-orm.io
ISC License
623 stars 20 forks source link

hooks #60

Closed CanRau closed 2 months ago

CanRau commented 8 months ago

Sorry I'm on phone right now so just referencing this right now https://github.com/drizzle-team/drizzle-orm/discussions/1426

lroal commented 8 months ago

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.

CanRau commented 8 months ago

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 🤷🏼

lroal commented 8 months ago

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.