温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/bun/SQL/beginDistributed
点击访问原文链接

SQL.beginDistributed method | Bun module | Bun

SQL.beginDistributed method | Bun module | BunBuildDocsReferenceGuidesBlogDiscord/Bun/SQL/beginDistributedMbeginDistributed

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/Bun/SQL/beginDistributedMbeginDistributed

method

SQL.beginDistributedbeginDistributedT>(name: string,fn: TransactionContextCallbackT>): PromiseContextCallbackResultT>>;

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.

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");
Referenced typestype TransactionContextCallbackT> = ContextCallbackT, TransactionSQL>

Callback function type for transaction contexts

type ContextCallbackResultT> = T extends PromiseLikeany>[] ? AwaitPromisesArrayT> : AwaitedT>

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

SQL.beginDistributed method | Bun module | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for method bun.SQL.beginDistributed | Bun