Closed igalklebanov closed 21 hours ago
The latest updates on your projects. Learn more about Vercel for Git ↗︎
Name | Status | Preview | Comments | Updated (UTC) |
---|---|---|---|---|
kysely | ✅ Ready (Inspect) | Visit Preview | 💬 Add feedback | Oct 5, 2024 4:53pm |
I was wondering, since you already have a reference to the transaction trxAfterFoo
and it has been named at creation with trx.savepoint('foo').execute()
why not default to it
instead of
trxAfterFoo.rollbackToSavepoint('foo')
It should technically be enough with trxAfterFoo.rollbackToSavepoint()
or am I missing something?
The reason I ask is because I'd like something simple like db.startTransaction()
and db.endTransaction()
to be in beforeEach
and afterEach
test, so each unit test runs with empty tables.
I was wondering, since you already have a reference to the transaction
trxAfterFoo
and it has been named at creation withtrx.savepoint('foo').execute()
why not default to itinstead of
trxAfterFoo.rollbackToSavepoint('foo')
It should technically be enough with
trxAfterFoo.rollbackToSavepoint()
or am I missing something?The reason I ask is because I'd like something simple like
db.startTransaction()
anddb.endTransaction()
to be inbeforeEach
andafterEach
test, so each unit test runs with empty tables.
I'll investigate, but off the top:
trxAfterFoo
provides autocompletion and type-checking of the savepoint argument you pass to rollbackToSavepoint
. What are we saving here? a few characters? what's so wrong about:let trx: ControlledTransaction<DB, ['post_setup']>;
before(async () => {
const initialTrx = await db.startTransaction().execute();
await setupTest(initialTrx);
trx = await trx.savepoint('post_setup').execute();
});
afterEach(async () => {
await trx.rollbackToSavepoint('post_setup').execute();
});
after(async () => {
await trx.rollback().execute();
});
This would introduce the need for either runtime errors when the instance doesn't have an "immediate" savepoint to default to OR to subclass ControlledTransaction
and move some savepoint methods to the child. Having to pass the argument and having its type bound to a list of savepoints allows us to keep things less complicated.
It is less WYSIWYG.
Tests are not the only use case for this, tho I'd love for all use cases to have good DX here.
trxAfterFoo
allows rolling back and releasing savepoints up to "foo" AND savepoints that were created before it.
You'd still have to hold onto a new instance of the same transaction, but with foo
in its state. We don't mutate existing instances as a design principle.
Just want to say this is a great feature, and I eagerly await for this to be released.
closes #257.
This PR adds some optional savepoint-related methods to drivers - need to make sure we don't introduce a breaking change here! A new
ControlledTransaction
that allows manualcommit
,rollback
and savepoint-related commands.Some design goals (that hopefully will be met once this is done) with
ControlledTransaction
:- allow to release the connection on commit/rollback on demand via an option.