Begins a distributed transaction Also know as Two-Phase Commit, in a distributed transaction, Phase 1 involves the coordinator preparing nodes by ensuring data is written and ready to commit, while Phase 2 finalizes with nodes committing or rolling back based on the coordinator's decision, ensuring durability and releasing locks. In PostgreSQL and MySQL distributed transactions persist beyond the original session, allowing privileged users or coordinators to commit/rollback them, ensuring support for distributed transactions, recovery, and administrative tasks. beginDistributed will automatic rollback if any exception are not caught, and you can commit and rollback later if everything goes well. PostgreSQL natively supports distributed transactions using PREPARE TRANSACTION, while MySQL uses XA Transactions, and MSSQL also supports distributed/XA transactions. However, in MSSQL, distributed transactions are tied to the original session, the DTC coordinator, and the specific connection. These transactions are automatically committed or rolled back following the same rules as regular transactions, with no option for manual intervention from other sessions, in MSSQL distributed transactions are used to coordinate transactions using Linked Servers.
SQL.beginDistributed method | Bun module | Bun BuildDocsReferenceGuidesBlogDiscord/Bun/SQL/beginDistributedMbeginDistributed BuildDocsReferenceGuidesBlogDiscord /Bun/SQL/beginDistributedMbeginDistributed SQL.beginDistributedbeginDistributedT>(name: string,fn: TransactionContextCallbackT>): PromiseContextCallbackResultT>>; Referenced typestype TransactionContextCallbackT> = ContextCallbackT, TransactionSQL> type ContextCallbackResultT> = T extends PromiseLikeany>[] ? AwaitPromisesArrayT> : AwaitedT>
Search the reference...
/
method
await sql.beginDistributed("numbers", async sql => {
await sql`create table if not exists numbers (a int)`;
await sql`insert into numbers values(1)`;
});
// later you can call
await sql.commitDistributed("numbers");
// or await sql.rollbackDistributed("numbers");
Callback function type for transaction contexts
Resources
ReferenceDocsGuidesDiscordMerch StoreGitHubBlogToolkit
RuntimePackage managerTest runnerBundlerPackage runnerProject
Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicenseBaked with ❤️ in San Francisco
We're hiring →SQL.beginDistributed method | Bun module | Bun,AI智能索引,全网链接索引,智能导航,网页索引
- API documentation for method bun.SQL.beginDistributed | Bun