feat: scoped data objects#380
Conversation
f61c80e to
3004a19
Compare
e409722 to
4657d80
Compare
f088dfc to
e94804a
Compare
JakeTrevor
left a comment
There was a problem hiding this comment.
This is very cool work. I think it is a great step in the right direction.
There are a few minor points which are in the comments below - but there is one major point I want to raise right now.
I think the way scope.transaction works at the minute should be tweaked. There are details below, but the problem is that constructing a new scope object means that everything that uses the old one is unusable. This seems bad to me on a few levels.
Firstly, it means that we need to construct new DOs inside the tx. At the least, this is annoying. I think the fact that the objects are just there is part of what makes the proc api stuff so nice to work with.
But I also worry that it could error prone - you must not use the existing objects from the proc inside the tx, because they aren't using the right scope.
So I think the better solution is to instead have scope.transaction mutate the scope it's called on, so that the scope's db is the tx object. The advantage here is that so long as all the objects share the same scope (and they should) then calling transaction just makes everything work magically - so long as we can get it to work.
There's a sketch of what this could look like in the comments. It probably needs testing.
JakeTrevor
left a comment
There was a problem hiding this comment.
I don't have any major comments for this. I think the heart of it is very good. We can quibble about some of the tedious details later.
5d99030 to
25cfde9
Compare
Scope tracks whether a data object is in a transaction to enable DO methods to participate in transactions as a bonus this eliminates the standalone tx helpers
…d old project with scope
5cab167 to
4b326c5
Compare
This is pt.2 of the big backend refactor
Summary
Scopeabstraction that wraps the Prisma DB client and provides nice ergonomic, nestable transaction managementProjectdata object fromDataObject(which uses the raw DB client) toScopedDataObject, so it automatically participates in whatever transaction context it's given (it works similar to how thegetoperations for spaces on DOs either return a cached object or create one, cache it and then return it)ProjectDO can now absorb standalone transactionsdb.$transaction(we can slowly start to phase db out of the tRPC context, in favour of the newsc(scope) which supports transaction when they are needed)We are still not at the end of the road there is one or two more parts I would like to explore, but before I start committing to stuff, I'd like to get your feedback on this idea.