Closed IbrahimMohammed47 closed 11 months ago
Thats how things work and dont even need to be mention in docs.
@masterbater I think you based this on assumptions from other libraries.. which is good that you have this intuition.. but it's not the case that everyone is like you or have your same experience. someone who knows only about transactions will firstly ask about what commits it and what rolls it back.
Sequelize - for example - did their homework:
@masterbater I think you based this on assumptions from other libraries.. which is good that you have this intuition.. but it's not the case that everyone is like you or have your same experience. someone who knows only about transactions will firstly ask about what commits it and what rolls it back.
Sequelize - for example - did their homework:
I understand that, you are right if their first orm is drizzle, but you can infer it by their sample transaction in the docs even mention transaction are A transaction in its entirety can commit to a database as a single logical unit or rollback (become undone) as a single logical unit.
https://orm.drizzle.team/docs/transactions
I also check they dont support manual controls of transaction(when to start, rollback, or commit) at least with their helper db.transaction, like prisma and laravel eloquent or any orm
@masterbater I think you based this on assumptions from other libraries.. which is good that you have this intuition.. but it's not the case that everyone is like you or have your same experience. someone who knows only about transactions will firstly ask about what commits it and what rolls it back. Sequelize - for example - did their homework:
I understand that, you are right if their first orm is drizzle, but you can infer it by their sample transaction in the docs even mention transaction are
A transaction in its entirety can commit to a database as a single logical unit or rollback (become undone) as a single logical unit.
https://orm.drizzle.team/docs/transactions
I also check they dont support manual controls of transaction(when to start, rollback, or commit) at least with their helper db.transaction, like prisma and laravel eloquent or any orm
Actually they do support manual control of rolling back which made me a little confused in the first place, this is right from the docs:
const db = drizzle(...)
await db.transaction(async (tx) => {
const [account] = await tx.select({ balance: accounts.balance }).from(accounts).where(eq(users.name, 'Dan'));
if (account.balance < 100) {
await tx.rollback()
return
}
await tx.update(accounts).set({ balance: sql`${accounts.balance} - 100.00` }).where(eq(users.name, 'Dan'));
await tx.update(accounts).set({ balance: sql`${accounts.balance} + 100.00` }).where(eq(users.name, 'Andrew'));
});
Right I just scan it, you are right they support it, my mistake
On Fri, Nov 3, 2023, 5:19 PM Ibrahim Mohammed @.***> wrote:
@masterbater https://github.com/masterbater I think you based this on assumptions from other libraries.. which is good that you have this intuition.. but it's not the case that everyone is like you or have your same experience. someone who knows only about transactions will firstly ask about what commits it and what rolls it back. Sequelize - for example - did their homework: [image: image] https://user-images.githubusercontent.com/25140638/279986446-58d2d83f-0949-47e2-ada9-4c126e380b3c.png
I understand that, you are right if their first orm is drizzle, but you can infer it by their sample transaction in the docs even mention transaction are A transaction in its entirety can commit to a database as a single logical unit or rollback (become undone) as a single logical unit. https://orm.drizzle.team/docs/transactions
I also check they dont support manual controls of transaction(when to start, rollback, or commit) at least with their helper db.transaction, like prisma and laravel eloquent or any orm
Actually they do support manual control of rolling back which made me a little confused in the first place, this is right from the docs:
const db = drizzle(...)await db.transaction(async (tx) => { const [account] = await tx.select({ balance: accounts.balance }).from(accounts).where(eq(users.name, 'Dan')); if (account.balance < 100) { await tx.rollback() return } await tx.update(accounts).set({ balance: sql
${accounts.balance} - 100.00
}).where(eq(users.name, 'Dan')); await tx.update(accounts).set({ balance: sql${accounts.balance} + 100.00
}).where(eq(users.name, 'Andrew'));});— Reply to this email directly, view it on GitHub https://github.com/drizzle-team/drizzle-orm/issues/1450#issuecomment-1792102319, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGI6VFAZ4ADHXQY5QAU4TMTYCSZJPAVCNFSM6AAAAAA6YNLSOWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJSGEYDEMZRHE . You are receiving this because you were mentioned.Message ID: @.***>
They support manual rollbacks, but all tx.rollback()
does is throw an error, so it's just a nice helper function
I think the docs should clearly mention that a transaction would rollback when an exception is thrown without catching it inside the transaction block