Coder Social home page Coder Social logo

Needed: Database Transaction handling for multiple database actions if any error occurred Rollback for data consistency. about supabase-dart HOT 8 CLOSED

supabase avatar supabase commented on June 17, 2024
Needed: Database Transaction handling for multiple database actions if any error occurred Rollback for data consistency.

from supabase-dart.

Comments (8)

bdlukaa avatar bdlukaa commented on June 17, 2024

This is a valid request, but I don't think this will be addressed any time soon

from supabase-dart.

JasonChiu-dev avatar JasonChiu-dev commented on June 17, 2024

This is a valid request, but I don't think this will be addressed any time soon

  1. Thank you for your reply. The transaction is a key function for database handling. How long will it release?
  2. I don't know how to really implement the correct rpc function for multiple database actions with complex arguments for database actions, including insert to the first table by multiple rows and then update the second table for different rows with different id and then update the third table for updating the data by key, if there is any error occurred during the THREE TABLEs transaction then ROLLBACK, otherwise COMMIT the transaction.

Is there Any solution or suggestion for writing the correct rpc function to handle the multiple tables' operations(insert, update, ...) in one transaction which can make sure the data consistency?

from supabase-dart.

bdlukaa avatar bdlukaa commented on June 17, 2024

In my opinion, creating a rpc function is the best option.

There are some examples out there in the internet.

if there is any error occurred during the THREE TABLEs

My question is: why would there be any error in the transaction?

from supabase-dart.

JasonChiu-dev avatar JasonChiu-dev commented on June 17, 2024

In my opinion, creating a rpc function is the best option.

There are some examples out there in the internet.

if there is any error occurred during the THREE TABLEs

My question is: why would there be any error in the transaction?

The app is running on cloud and multi-users environment. I don't what kind of error will occurred but for data consistency, it is needed to check any error especially the THREE TABLES' actions are in ONE transaction.

from supabase-dart.

JasonChiu-dev avatar JasonChiu-dev commented on June 17, 2024

I do need the feature: BEGIN / COMMIT / ROLLBACK on Supabase, like:

await supabase.transaction(
supabase.from(...).insert(table1...),
// if any error, rollback.
supabase.from(...).update(table2...)
// if any error, rollback.
supabase.from(...).updata(table3...)
// if no error, Commit.
)

BANKing Transaction is a very good example for why I need the function as I mentioned above.

from supabase-dart.

JasonChiu-dev avatar JasonChiu-dev commented on June 17, 2024

I don't what kind of error will occurred but for data consistency, it is needed to check any error especially the THREE TABLES' actions are in ONE transaction.

correct typo: I don't know what kind of error will occurred during the transaction. But for data consistency, it is needed to check any error and rollback, especially the THREE TABLES' actions are in ONE transaction and it has to commit when the THREE TABLEs actions are all succeed.

from supabase-dart.

bdlukaa avatar bdlukaa commented on June 17, 2024

As I said, this could be achieved as a rpc function. Supabase uses Postgre, which support transactions.

See https://www.postgresql.org/docs/8.3/tutorial-transactions.html

Unfortunately Supabase is still in beta and doesn't have all these features yet. Tho, this can be achived with a rpc function.

Tho this a valid request to make to the main team

from supabase-dart.

steve-chavez avatar steve-chavez commented on June 17, 2024

it is needed to check any error especially the THREE TABLES' actions are in ONE transaction.

@JasonChiu-dev I've added an example for how to do the above on supabase/supabase#3732 (comment). Basically you just need to do RAISE on the function.

I'll close this one, a more general transactions interface can be discussed at supabase/postgrest-js#219.

from supabase-dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.