PageSourceSearch

https://spacetimedb.com/docs/assets/js/8a14c890.b11502fa.js

js spacetimedb.com collected 2026-09-25 14:15:02 UTC 43,260 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunkdocs=self.webpackChunkdocs||[]).push([[23],{31966:(e,s,n)=>{n.r(s),n.d(s,{assets:()=>h,contentTitle:()=>d,default:()=>x,frontMatter:()=>i,metadata:()=>l,toc:()=>F});const l=JSON.parse('{"id":"core-concepts/databases/transactions-atomicity","title":"Transactions and Atomicity","description":"SpacetimeDB provides strong transactional guarantees for all database operations. Every reducer runs inside a database transaction, ensuring your data remains consistent and reliable even under concurrent load.","source":"@site/docs/00200-core-concepts/00100-databases/00100-transactions-atomicity.md","sourceDirName":"00200-core-concepts/00100-databases","slug":"/databases/transactions-atomicity","permalink":"/docs/databases/transactions-atomicity","draft":false,"unlisted":false,"editUrl":"https://github.com/clockworklabs/SpacetimeDB/edit/master/docs/docs/00200-core-concepts/00100-databases/00100-transactions-atomicity.md","tags":[],"version":"current","sidebarPosition":100,"frontMatter":{"title":"Transactions and Atomicity","slug":"/databases/transactions-atomicity"},"sidebar":"sidebar","previous":{"title":"The Database Module","permalink":"/docs/databases"},"next":{"title":"spacetime dev","permalink":"/docs/databases/developing"}}');var r=n(86106),c=n(56225),a=n(51471),t=n(43244),o=n(67834);const i={title:"Transactions and Atomicity",slug:"/databases/transactions-atomicity"},d=void 0,h={},F=[{value:"What is a Transaction?",id:"what-is-a-transaction",level:2},{value:"ACID Properties",id:"acid-properties",level:2},{value:"Atomicity",id:"atomicity",level:3},{value:"Consistency",id:"consistency",level:3},{value:"Isolation",id:"isolation",level:3},{value:"Durability",id:"durability",level:3},{value:"Transaction Scope",id:"transaction-scope",level:2},{value:"Reducers: Automatic Transactions",id:"reducers-automatic-transactions",level:3},{value:"Nested Reducer Calls",id:"nested-reducer-calls",level:3},{value:"Procedures: Manual Transactions",id:"procedures-manual-transactions",level:3},{value:"Best Practices",id:"best-practices",level:2},{value:"Keep Transactions Short",id:"keep-transactions-short",level:3},{value:"Handle Errors Gracefully",id:"handle-errors-gracefully",level:3},{value:"Limitations",id:"limitations",level:2},{value:"No Nested Transactions",id:"no-nested-transactions",level:3},{value:"Auto-Increment is Not Transactional",id:"auto-increment-is-not-transactional",level:3},{value:"Related Topics",id:"related-topics",level:2}];function p(e){const s={a:"a",admonition:"admonition",code:"code",h2:"h2",h3:"h3",li:"li",p:"p",pre:"pre",span:"span",strong:"strong",ul:"ul",...(0,c.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(s.p,{children:["SpacetimeDB provides strong transactional guarantees for all database operations. Every ",(0,r.jsx)(s.a,{href:"/docs/functions/reducers",children:"reducer"})," runs inside a database transaction, ensuring your data remains consistent and reliable even under concurrent load."]}),"\n",(0,r.jsx)(s.h2,{id:"what-is-a-transaction",children:"What is a Transaction?"}),"\n",(0,r.jsxs)(s.p,{children:["A ",(0,r.jsx)(s.a,{href:"https://en.wikipedia.org/wiki/Database_transaction",children:"database transaction"})," is a sequence of operations that execute as a single, indivisible unit of work. In SpacetimeDB, each reducer invocation is a transaction - either all of its changes succeed and are committed to the database, or all changes are rolled back as if the reducer never ran."]}),"\n",(0,r.jsx)(s.h2,{id:"acid-properties",children:"ACID Properties"}),"\n",(0,r.jsx)(s.p,{children:"SpacetimeDB transactions provide the following guarantees:"}),"\n",(0,r.jsx)(s.h3,{id:"atomicity",children:"Atomicity"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"All-or-nothing execution"}),": A reducer's changes either all succeed or all fail together. There's no partial state."]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["If a reducer completes successfully, all changes (inserts, updates, deletes) are ",(0,r.jsx)(s.strong,{children:"committed"})," to the database"]}),"\n",(0,r.jsxs)(s.li,{children:["If a reducer throws an exception or returns an error, all changes are ",(0,r.jsx)(s.strong,{children:"rolled back"})," and the database remains unchanged"]}),"\n",(0,r.jsx)(s.li,{children:"It's not possible to keep some changes and discard others from a single reducer execution"}),"\n"]}),"\n",(0,r.jsx)(s.admonition,{type:"note",children:(0,r.jsxs)(s.p,{children:["This atomicity guarantee applies to ",(0,r.jsx)(s.strong,{children:"reducers"}),", which run in a single transaction. ",(0,r.jsx)(s.a,{href:"/docs/functions/procedures",children:"Procedures"})," can manually open multiple separate transactions, where each transaction is individually atomic, but the procedure as a whole is not. See ",(0,r.jsx)(s.a,{href:"#procedures-manual-transactions",children:"Procedures: Manual Transactions"})," below."]})}),"\n",(0,r.jsx)(s.h3,{id:"consistency",children:"Consistency"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Valid states only"}),": Transactions ensure the database moves from one valid state to another. All constraints (unique keys, indexes, foreign key-like relationships in your logic) are enforced."]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:"Unique constraints are checked before commit"}),"\n",(0,r.jsx)(s.li,{children:"If a constraint would be violated, the entire transaction is rolled back"}),"\n",(0,r.jsx)(s.li,{children:"The database never enters an invali
1d state"}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"isolation",children:"Isolation"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Consistent snapshots"}),": Each reducer sees a consistent snapshot of the database and doesn't observe partial changes from other reducer executions."]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:"A reducer sees the database state as it was at the start of its transaction"}),"\n",(0,r.jsx)(s.li,{children:"A reducer will not observe the effects of other reducers modifying the database while it runs"}),"\n",(0,r.jsx)(s.li,{children:"Each reducer completes fully before its changes are visible to others"}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"This prevents race conditions and ensures predictable behavior."}),"\n",(0,r.jsx)(s.h3,{id:"durability",children:"Durability"}),"\n",(0,r.jsxs)(s.p,{children:[(0,r.jsx)(s.strong,{children:"Persistent changes"}),": Once a reducer successfully commits, its changes are permanent and will survive server restarts. SpacetimeDB persists committed transactions to disk."]}),"\n",(0,r.jsx)(s.h2,{id:"transaction-scope",children:"Transaction Scope"}),"\n",(0,r.jsx)(s.h3,{id:"reducers-automatic-transactions",children:"Reducers: Automatic Transactions"}),"\n",(0,r.jsx)(s.p,{children:"Every reducer invocation automatically runs in its own transaction:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:"The transaction starts when the reducer is called"}),"\n",(0,r.jsx)(s.li,{children:"The transaction commits when the reducer returns successfully"}),"\n",(0,r.jsx)(s.li,{children:"The transaction rolls back if the reducer throws an exception or returns an error"}),"\n"]}),"\n",(0,r.jsx)(s.p,{children:"You don't need to manually start or commit transactions in reducers - SpacetimeDB handles this automatically."}),"\n",(0,r.jsx)(s.h3,{id:"nested-reducer-calls",children:"Nested Reducer Calls"}),"\n",(0,r.jsxs)(s.p,{children:["When a reducer calls another reducer directly (not via scheduling), they execute in the ",(0,r.jsx)(s.strong,{children:"same transaction"}),":"]}),"\n",(0,r.jsxs)(a.A,{groupId:"server-language",queryString:!0,children:[(0,r.jsx)(t.A,{value:"typescript",label:"TypeScript",children:(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"export"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" const"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" parent_reducer "}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"="}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" spacetimedb."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"reducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(("}),(0,r.jsx)(s.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:") "}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"=>"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    TableA."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"({ "}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"/* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // This runs in the SAME transaction"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"    childReducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(ctx);"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    TableB."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"({ "}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"/* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // All changes from both parent and child commit together"})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"});"})}),"\n",(0,r.jsx)(s.span,{className:"line"}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"function"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" childReducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:"ctx"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:") {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    TableC."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"({ "}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"/* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // If this throws, the parent's changes also roll back"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"    if"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" (someCondition) {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"        throw"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6",fontWeight:"bold"},children:" new"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" Error"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#E9F284"},children:"'"}),(0,r.jsx)(s.span,{style:{color:"#F1FA8C"},children:"Child failed"}),(0,r.jsx)(s.span,{style:{color:"#E9F284"},children:"'"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,r.jsx)(t.A,{value:"csharp",label:"C#",children:(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"["}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Reducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"public"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" static"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" void"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" ParentReducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,r.jsx)(s.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ctx.Db.TableA."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"Insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"new"}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" RowA"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" { "}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"/* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // This runs in the SAME transaction"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"    ChildReducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(ctx);"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ctx.Db.TableB."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"Insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"new"}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" RowB"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" { "}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"/* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // All changes from both parent and child commit together"})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,r.jsx)(s.span,{className:"line"}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"["}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"SpacetimeDB"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"Reducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"]"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"public"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" static"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" void"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" ChildReducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,r.jsx)(s.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" ctx"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:")"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"{"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ctx.Db.TableC."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"Insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"new"}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" RowC"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" { "}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"/* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // If this throws, the parent's changes also roll back"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"    if"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" (someCondition)"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    {"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"        throw"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" new"}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Exception"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#E9F284"},children:'"'}),(0,r.jsx)(s.span,{style:{color:"#F1FA8C"},children:"Child failed"}),(0,r.jsx)(s.span,{style:{color:"#E9F284"},children:'"'}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,r.jsx)(t.A,{value:"rust",label:"Rust",children:(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,r.jsxs)(s.code,{children:[(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"#[reducer]"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"pub"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" fn"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" parent_reducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:":"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" &"}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:") "}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"->"}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"<(), "}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"String"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"> {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ctx"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"db"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"table_a"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"}
1,children:"()"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"RowA"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" { "}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"/* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // This runs in the SAME transaction"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"    child_reducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(ctx)"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"?"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:";"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ctx"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"db"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"table_b"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"()"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"RowB"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" { "}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"/* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // All changes from both parent and child commit together"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"    Ok"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(())"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,r.jsx)(s.span,{className:"line"}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"#[reducer]"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"pub"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" fn"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" child_reducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(ctx"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:":"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" &"}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:") "}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"->"}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Result"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"<(), "}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"String"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"> {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ctx"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"db"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"table_c"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"()"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"RowC"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" { "}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"/* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // If this returns Err, the parent's changes also roll back"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"    if"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" some_condition {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"        return"}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:" Err"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#F1FA8C"},children:'"Child failed"'}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"to_string"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"}
1,children:"());"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"    Ok"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(())"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})}),(0,r.jsxs)(t.A,{value:"cpp",label:"C++",children:[(0,r.jsx)(o._,{}),(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(s.pre,{className:"shiki spacetime-dark",style:{backgroundColor:"var(--clockworklabs-code-background-color)",color:"#F8F8F2"},tabIndex:"0",children:(0,r.jsxs)(s.code,{children:[(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"using"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:" namespace"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" SpacetimeDB;"})]}),"\n",(0,r.jsx)(s.span,{className:"line"}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"// Forward declare child reducer to allow calling it before its definition"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerResult"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" child_reducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#8BE9FD",fontStyle:"italic"},children:"ReducerContext"}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"&"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:", "}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"bool"}),(0,r.jsx)(s.span,{style:{color:"#FFB86C",fontStyle:"italic"},children:" some_condition"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,r.jsx)(s.span,{className:"line"}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"SPACETIMEDB_REDUCER"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(parent_reducer, ReducerContext ctx, "}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"bool"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" some_condition) {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ctx.db[table_a]."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(RowA{"}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:" /* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // This runs in the SAME transaction"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ReducerResult result "}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"="}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" child_reducer"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(ctx, some_condition);"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"    if"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" (result."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"is_err"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"()) {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"        return"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" result;"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ctx.db[table_b]."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(RowB{"}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:" /* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // All changes from both parent and child commit together"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"    return"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" Ok"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"}
1,children:"();"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"}"})}),"\n",(0,r.jsx)(s.span,{className:"line"}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"SPACETIMEDB_REDUCER"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(child_reducer, ReducerContext ctx, "}),(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"bool"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" some_condition) {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    ctx.db[table_c]."}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:"insert"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"(RowC{"}),(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:" /* ... */"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" });"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#6272A4"},children:"    // If this returns Err, the parent's changes also roll back"})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"    if"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:" (some_condition) {"})]}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"        return"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" Err"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"("}),(0,r.jsx)(s.span,{style:{color:"#E9F284"},children:'"'}),(0,r.jsx)(s.span,{style:{color:"#F1FA8C"},children:"Child failed"}),(0,r.jsx)(s.span,{style:{color:"#E9F284"},children:'"'}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:");"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    }"})}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"    "})}),"\n",(0,r.jsxs)(s.span,{className:"line",children:[(0,r.jsx)(s.span,{style:{color:"#FF79C6"},children:"    return"}),(0,r.jsx)(s.span,{style:{color:"#50FA7B"},children:" Ok"}),(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"();"})]}),"\n",(0,r.jsx)(s.span,{className:"line",children:(0,r.jsx)(s.span,{style:{color:"#F8F8F2"},children:"}"})})]})})})]})]}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsxs)(s.p,{children:["SpacetimeDB does ",(0,r.jsx)(s.strong,{children:"not"})," support nested transactions. Nested reducer calls execute in the same transaction as their parent. If you need separate transactions, use ",(0,r.jsx)(s.a,{href:"/docs/tables/schedule-tables",children:"scheduled reducers"})," instead."]})}),"\n",(0,r.jsx)(s.h3,{id:"procedures-manual-transactions",children:"Procedures: Manual Transactions"}),"\n",(0,r.jsxs)(s.p,{children:["Unlike reducers, ",(0,r.jsx)(s.a,{href:"/docs/functions/procedures",children:"procedures"})," don't automatically run in transactions. Procedures can run transactions, but must manually open them using ",(0,r.jsx)(s.code,{children:"with_tx"})," (Rust) or ",(0,r.jsx)(s.code,{children:"withTx"})," (TypeScript). This gives procedures more flexibility:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:["Procedures can perform operations ",(0,r.jsx)(s.strong,{children:"outside"})," transactions (like HTTP requests)"]}),"\n",(0,r.jsxs)(s.li,{children:["Procedures can open ",(0,r.jsx)(s.strong,{children:"multiple separate transactions"})," if needed"]}),"\n",(0,r.jsxs)(s.li,{children:["Each ",(0,r.jsx)(s.code,{children:"with_tx"}),"/",(0,r.jsx)(s.code,{children:"withTx"})," call creates a new transaction that commits independently"]}),"\n"]}),"\n",(0,r.jsxs)(s.p,{children:["See ",(0,r.jsx)(s.a,{href:"/docs/functions/procedures",children:"Procedures"})," for more details on manual transaction management."]}),"\n",(0,r.jsx)(s.h2,{id:"best-practices",children:"Best Practices"}),"\n",(0,r.jsx)(s.h3,{id:"keep-transactions-short",children:"Keep Transactions Short"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:"Perform only necessary database operations within reducers"}),"\n",(0,r.jsxs)(s.li,{children:["Move external I/O (HTTP requests, etc.) to ",(0,r.jsx)(s.a,{href:"/docs/functions/procedures",children:"procedures"})]}),"\n",(0,r.jsx)(s.li,{children:"Shorter transactions reduce contention and improve throughput"}),"\n"]}),"\n",(0,r.jsx)(s.h3,{id:"handle-errors-gracefully",children:"Handle Errors Gracefully"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:"Return descriptive errors to help clients understand failures"}),"\n",(0,r.jsxs)(s.li,{children:["Use ",(0,r.jsx)(s.code,{children:"Result<(), String>"})," in Rust or throw exceptions with clear messages"]}),"\n",(0,r.jsx)(s.li,{children:"Remember: any error rolls back ALL changes"}),"\n"]}),"\n",(0,r.jsx)(s.h2,{id:"limitations",children:"Limitations"}),"\n",(0,r.jsx)(s.h3,{id:"no-nested-transactions",children:"No Nested Transactions"}),"\n",(0,r.jsxs)(s.p,{children:["SpacetimeDB does not support nested transactions. When one reducer calls another, they share the same transaction. If you need separate transactions, use ",(0,r.jsx)(s.a,{href:"/docs/tables/schedule-tables",children:"scheduled reducers"})," to trigger the second reducer asynchronously."]}),"\n",(0,r.jsx)(s.h3,{id:"auto-increment-is-not-transactional",children:"Auto-Increment is Not Transactional"}),"\n",(0,r.jsxs)(s.p,{children:["The ",(0,r.jsx)(s.code,{children:"#[auto_inc]"})," sequence generator is not transactional:"]}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsx)(s.li,{children:"Sequence numbers are allocated even if a transaction rolls back"}),"\n",(0,r.jsx)(s.li,{children:"This can create gaps in your sequence"}),"\n",(0,r.jsxs)(s.li,{children:["See ",(0,r.jsx)(s.a,{href:"/docs/tables/auto-increment#crash-recovery",children:"Auto-Increment"})," for details"]}
1),"\n"]}),"\n",(0,r.jsx)(s.h2,{id:"related-topics",children:"Related Topics"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:(0,r.jsx)(s.a,{href:"/docs/functions/reducers",children:"Reducers"})})," - Functions that modify database state transactionally"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:(0,r.jsx)(s.a,{href:"/docs/functions/procedures",children:"Procedures"})})," - Functions with manual transaction control"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:(0,r.jsx)(s.a,{href:"/docs/tables/schedule-tables",children:"Schedule Tables"})})," - Schedule reducers for separate transactions"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.strong,{children:(0,r.jsx)(s.a,{href:"/docs/clients/subscriptions",children:"Subscriptions"})})," - How clients receive transactional updates"]}),"\n"]})]})}function x(e={}){const{wrapper:s}={...(0,c.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(p,{...e})}):p(e)}},43244:(e,s,n)=>{n.d(s,{A:()=>a});n(7378);var l=n(23372);const r={tabItem:"tabItem_w6aI"};var c=n(86106);function a({children:e,hidden:s,className:n}){return(0,c.jsx)("div",{role:"tabpanel",className:(0,l.A)(r.tabItem,n),hidden:s,children:e})}},51471:(e,s,n)=>{n.d(s,{A:()=>N});var l=n(7378),r=n(23372),c=n(23418),a=n(46585),t=n(30505),o=n(99202),i=n(81922),d=n(46923),h=n(73126);function F(e){return l.Children.toArray(e).filter(e=>"\n"!==e).map(e=>{if(!e||(0,l.isValidElement)(e)&&function(e){const{props:s}=e;return!!s&&"object"==typeof s&&"value"in s}(e))return e;throw new Error(`Docusaurus error: Bad <Tabs> child <${"string"==typeof e.type?e.type:e.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`)})?.filter(Boolean)??[]}function p(e){const{values:s,children:n}=e;return(0,l.useMemo)(()=>{const e=s??function(e){return F(e).map(({props:{value:e,label:s,attributes:n,default:l}})=>({value:e,label:s,attributes:n,default:l}))}(n);return function(e){const s=(0,d.XI)(e,(e,s)=>e.value===s.value);if(s.length>0)throw new Error(`Docusaurus error: Duplicate values "${s.map(e=>e.value).join(", ")}" found in <Tabs>. Every value needs to be unique.`)}(e),e},[s,n])}function x({value:e,tabValues:s}){return s.some(s=>s.value===e)}function j({queryString:e=!1,groupId:s}){const n=(0,t.W6)(),r=function({queryString:e=!1,groupId:s}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!s)throw new Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return s??null}({queryString:e,groupId:s});return[(0,i.aZ)(r),(0,l.useCallback)(e=>{if(!r)return;const s=new URLSearchParams(n.location.search);s.set(r,e),n.replace({...n.location,search:s.toString()})},[r,n])]}function u(e){const{defaultValue:s,queryString:n=!1,groupId:r}=e,c=p(e),[a,t]=(0,l.useState)(()=>function({defaultValue:e,tabValues:s}){if(0===s.length)throw new Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!x({value:e,tabValues:s}))throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${s.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}const n=s.find(e=>e.default)??s[0];if(!n)throw new Error("Unexpected error: 0 tabValues");return n.value}({defaultValue:s,tabValues:c})),[i,d]=j({queryString:n,groupId:r}),[F,u]=function({groupId:e}){const s=function(e){return e?`docusaurus.tab.${e}`:null}(e),[n,r]=(0,h.Dv)(s);return[n,(0,l.useCallback)(e=>{s&&r.set(e)},[s,r])]}({groupId:r}),y=(()=>{const e=i??F;return x({value:e,tabValues:c})?e:null})();(0,o.A)(()=>{y&&t(y)},[y]);return{selectedValue:a,selectValue:(0,l.useCallback)(e=>{if(!x({value:e,tabValues:c}))throw new Error(`Can't select invalid tab value=${e}`);t(e),d(e),u(e)},[d,u,c]),tabValues:c}}var y=n(52538);const m={tabList:"tabList_duiv",tabItem:"tabItem_a1H9"};var b=n(86106);function f({className:e,block:s,selectedValue:n,selectValue:l,tabValues:c}){const t=[],{blockElementScrollPositionUntilNextRender:o}=(0,a.a_)(),i=e=>{const s=e.currentTarget,r=t.indexOf(s),a=c[r].value;a!==n&&(o(s),l(a))},d=e=>{let s=null;switch(e.key){case"Enter":i(e);break;case"ArrowRight":{const n=t.indexOf(e.currentTarget)+1;s=t[n]??t[0];break}case"ArrowLeft":{const n=t.indexOf(e.currentTarget)-1;s=t[n]??t[t.length-1];break}}s?.focus()};return(0,b.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":s},e),children:c.map(({value:e,label:s,attributes:l})=>(0,b.jsx)("li",{role:"tab",tabIndex:n===e?0:-1,"aria-selected":n===e,ref:e=>{t.push(e)},onKeyDown:d,onClick:i,...l,className:(0,r.A)("tabs__item",m.tabItem,l?.className,{"tabs__item--active":n===e}),children:s??e},e))})}function v({lazy:e,children:s,selectedValue:n}
1){const c=(Array.isArray(s)?s:[s]).filter(Boolean);if(e){const e=c.find(e=>e.props.value===n);return e?(0,l.cloneElement)(e,{className:(0,r.A)("margin-top--md",e.props.className)}):null}return(0,b.jsx)("div",{className:"margin-top--md",children:c.map((e,s)=>(0,l.cloneElement)(e,{key:s,hidden:e.props.value!==n}))})}function g(e){const s=u(e);return(0,b.jsxs)("div",{className:(0,r.A)(c.G.tabs.container,"tabs-container",m.tabList),children:[(0,b.jsx)(f,{...s,...e}),(0,b.jsx)(v,{...s,...e})]})}function N(e){const s=(0,y.A)();return(0,b.jsx)(g,{...e,children:F(e.children)},String(s))}},56225:(e,s,n)=>{n.d(s,{R:()=>a,x:()=>t});var l=n(7378);const r={},c=l.createContext(r);function a(e){const s=l.useContext(c);return l.useMemo(function(){return"function"==typeof e?e(s):{...s,...e}},[s,e])}function t(e){let s;return s=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:a(e.components),l.createElement(c.Provider,{value:s},e.children)}},67834:(e,s,n)=>{n.d(s,{_:()=>r});n(7378);var l=n(86106);function r(){return(0,l.jsx)(l.Fragment,{})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.