Can i use transaction in multiple connection?

In my case i use multiple connection to insert data

await Database.connection('db01').table('agent').insert({})

await Database.connection('db02').table('agent').insert({})

await Database.connection('db03').table('agent').insert({})

How to use transaction in the example code above at the same time ?

Yes, you can use

How to do that ?

Is there a sample code ?

From fast searching it seems like you can’t do transaction across multiple connections. Seems to be limitation of database server.

Most likely you can hack something together with promises and manually reverting everything if one fails.

Here is issue about it in Knex (and Adonis uses Knex under the hood)

Another idea that I just got is that you create staging table or to_be_inserted table or something similar. First you write all your data in there and after all writes succeed you do last query

INSERT INTO real_table (hurr, durr) 
SELECT hurr, durr
FROM staging
WHERE some_condition;  

Sorry for wrong replay